Coder Social home page Coder Social logo

ecql's Introduction

Erlang Cassandra CQL Driver Build Status

Cassandra Native CQL Driver written in Erlang/OTP.

Features

  • CQL BINARY PROTOCOL v3 Support
  • Username, Password Authentication
  • Query, Prepare and Execute

Limits

  • TODO: Batch Query Support
  • TODO: Event Register
  • TODO: SSL Support

Usage

Schema

schema/test.schema.md

Connect

Connect to localhost:9042:

{ok, C} = ecql:connect().

Connect to nodes with username, password:

CassNodes = [{"127.0.0.1", 9042}, {"192.168.1.4", 9042}],
{ok, C} = ecql:connect([{nodes, CassNodes}, {username, "cassandra"}, {password, "cassandra"}]).

Query

{ok, KeySpace} = ecql:query(C, "use test").

{ok, {TableSpec, Columns, Rows}} = ecql:query(C, "select * from test.tab").

{ok, {TableSpec, Columns, Rows}} = ecql:query(C, "select * from test.tab where first_id = ? and second_id = ?", [{bigint, 1}, 'secid']).

Async Query

{ok, Ref} = ecql:async_query(C, "select * from test.tab"),
receive
	{async_cql_reply, Ref, {ok, Result} ->
		io:format("Result: ~p~n", [Result]);
	{async_cql_reply, Ref, Error} ->
        io:format("Result: ~p~n", [Result])
after
	1000 -> error(timeout)
end.

Prepare

{ok, Id} = ecql:prepare(C, "select * from test.tab where first_id = ? and second_id = ?").

Execute

{ok, {TableSpec, Columns, Rows}} = ecql:execute(C, Id, [{bigint, 1}, 'secid']).

Close

ok = ecql:close(C).

Connect Options

-type option() :: {nodes,    [{host(), inet:port_number()}]}
                | {username, iolist()}
                | {password, iolist()}
                | {keyspace, iolist()}
                | {tcp_opts, [gen_tcp:connect_option()]}
                | {ssl,      boolean()}
                | {ssl_opts, [ssl:ssl_option()]}
                | {timeout,  timeout()}
                | {logger,   atom() | {atom(), atom()}}.

Logger

%% log to stdout with info level
ecql:start_link([{logger, info}]).

%% log to otp standard error_logger with warning level
ecql:start_link([{logger, {otp, warning}}]).

%% log to lager with error level
ecql:start_link([{logger, {lager, error}}]).

Logger modules

Module Description
stdout io:format
otp error_logger
lager lager

Logger Levels

all
debug
info
warning
error
critical
none

License

The MIT License (MIT)

Author

Feng Lee [email protected]

ecql's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.