Apache Cassandra的Ruby ORM框架:Cassandro

jopen 10年前

Cassandro是一个小型的Ruby ORM框架,针对Apache Cassandra 2.0 和 CQL 3.0。Cassandro 使用新的 Datastax Ruby Driver (官方驱动器)。

Basic Cassandro

Connecting to Cassandra DB: Cassandro.connect(Hash options). For full list of options visit Ruby Driver Documentation

Cassandro.connect(                    hosts: ['127.0.0.1'],                    keyspace: 'some_keyspace'                   )

Creating a new keyspace. For full details of keyspace creation visit CLI keyspace

Cassandro.create_keyspace('new_keyspace', 'SimpleStrategy', 1) 

Select keyspace outside #connect

Cassandro.use('keyspace_name') 

Create table.

table = <<-TABLEDEF                                                                  CREATE TABLE IF NOT EXISTS table_name (                                                    id UUID,                                                                             username VARCHAR,                                                                       crypted_password VARCHAR,                                                            created_at TIMESTAMP,                                                                updated_at TIMESTAMP,                                                                PRIMARY KEY(id,username)                                                              )                                                                                  TABLEDEF    Cassandro.execute(table)

Execute queries.

result = Cassandro.execute("SELECT * FROM table_name;") 

Using Driver directly.

statement = Cassandro.client.prepare("SELECT * FROM table_name WHERE colname = ?;")  result = Cassandro.client.execute(statement, id)

项目主页:http://www.open-open.com/lib/view/home/1414933010997