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.
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
.
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.
This module extends HeartObject
with the ::where
class method, which takes a hash with the form {attribute_name: attribute_value}
.
This module adds associations:
#belongs_to
#has_many
#has_one_through
allowing one to call, sayrandom_human.cats
and receive an array of all of the cats belonging torandom_human
.
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-typeWHERE
string as an argument.
- Lazy, stackable
-
includes
for prefetching associated data to reduce db queries. -
has_many :through
associations. - data validations.