Use Foundational to interface with FoundationDB Ruby API in a more pleasant, rubyesque way.
It features syntactic sugar to do the most common things you'll want to do. Plus it also includes example implementations of FoundationDB persisted array and hashes.
Add this line to your application's Gemfile:
gem 'foundational'
And then execute:
$ bundle
Or install it yourself as:
$ gem install foundational
Instead of:
require 'fdb'
FDB.api_version 21
db = FDB.open
Let's do this:
require 'foundational'
Fd.open
And then you can access the db from everywhere:
Fd.db.transact do |tr|
tr['a'] = 'A'
tr['b'] = 'B'
end
Some tuples:
FDB::Tuple.unpack(FDB::Tuple.pack([1, 2, 3]))
# becomes
Fd.tuple_unpack(Fd.tuple_pack(1, 2, 3))
# or even better
Fd.tu(Fd.tp(1, 2, 3))
Let's say you want to turn your simple, one level Array into a FoundationDB persisted Array, then:
ary = Fd::Array.new 'simple_array'
ary << 1
ary << 'dos'
ary << [3]
# some time later
ary = Fd::Array.new 'simple_array'
# => [1, 'dos', [3]]
Very similar to what you can do with a FoundationDB persisted Hash:
hsh = Fd::Hash.new 'simple_hash'
hsh['a'] = 1
hsh['b'] = 'dos'
hsh['c'] = [3]
# some time later
hsh = Fd::Hash.new 'simple_hash'
# => { 'a' => 1, 'b' => 'dos', 'c' => [3] }
FoundationDB only saves basic values (strings) so we are using several serializers to choose from: MessagePack (default, fastest), JSON (slow) and YAML (slowest). Strings are left untouched though. You can choose your converter but be careful because some don't translate symbols or complex Ruby objects (MessagePack, JSON). As always, you need to choose between speed and features.
We are enforcing sub-keyspaces (namespaces for your tuple keys) inside Foundational (['Fd'] is the default keyspace) so if you want another set of keyspaces just set it like so:
Fd.keyspace = %w{ Some Other Keyspace }
Be excellent to each other. Party on, dudes!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request