A simple Orm inspired by active recrod.
- Install gem
# Ruby
gem install "<GEM_NAME>"
# For bundler place in Gemfile
gem "<GEM_NAME>""
- Include mixin SimpleOrm
include SimpleOrm
- Use find and all methods along with defined properties based on column names
class User
...
include SimpleOrm
# If users table has employee_id they can be fetched by calling has_one method
has_one :employee
...
# adds the following methods #find, #all and properties and relationships based on the users table.
# find's the user object with with a given id
# def self.find(id)
...
# returns an array of objects for the class
# def self.all
...
end
# RU for now missing CD of CRUD :)
user = User.find(1) # Execute SQL : "Select * from users where id = 1"
user.username # get username stored in db
user.username = "wasimakram" # set instance variable username
user.save # Update user in db using attributes
# has_one association
user.employee # returns an employee object
# helper methods
User.column_names # list of all columns in db
user.to_h # hash of user attributes
user.to_s # string of to_h
###