Skip to content

Commit a0d5a4c

Browse files
author
Philip Sampaio
committed
Prepare for first release
1 parent 6d6bc32 commit a0d5a4c

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed

README.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
11
# ReqCH
22

3-
A Req plugin for ClickHouse.
3+
[![Docs](https://img.shields.io/badge/hex.pm-docs-8e7ce6.svg)](https://hexdocs.pm/req_ch)
4+
[![Hex pm](http://img.shields.io/hexpm/v/req_ch.svg?style=flat&color=blue)](https://hex.pm/packages/req_ch)
45

5-
## Installation
6+
A [Req](https://github.com/wojtekmach/req) plugin for [ClickHouse](https://clickhouse.com/).
67

7-
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8-
by adding `req_ch` to your list of dependencies in `mix.exs`:
8+
## Usage
9+
10+
Assuming that you have a ClickHouse server running on localhost, this code is going to run:
911

1012
```elixir
11-
def deps do
12-
[
13-
{:req_ch, "~> 0.1.0"}
14-
]
15-
end
13+
Mix.install([
14+
{:req_ch, "~> 0.1.0"}
15+
])
16+
17+
req = ReqCH.new(database: "system")
18+
19+
ReqCH.query!(req, "SELECT number FROM numbers LIMIT 5").body
20+
# => "0\n1\n2\n3\n4\n"
21+
22+
ReqCH.query!(req, "SELECT number FROM numbers WHERE number > {num:UInt8} LIMIT 5", [num: 12]).body
23+
# => "13\n14\n15\n16\n17\n"
1624
```
1725

26+
It's also possible to return `Explorer` dataframes, if the `:explorer` package is installed
27+
and the `:explorer` format is used:
28+
29+
```elixir
30+
Mix.install([
31+
{:req_ch, "~> 0.1.0"},
32+
{:explorer, "~> 0.10.0"}
33+
])
34+
35+
req = ReqCH.new(database: "system")
36+
37+
ReqCH.query!(req, "SELECT number, number - 2 as less_two FROM numbers LIMIT 5", [], [format: :explorer]).body
38+
# => #Explorer.DataFrame<
39+
# Polars[5 x 2]
40+
# number u64 [0, 1, 2, 3, 4]
41+
# less_two s64 [-2, -1, 0, 1, 2]
42+
# >
43+
```
44+
45+
See the [documentation](https://hexdocs.pm/req_ch) for details.
46+
1847
## License
1948

2049
Copyright (C) 2024 Dashbit

lib/req_ch.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ defmodule ReqCH do
2929
This option accepts `:tsv`, `:csv`, `:json` or `:explorer` as atoms.
3030
3131
It also accepts all formats described in the #{@formats_page} page.
32+
Use plain strings for these formats.
3233
3334
The `:explorer` format is special, and will build an Explorer dataframe
3435
in case the `:explorer` dependency is installed.
@@ -41,14 +42,14 @@ defmodule ReqCH do
4142
After setting a default database, one can make a request directly:
4243
4344
iex> req = ReqCH.new(database: "system")
44-
iex> Req.post!(req, body: "SELECT number FROM numbers LIMIT 3").body
45-
1\n2\n3\n
45+
iex> Req.post!(req, body: "SELECT number + 1 FROM numbers LIMIT 3").body
46+
"1\\n2\\n3\\n"
4647
4748
It's also possible to make a query using `Req.get/2`:
4849
4950
iex> req = ReqCH.new(database: "system")
50-
iex> Req.get!(req, params: [query: "SELECT number FROM numbers LIMIT 3"]).body
51-
1\n2\n3\n
51+
iex> Req.get!(req, params: [query: "SELECT number + 1 FROM numbers LIMIT 3"]).body
52+
"1\\n2\\n3\\n"
5253
5354
In case the server needs authentication, it's possible to use `Req` options for that.
5455

mix.exs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,45 @@ defmodule ReqCH.MixProject do
1111
name: "ReqCH",
1212
description: "A minimal Req plugin for ClickHouse",
1313
start_permanent: Mix.env() == :prod,
14+
preferred_cli_env: [
15+
docs: :docs,
16+
"hex.publish": :docs
17+
],
18+
docs: docs(),
19+
package: package(),
1420
deps: deps()
1521
]
1622
end
1723

18-
# Run "mix help compile.app" to learn about applications.
1924
def application do
2025
[
2126
extra_applications: [:logger]
2227
]
2328
end
2429

25-
# Run "mix help deps" to learn about dependencies.
2630
defp deps do
2731
[
2832
{:req, "~> 0.5"},
2933
{:explorer, "~> 0.10", optional: true},
3034
{:ex_doc, ">= 0.0.0", only: :docs, runtime: false}
3135
]
3236
end
37+
38+
defp package do
39+
[
40+
licenses: ["Apache-2.0"],
41+
links: %{
42+
"GitHub" => "https://github.com/livebook-dev/req_ch"
43+
}
44+
]
45+
end
46+
47+
defp docs do
48+
[
49+
main: "readme",
50+
source_url: "https://github.com/livebook-dev/req_ch",
51+
source_ref: "v#{@version}",
52+
extras: ["README.md"]
53+
]
54+
end
3355
end

0 commit comments

Comments
 (0)