Official Ruby client for the ONQL database server.
gem install onql-clientOr in your Gemfile:
gem 'onql-client'gem 'onql-client', git: 'https://github.com/ONQL/onqlclient-ruby'gem 'onql-client',
git: 'https://github.com/ONQL/onqlclient-ruby',
tag: 'v0.1.0'require 'onql'
client = ONQL::Client.connect('localhost', 5656)
client.insert('mydb', 'users', { id: 'u1', name: 'John', age: 30 })
rows = client.onql('mydb.users[age>18]')
puts rows.inspect
client.update('mydb', 'users', { age: 31 },
client.build('mydb.users[id=$1].id', 'u1'))
client.delete('mydb', 'users', '', ids: ['u1'])
client.closeCreates and returns a connected client instance.
Sends a raw request frame and waits for a response.
Closes the connection.
On top of raw send_request, the client exposes convenience methods for the
common insert / update / delete / onql operations. Each one builds the
standard payload envelope for you and unwraps the {error, data} response —
raising RuntimeError on non-empty error, returning the decoded data
field on success.
db is passed explicitly to insert / update / delete. onql takes a
fully-qualified ONQL expression.
query arguments are ONQL expression strings, e.g.
'mydb.users[id="u1"].id'.
Insert a single record.
client.insert('mydb', 'users', { id: 'u1', name: 'John', age: 30 })Update records matching query (or explicit ids).
client.update('mydb', 'users', { age: 31 },
client.build('mydb.users[id=$1].id', 'u1'))
client.update('mydb', 'users', { age: 31 }, '', ids: ['u1'])Delete records matching query (or ids).
client.delete('mydb', 'users',
client.build('mydb.users[id=$1].id', 'u1'))
client.delete('mydb', 'users', '', ids: ['u1'])Run a raw ONQL query.
rows = client.onql('mydb.users[age>18]')Replace $1, $2, … placeholders with values.
q = client.build('mydb.users[name=$1 and age>$2]', "John", 18)
rows = client.onql(q)Class-level helper that parses the {error, data} envelope.
<request_id>\x1E<keyword>\x1E<payload>\x04
\x1E— field delimiter\x04— end-of-message marker
MIT