active_pstore

This library has Active Record like interface. Use pstore to store data.


Keywords
pstore, rails
License
MIT
Install
gem install active_pstore -v 0.5.2

Documentation

Active PStore Build Status Code Climate Test Coverage Gem Version git.legal

This library has Active Record like interface. Use pstore to store data.

SYNOPSIS

specify data store path

require 'active_pstore'

ActivePStore::Base.establish_connection(database: '/path/to/file')

class definition

class Artist < ActivePStore::Base
  attr_accessor :name
end

instantiate

randy_rhoads = Artist.new(name: 'Randy Rhoads')

or

randy_rhoads = Artist.new {|a|
  a.name = 'Randy Rhoads'
}

ActivePStore::Base.build method the same as ActivePStore::Base.new method.

save

randy_rhoads.save

database key is string of class name.

Artist.table_name # => 'Artist'

ex) Fetch stored artist objects by pure PStore.

database = PStore.new('/path/to/file')
database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist class.

identifier

allocate value of ActivePStore::Base#id using SecureRandom.hex.

randy_rhoads = Artist.new(name: 'Randy Rhoads')
randy_rhoads.id # => nil

randy_rhoads.save
randy_rhoads.id # => "0b84ece5d5be3bce3ee2101c1c4f6fda"

instantiate with save

randy_rhoads = Artist.create(name: 'Randy Rhoads')

or

randy_rhoads = Artist.create {|a|
  a.name = 'Randy Rhoads'
}

find series

Artist.all
Artist.first
Artist.last
Artist.find('388980778246cbcbfcbb7a8292f28c37') # ActivePStore::Base#id is an SecureRandom.hex value
Artist.where(name: 'Randy Rhoads')

Range

Artist.where(birth_date: Date.new(1948, 12, 3)..Date.new(1956, 12, 6))

see spec codes for more information.

Integration with Rails

This library has following generators.

Generate config file

Execute these lines in your Rails application directory:

bundle exec rails g active_pstore:config

And then create config/active_pstore.yml

Using the config/database.yml file you can specify all the information needed to access your pstore database:

development:
  database: db/active_pstore_development.yml

Generate model file

Execute these lines in your Rails application directory:

bundle exec rails g active_pstore:model artist name associated_act instrument birth_date

And then create app/models/artist.rb

class Artist < ActivePStore::Base
  attr_accessor :name
  attr_accessor :associated_act
  attr_accessor :instrument
  attr_accessor :birth_date
end

REQUIREMENTS

INSTALL

Add these lines to your application's Gemfile:

gem 'active_pstore'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_pstore

And require it as:

require 'active_pstore'

Problems

  • Transaction NOT supported (caused by implementation)
  • Data Migration NOT supported
  • Performance (caused by implementation)
  • and Not solving the root cause for enterprise...

Presentation Document

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

License

Active PStore is released under the MIT License.