Ruby driver for SurrealDB databases.
Add this line to your application's Gemfile:
gem 'surrealdb'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install surrealdb
Included with this module are two Classes, SurrealDB::HTTPClient
and SurrealDB::SurrealError
, where SurrealError
is raised for any errors that occur during the HTTP request.
Create a client with the following code:
require "surrealdb"
SurrealDB::HTTPClient.new(
"http://localhost:8000/",
namespace: "test",
database: "test",
username: "root",
password: "root"
) do |client|
...
end
The following examples assume that the client is created as above.
Execute a query. It takes a string as the table name to select from, and returns Array<Hash>
.
client.execute("SELECT * FROM test")
# => [{"id"=>1, "name"=>"test"}]
client.execute("DELETE test:1")
# => []
Retrieve all of the data from a table. Takes a string as the table name to select from. Returns Array<Hash>
.
client.select_all("test")
# => [{"id"=>1, "name"=>"test"}]
Retrieve one record from a table. Takes a string as as the table name to select from, and an id of any type. Returns Hash
.
client.select_one("test", 1)
# => {"id"=>1, "name"=>"test"}
Replace a record in a table. Takes a string as the table name the record exists in, an id of any type, and a Hash
of values to replace. Returns Hash
.
client.replace_one("test", 1, {name: "test2", title: "test"})
# => {"id"=>1, "name"=>"test2", "title"=>"test"}
Update values of a record in a table. Takes a string as the table name to update a record in, an id of any type, and a Hash
of values to replace. Returns Hash
.
client.upsert_one("test", 1, {name: "test4"})
# => {"id"=>1, "name"=>"test4", "title"=>"test"}
Delete all records from a table. Takes a string as the table name to delete records from. Returns nil
.
client.delete_all("test")
# => nil
Delete a record from a table. Takes a string as the table name to delete a record from, and an id of any type. Returns nil
.
client.delete_one("test", 1)
# => nil
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/surrealdb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Everyone interacting in the Surrealdb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.