ephraimpei / sql-object

An ORM solution inspired by Active Record

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQL Object

Summary

SQL Object is an ORM solution that maps SQL queries onto Ruby objects. It aims to provide an alternative to ActiveRecord.

Libraries

  • SQLite3
  • RSpec
  • ActiveSupport::Inflector

Features

  • Replicates core functionality of ActiveRecord::Base

API

SQLObject provides a few of your favorite ActiveRecord associations:

  • has_many
  • belongs_to
  • has_one_through

SQLObject provides the following ActiveRecord methods:

  • #save
  • #create
  • #update
  • #destroy

How It Works

SQLObject makes reference to DBConnection, which delegates SQLite::Database instance methods like #execute, #get_first_row, #last_insert_row_id, etc. to a singleton instance of SQLite::Database. Consumers of the API specify this instance by calling DBConnection::open(file), providing an SQLite db file path as an argument.

SQLObject provides a utility belt of class/instance methods that map to SQL queries.

Associations (has_many, belongs_to, has_one_through) are dynamically generated by the Associatable module, which extends SQLObject. Associations infer class_name, foreign_key and primary_key based on the same conventions as ActiveRecord. You can override these if the database schema you're working with is non-compliant (or ActiveSupport::Inflector fails to guess your table name).

About

An ORM solution inspired by Active Record


Languages

Language:Ruby 100.0%