Skip to content

Use Foundational to interface with with FoundationDB Ruby API in a more pleasant, rubyesque way.

License

Notifications You must be signed in to change notification settings

aemadrid/foundational

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foundational

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.

Installation

Add this line to your application's Gemfile:

gem 'foundational'

And then execute:

$ bundle

Or install it yourself as:

$ gem install foundational

Usage

Convenience Methods

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))

Persisted Array

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]]

Persisted Hash

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] }

Conversion

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.

Sub-Keyspaces

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 }

The End

Be excellent to each other. Party on, dudes!


Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Use Foundational to interface with with FoundationDB Ruby API in a more pleasant, rubyesque way.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages