Tdengine driver for Elixir.
Documentation:
iex> {:ok, pid} = Tdex.start_link(protocol: :native, hostname: "localhost", port: 6030, username: "root", password: "taosdata", database: "test", pool_size: 1)
OR
iex> {:ok, pid} = Tdex.start_link(protocol: :ws, hostname: "localhost", port: 6041, username: "root", password: "taosdata", database: "test", pool_size: 1, timeout: 120_000)
Where the configuration for the Repo must be in your application environment, usually defined in your config/config.exs
# native connect
config :tdex, Tdex.Repo,
protocol: :native,
username: "root",
database: "test",
hostname: "127.0.0.1",
password: "taosdata",
port: 6030,
pool_size: 16
# ws connect
config :tdex, Tdex.Repo,
protocol: :ws,
username: "root",
database: "cfd80",
hostname: "127.0.0.1",
password: "taosdata",
port: 6041,
timeout: 1000,
pool_size: 16
After configuration is complete, run the command:
iex> {:ok, pid} = Tdex.start_link()
iex> Tdex.query!(pid, "SELECT ts,bid FROM tick LIMIT 10", [])
%Tdex.Result{
code: 0,
req_id: 2,
rows: [%{"bid" => 1091.752, "ts" => ~U[2015-08-09 17:00:00.000Z]}],
affected_rows: 0,
message: ""
}
iex> Tdex.query!(pid, "SELECT ts,bid FROM tick WHERE bid = ? AND ask = ? LIMIT 10", [1, 2])
%Tdex.Result{code: 0, req_id: 3, rows: [], affected_rows: 0, message: ""}
CREATE TABLE table_varbinary (ts TIMESTAMP, val VARBINARY);
tsNow = System.system_time(:nanosecond)
sql = 'insert into table_varbinary values(?, ?)'
{:ok, stmt} = Wrapper.taos_stmt_init(conn, sql)
try do
:ok = Wrapper.taos_multi_bind_set_timestamp(stmt, 0, tsNow)
:ok = Wrapper.taos_multi_bind_set_varbinary(stmt, 1, "Hello tdengine")
:ok = Wrapper.taos_stmt_bind_param_batch(stmt)
Wrapper.taos_stmt_execute(stmt)
catch _, ex ->
IO.inspect(ex);
IO.inspect(__STACKTRACE__)
after
IO.puts("close stmt")
Wrapper.taos_stmt_close(stmt)
end
tsNow = System.system_time(:nanosecond) sche= %{ts: {:ts, 0}, val: {:varbinary, 1}} data = [%{ts: tsNow, val: "record1"}, %{ts: tsNow+1, val: "record2"}, %{ts: tsNow+2, val: "record3"}] Tdex.execute(pid, %Tdex.Query{schema: sche, statement: 'insert into table_varbinary values(?, ?)'}, data)
Tdex comes with JSON support out of the box via the Jason library. To use it, add :jason to your dependencies:
{:jason, "~> 1.4"}
{:tdex, git: "git@github.com:skygroup2/tdex.git", branch: "dev"},