Git Product home page Git Product logo

dart_cassandra_cql's Introduction

Dart Driver for Apache Cassandra

Build Status Coverage Status

Dart driver for Apache Cassandra that supports Cassandra Query Language version 3.0+ (CQL3).

The driver has a small dependency tree and implements Cassandra binary protocol (versions 2 and 3) for communicating with Cassandra servers. The protocol and CQL versions to be used are both configurable by the user.

Installation

add the following dependency to install this plugin:\

dependency:
  dart_cassandra_cql:
    git: https://github.com/Sparks1998/dart_cassandra_cql

Features

  • Asynchronous API based on Future and Streams
  • Connection management via connection pools
  • Connection load-balancing and failover
  • Server event handling (node/topology/schema change events)
  • Query multiplexing on each connection
  • Batch and prepared queries with either positional or named placeholders
  • Query result streaming
  • Support for all Cassandra types including user defined types (UDT), tuples and custom types (via user-defined Codecs)

Quick start

import "dart:async";
import 'package:dart_cassandra_cql/dart_cassandra_cql.dart' as cql;

void main() {
  // Create a client for connecting to our cluster using native
  // protocol V3 and sensible defaults. The client will setup
  // a connection pool for you and connect automatically when
  // you execute a query.
  cql.Client client = cql.Client.fromHostList([
      "10.0.0.1:9042"
      , "10.0.0.2:9042"
  ]);

  // Perform a select with positional bindings
  client.query(
      cql.Query("SELECT * from test.type_test WHERE id=?", bindings : [123])
  ).then((Iterable<Map<String, Object>> rows) {
    // ...
  });

  // Perform an prepared insert with named bindings, a time-based uuid and tuneable consistency
  client.execute(
      cql.Query("INSERT INTO test.type_test (id, uuid_value) VALUES (:id, :uuid)", bindings : {
          "id" : 1
          , "uuid" : cql.Uuid.timeBased()
      }, consistency : cql.Consistency.LOCAL_QUORUM
       , prepared : true)
  ).then((cql.ResultMessage res) {
    // ...
  });

  // Perform a batch insert query
  client.execute(
      cql.BatchQuery()
        ..add(
          cql.Query("INSERT INTO test.type_test (id, uuid_value) VALUES (:id, :uuid)", bindings : {
              "id" : 1
              , "uuid" : cql.Uuid.timeBased()
          })
      )
        ..add(
          cql.Query("INSERT INTO test.type_test (id, uuid_value) VALUES (:id, :uuid)", bindings : {
              "id" : 2
              , "uuid" : cql.Uuid.timeBased()
          })
      )
        ..consistency = cql.Consistency.TWO
  ).then((cql.ResultMessage res) {
    // ...
  }).catchError((e) {
    // Handle errors
  });

  // Stream (paginated) query
  StreamSubscription sub;
  sub = client.stream(
      cql.Query("SELECT * from test.type_test")
      , pageSize : 200
  ).listen((Map<String, Object> row) {
    // Handle incoming row
    print("Next row: ${row}");
    // ... or manipulate stream
    sub.cancel();
  });

}

Api

See the Api documentation.

Contributing

See the Contributing Guide.

Acknowledgements

License

dart_cassandra_cql is distributed under the MIT license.

dart_cassandra_cql's People

Contributors

achilleasa avatar isoos avatar sparks1998 avatar

Stargazers

 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.