Giter VIP home page Giter VIP logo

jruby-mapdb's Introduction

Jruby::Mapdb

This is a jruby-only wrapper for MapDB (v0.9.8). MapDB is a fast key-value store java library.

Using this gem, MapDB trees are seen as hashes in jruby, making persistence easy and cheap.

2 types of storage from MapDB are available through the API:

  • MemoryDB
  • FileDB

Both MapDB types can co-exist in a same application provided their trees' names do not clash in Class namespace. Exceptions will be raised in such cases.

Installation

Add this line to your application's Gemfile:

gem 'jruby-mapdb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jruby-mapdb

Usage

  • MemoryDB scenario:
require 'jruby-mapdb'

db = Jruby::Mapdb::DB.new # the MemoryDB MapDB

db.tree :People # this will derive a class 'People' from Jruby::Mapdb::Tree, usable as a Hash

People[0] = 'CM'
p People[0]

People[1] = { :name => 'CM', :features => { :developer => true } }
p People[1]
  • FileDB scenario:
require 'jruby-mapdb'

db = Jruby::Mapdb::DB.new(:foodb) # the FileDB MapDB => 2 files created ('foodb' and 'foodb.p')

db.tree :People # this will derive a class 'People' from Jruby::Mapdb::Tree, usable as a Hash

People[0] = 'CM'
p People[0]

People[1] = { :name => 'CM', :features => { :developer => true } }
p People[1]

Jruby::Mapdb::DB API

This API has been kept as simple as possible, compatible with Ruby Hash.

It is compatible with most Enumerable methods: each, find_all, select, reject, entries, etc...


#new                      create a MemoryDB.
#new(dbname)              create a FileDB named dbname into current directory.

#tree(treename)           create a MapDB treemap, which can be used with Jruby::Mapdb::Tree API.

#close                    close DB instance.

#closed?                  return true if DB instance is closed, false otherwise.

#compact                  compact the DB. To be used in dedicated/isolated script, not in main script.

Jruby::Mapdb::Tree API

This API has been kept as simple as possible, compatible with Ruby Hash.

It is compatible with most Enumerable methods: each, find_all, select, reject, entries, etc...


#[](key)                  retrieve the value stored in tree with key. If the key is not defined yet, return nil.

#[]=(key, value)          store value with key in tree: key *cannot* be nil.

#key?(key)                true if the key is defined in the tree, false otherwise.

#keys                     returns array of all keys stored in tree

#count                    returns count of all keys stored in tree
#size                     returns count of all keys stored in tree

#regexp(pattern)          returns array of matched keys with pattern (extended + ignorecase)

#clear                    empty tree (remove all previously stored keys and values)

Testing

Testing is done using Test::Unit, and has been verified on jruby 1.6.8, 1.7.4, 1.7.5dev in both 1.8 and 1.9 modes.

$ rake

Contributors

  • fntzr (test refactoring)

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

jruby-mapdb's People

Contributors

cmichon avatar fntz avatar

Stargazers

Max Lord avatar Thomas Efer avatar Colin Surprenant avatar Scott Deming avatar Doug avatar Bill Dueber avatar Gus Becciu avatar

Watchers

 avatar  avatar James Cloos avatar

Forkers

fntz

jruby-mapdb's Issues

more doc elaboration

this is just a comment, your docs don't mention how to retrieve a tree that was previously persisted to file i.e. across sessions i.e. which would be a typical usage scenario.

No doubt to effectively use this one should also become acquainted with MapDB itself.

thanks

transaction support ?

is every put committed to db file ? or does that happen upon close ?

any support for rolling back a series of map puts ?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.