Object Relational Mapping

With object relational mapping, you don’t have to know structured query language (SQL) in order to write database queries. Liten and the ORM helps facilitate simple and rapid development and also allows both fluent sql queries as well as CRUD operations.



To create a new database connection, we need to instantiate the ORM class. Throughout the rest of the docs, we will use the variable $orm for the database connection.


Connect to a database table by calling the table() method.

An alternative to above is calling the database table as a method.


When calling the insert(array $data) method, $data can be passed as one dimensional array to insert one new record or multiple arrays to insert multiple records.

Single entry:

Multiple entries:


There are two ways to update a record, by using the active record pattern or by or by using the where clause.

Single entry:

The above can also be written as:

You can use the alternative save() instead of update().

Or you can use the set(array $data) or set($key, $value)

For multiple entries using set(array $data) and where($key, $value).


Save() is a shortcut to insert() or update().




Single entry:

Multiple entries:


Count all the entries based on where() clause.

Use count for a specific column name.


Max based on where() clause.


Min based on where() clause.


Sum based on where() clause.


Average based on where clause.



The fluent query feature of the ORM allows you to write simple queries without having to write SQL.


Returns a single record is found otherwise it will return false.

You can achieve the same above by using only the primary key and dropping the where clause.

Retrieving the entry


Find returns and ArrayIterator of rows found, otherwise it will return false.

Find also accepts a closure ( find(Closure $callback) ) to perform data manipulation.

Fluent Query Builder


Select all:

Select columns:


Where can be used to setup the where clauses and they work with find(), findOne(), update(), and delete(). This is the same for the where aliases as well.Repetitive call to where and it’s aliases will append to each other using the AND operator. Use _or() to mimic the OR operator.


There where aliases can help shorten the where examples above.

Primary key:

Not equal to:


Not like:

Greater than:

Greater than equal to:

Less than:

Less than equal to:

Where in:

Where not in:

Where null:

Where not null:

Where with OR and AND

Use _and_() / _or_() chained to any where clauses.



Order, Group, Limit, Offset




Last Modified: Apr 23, 2015 @ 11:33 PM

Liten Framework Forums Object Relational Mapping

This topic contains 0 replies, has 1 voice, and was last updated by  parkerj 2 years, 12 months ago.

You must be logged in to reply to this topic.