Skip to content

Commit

Permalink
Add Changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Shilov <[email protected]>
  • Loading branch information
shlima committed Nov 20, 2022
1 parent a40ad4d commit a293b5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@
`ClickHouse.connection.insert("table", [{id: 1})]` (for ruby < 3.0 use `ClickHouse.connection.insert("table", [{id: 1}], {})`)
* 🔥Added type serialization, example below

```sql
CREATE TABLE assets(visible Boolean, tags Array(Nullable(String))) ENGINE Memory
```

```ruby
@schema = ClickHouse.connection.table_schema('assets')

# Json each row
ClickHouse.connection.insert('assets', @schema.serialize(true, ['ruby']))

# Json compact

ClickHouse.connection.insert('assets', columns: %w[visible tags]) do |buffer|
buffer << [
@schema.serialize_column("visible", true),
@schema.serialize_column("tags", ['ruby']),
]
end
```

# 2.0.0
* Fixed `Bigdecimal` casting with high precision
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ response.body #=> "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"

## Insert

When column names and values are transferred separately, data transfers to the server
When column names and values are transferred separately, data sends to the server
using `JSONCompactEachRow` format by default.

```ruby
Expand All @@ -208,7 +208,7 @@ end
ClickHouse.connection.insert('table', columns: %i[id name], values: [[1, 'Mercury'], [2, 'Venus']])
```

When rows are passed as an Array or Hash, data transfers to the server
When rows are passed as an Array or a Hash, data sends to the server
using `JSONEachRow` format by default.

```ruby
Expand All @@ -228,7 +228,7 @@ end
```

Sometimes it's needed to use other format than `JSONEachRow` For example if you want to send BigDecimal's
you could use `JSONStringsEachRow` format so string representation of BigDecimal will be parsed:
you could use `JSONStringsEachRow` format so string representation of `BigDecimal` will be parsed:

```ruby
ClickHouse.connection.insert('table', { name: 'Sun', id: '1' }, format: 'JSONStringsEachRow')
Expand Down Expand Up @@ -346,9 +346,7 @@ end
## Type casting

By default gem provides all necessary type casting, but you may overwrite or define
your own logic.

if you need to redefine all built-in types with your implementation,
your own logic. if you need to redefine all built-in types with your implementation,
just clear the default type system:

```ruby
Expand All @@ -360,18 +358,16 @@ ClickHouse.types.default #=> #<ClickHouse::Type::UndefinedType>
Type casting works automatically when fetching data, when inserting data, you must serialize the types yourself

```sql
CREATE TABLE assets(
visible Boolean,
tags Array(Nullable(String))
) ENGINE Memory
CREATE TABLE assets(visible Boolean, tags Array(Nullable(String))) ENGINE Memory
```

```ruby
@schema = ClickHouse.connection.table_schema('assets')

# Json each row
ClickHouse.connection.insert('assets', @schema.serialize(true, ['ruby']))

# or
# Json compact

ClickHouse.connection.insert('assets', columns: %w[visible tags]) do |buffer|
buffer << [
Expand Down

0 comments on commit a293b5c

Please sign in to comment.