It's only for demonstration purposes. If you want to use it in your application - feel free:
gem "jason-orm", :require => "jason"
It uses .json files for persistence. One for each model (imagine as *row).
By now, Jason supports:
- a persistence_layer
- a simple relation (association) mapper
Jason.setup do |config| config.persistence_path = "/Users/bob/jsons" config.restore_app = MyOwn::RestoreApp end
config.restore_app allows to use an own Class which handles restoring from .json files.
If this is set, it replaces the integrated
The persistence layer
Usage of the persistence layer is widly known from other libraries.
By now, it supports the following datatypes:
class Person include Jason::Persistence attribute :first_name, String attribute :last_name, String end person = Person.new(:first_name => "Michail", :last_name => "Bulgakov") person.save person.update_attributes(:first_name => "Sascha") person.delete Person.find("1223wer43") Person.find_by_id("1223wer43") Person.find_by_last_name("Bulgakov") #=> returns Array, it's kind of 'where' Person.find_by_first_name("Michael")
The relation mapper
Usage of the relation mapper is also widly known from other libraries.
By now it supports:
- has_many (work in progress)
class Person include Jason::Persistence include Jason::Relation attribute :first_name, String attribute :last_name, String attribute :age, Integer belongs_to :wife end class Wife include Jason::Persistence include Jason::Relation attribute :name, String end person = Person.new(:first_name => "Michail", :last_name => "Bulgakov") woman = Wife.new(:name => "Natascha Rutskovskaja") person.wife = woman person.save
belongs_to takes also a second parameter which is a hash:
belongs_to :wife, :class => "Woman"
so different class (names) are assignable to the relation name.
|Custom data types||TODO|
|deletable only if already saved||DONE|
|code documentation||Partly & TODO|
Author: Daniel Schmidt, 15/16/17. July 2012