crate-connect
A simple node.js driver to connect to a Crate.io Data Storage, this was originally part of the CrateJS driver, now CrateJS is an extension of crate-connect.
Installation
npm install crate-connect
Sample usage
var Crate = ; // You can have as many db instance as you please :)// You should probably add this part to another module and export it!var db = host: 'localhost' //Defaults to localhost port: 4200 //Defaults to 4200 // You can also send in a cluster of nodes cluster: host: 'localhost' port:4200 ; // Now lets build some queries, using placeholders, you can either use ? or $1, $2, $3...var q = getSomeTweets: db getReTweeted: db; // Get some tweetsqgetSomeTweets; // Get only tweets with retweetsqgetReTweeted; { iferr //Do something return; console; console; console;}
Methods
db.Query(string)
- This constructs a query and returns an .execute() method.
db.execute(query, statements, callback)
- This executes a query directly
- Statements is an optional parameter, you can replace it with the callback
db
db.blob()
- Methods related to managing blob's
- Note that this does not construct the sha1 hash from the buffer, you need to do it yourself.
- Note that if the sha1 hash is not correct, the blob wont be inserted. The sha1 hash must be calculated from the blob to be inserted.
blob().put(table, sha1Hash, buffer, callback)
var buffer = 'sample'var hash = crypto ####
blob().get(table, sha1Hash, callback)
db
blob().check(table, sha1Hash, callback)
db
blob().delete(table, sha1Hash, callback)
db
TODO
- Refactor some pieces of this code, its messy :(