Skip to content

Object Relational Mapping for Ruby and your database, RubyHeartDb cosplays as Rails' ActiveRecord.

Notifications You must be signed in to change notification settings

solugebefola/RubyHeartDb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby♥︎Db

This is an object relational mapping written in Ruby that has some of the fine aspects of Rails' ActiveRecord.

It could be used in tandem with a Rails-like framework to act as the back-end for a web application. Or just for your own amusement.

How to use Ruby♥︎Db

Naturally, one needs Ruby to run the project. Here is a good place to start for instructions on putting ruby on your machine and general Ruby information.

If you already have the deep, deep Ruby knowledge, you can try out Ruby♥︎Db in a REPL like irb or pry. Simply download the repository and go to town:

$ bundle install
$ pry
> load 'demo.db'

The demo has Cat, Human, and House classes, all inheriting from HeartObject.

HeartObject

This is the core of the system. HeartObject has available the following methods:

  • Class methods

    • ::all
    • ::find(id)
  • Instance methods

    • #attributes
    • #save which accesses #insert or #update depending on whether the record is already in the database.

Searchable

This module extends HeartObject with the ::where class method, which takes a hash with the form {attribute_name: attribute_value}.

Associatable

This module adds associations:

  • #belongs_to
  • #has_many
  • #has_one_through allowing one to call, say random_human.cats and receive an array of all of the cats belonging to random_human.

Future additions

In the spirit of making this thing more interesting, I would like to add:

  • ::first and ::last
  • ::where modifications
    • Lazy, stackable ::where so that it doesn't query the database until necessary (lazy is a good thing in this case).
    • Enable ::where to take a SQL-type WHERE string as an argument.
  • includes for prefetching associated data to reduce db queries.
  • has_many :through associations.
  • data validations.

About

Object Relational Mapping for Ruby and your database, RubyHeartDb cosplays as Rails' ActiveRecord.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages