Rbdb
Simple in memory database for Ruby
Installation
Add this line to your application's Gemfile:
gem 'rbdb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rbdb
Usage
require 'rbdb'
db = Rbdb.create_db('app') # Create a DB
table = db.create_table('people') # And a table
table.fields = {name: :string, age: :integer} # Assign it a schema like field (Hash)
table.insert({name: 'John', age: 31}) # Give it some records
table.insert({name: 'Doe', age: 31})
table.find_all({age: 31})
=> [{:name=>"John", :age=>31, :id=>1}, {:name=>"Doe", :age=>31, :id=>2}]
Rbdb automatically assigns a unique id to each record inserted.
Top level namespace
The top level namespace is meant to contain all databases.
Rbdb.create_db(name, = {})
creates a DB with name and adds it to the top level container and return it
name: The name to give to the database
options: force - If set to true, overwrites the DB with name if it exists and is not contained in the top level namespace.
Rbdb.add_db(db, = {})
add a DB to the top level container and return it
db: The database to add to the top level container
options: force - If set to true, overwrites the DB with db.name if it exists and is not in the top level namespace.
Rbdb.databases
returns all databases
Rbdb.find_db(name)
finds the database with name in the top level namespace
name: the name of the database to find.
Rbdb.delete_db(name)
deletes the database with name in the top level namespace
name: the name of the database to delete.
Rbdb.flush
Used for debugging and testing purposes. Deletes all DB's in the top level container.
Contributing
- Fork it ( https://github.com/dibenso/rbdb/fork )
- 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 a new Pull Request