Apache Cassandra的Ruby ORM框架:Cassandro
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)
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!