Skip to content

Commit

Permalink
Merge pull request #244 from plausible/improve-docs
Browse files Browse the repository at this point in the history
Improve docs
  • Loading branch information
ruslandoga authored Feb 8, 2025
2 parents 260268c + e7108cc commit c8f71d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Ch.query!(pid, "CREATE TABLE IF NOT EXISTS ch_demo(id UInt64) ENGINE Null")
Ch.query!(pid, "INSERT INTO ch_demo(id) SELECT number FROM system.numbers LIMIT {limit:UInt8}", %{"limit" => 2})
```

#### Insert rows as [RowBinary](https://clickhouse.com/docs/en/interfaces/formats#rowbinary) (efficient)
#### Insert rows as [RowBinary](https://clickhouse.com/docs/en/interfaces/formats/RowBinary) (efficient)

```elixir
{:ok, pid} = Ch.start_link()
Expand All @@ -106,7 +106,7 @@ types = [:u64]

Note that RowBinary format encoding requires `:types` option to be provided.

Similarly, you can use [`RowBinaryWithNamesAndTypes`](https://clickhouse.com/docs/en/interfaces/formats#rowbinarywithnamesandtypes) which would additionally do something like a type check.
Similarly, you can use [RowBinaryWithNamesAndTypes](https://clickhouse.com/docs/en/interfaces/formats/RowBinaryWithNamesAndTypes) which would additionally do something like a type check.

```elixir
sql = "INSERT INTO ch_demo FORMAT RowBinaryWithNamesAndTypes"
Expand Down Expand Up @@ -165,7 +165,7 @@ settings = [async_insert: 1]

#### NULL in RowBinary

It's the same as in [`ch-go`](https://clickhouse.com/docs/en/integrations/go#nullable)
It's the same as in [ch-go](https://clickhouse.com/docs/en/integrations/go#nullable)

> At insert time, Nil can be passed for both the normal and Nullable version of a column. For the former, the default value for the type will be persisted, e.g., an empty string for string. For the nullable version, a NULL value will be stored in ClickHouse.
Expand Down
2 changes: 1 addition & 1 deletion lib/ch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Ch do
| {:scheme, String.t()}
| {:hostname, String.t()}
| {:port, :inet.port_number()}
| {:transport_opts, :gen_tcp.connect_option()}
| {:transport_opts, [:gen_tcp.connect_option() | :ssl.tls_client_option()]}
| DBConnection.start_option()

@doc """
Expand Down
12 changes: 7 additions & 5 deletions lib/ch/row_binary.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Ch.RowBinary do
@moduledoc "Helpers for working with ClickHouse [`RowBinary`](https://clickhouse.com/docs/en/sql-reference/formats#rowbinary) format."
@moduledoc "Helpers for working with ClickHouse [RowBinary](https://clickhouse.com/docs/en/interfaces/formats/RowBinary) format."

# @compile {:bin_opt_info, true}
@dialyzer :no_improper_lists
Expand Down Expand Up @@ -28,7 +28,7 @@ defmodule Ch.RowBinary do
defp encode_types([] = done), do: done

@doc """
Encodes a single row to [`RowBinary`](https://clickhouse.com/docs/en/sql-reference/formats#rowbinary) as iodata.
Encodes a single row to [RowBinary](https://clickhouse.com/docs/en/interfaces/formats/RowBinary) as iodata.
Examples:
Expand All @@ -50,7 +50,7 @@ defmodule Ch.RowBinary do
defp _encode_row([] = done, []), do: done

@doc """
Encodes multiple rows to [`RowBinary`](https://clickhouse.com/docs/en/sql-reference/formats#rowbinary) as iodata.
Encodes multiple rows to [RowBinary](https://clickhouse.com/docs/en/interfaces/formats/RowBinary) as iodata.
Examples:
Expand Down Expand Up @@ -453,7 +453,7 @@ defmodule Ch.RowBinary do
defp d(?f), do: 15

@doc """
Decodes [`RowBinaryWithNamesAndTypes`](https://clickhouse.com/docs/en/sql-reference/formats#rowbinarywithnamesandtypes) into rows.
Decodes [RowBinaryWithNamesAndTypes](https://clickhouse.com/docs/en/interfaces/formats/RowBinaryWithNamesAndTypes) into rows.
Example:
Expand All @@ -474,12 +474,14 @@ defmodule Ch.RowBinary do
[["1+1"], [2]]
"""
def decode_names_and_rows(row_binary_with_names_and_types)

def decode_names_and_rows(<<cols, rest::bytes>>) do
decode_names(rest, cols, cols, _acc = [])
end

@doc """
Decodes [`RowBinary`](https://clickhouse.com/docs/en/sql-reference/formats#rowbinary) into rows.
Decodes [RowBinary](https://clickhouse.com/docs/en/interfaces/formats/RowBinary) into rows.
Example:
Expand Down

0 comments on commit c8f71d3

Please sign in to comment.