2017 © Pedro PelĂĄez
 

library rorm

Simple lightweight ORM

image

rrelmy/rorm

Simple lightweight ORM

  • Thursday, October 12, 2017
  • by rrelmy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,331 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

Rorm

  • Author: RĂ©my M. Böhler code@rrelmy.ch
  • License: MIT
  • Version: 0.1

Build Status Code Coverage Scrutinizer Code Quality, (*1)

Build Status, (*2)

Requirements

  • PHP 5.3

PHP 5.3 requires a JsonSerializable polyfill for the Model., (*3)

With PHP 5.5 we could ditch the QueryIterator and use yield. Yield seems to have a little bit bigger memory footprint., (*4)

Goals

  • Easy to use, easy to extend
  • Minimalistic ORM
  • Fast and low memory footprint
  • compound key support
  • Almost 100% test code coverage

TODO

  • check for possible model loaded hook
  • check if autoId could be ditched
  • consider setExpr (may be bad because until the model is loaded again the data is 'weird')
  • grouping/having support inside the QueryBuilder
  • Documentation

Ideas

  • Cache

Usage

General

Code Description
Rorm::setDatabase($dbh); Set default database connection
Rorm::getDatabase(); Retrieve the PDO object
Rorm::isMySQL($dbh) Check for MySQL connection
Rorm::isSQLite($dbh) Check for SQLite connection
Rorm::quote($dbh, $value) Returns the quoted value
Rorm::getIdentifierQuoter() Returns a closure to quote identifiers

Model

Code Description
MyModel::getTable(); Get the table name
MyModel::getDatabase(); Get the database connection
MyModel::create(); Create a new instance
MyModel::find($id); Find the model with specific $id
MyModel::findAll(); Get all available models
MyModel::query(); Create a new QueryBuilder instance
MyModel::customQuery($sql); Create a custom query
Code Description
$model->getId() Get the id of the current model
$model->hasId() Check if the model has a id specified
$model->save() Save current data to the database
$model->delete() Delete entry from the database
$model->getData() Get all data as array
$model->setData($data) Overwrite the data
$model->get($name) Get property
$model->set($name, $value) Set property
$model->has($name) Check if data exists
$model->remove($name) Remove property
$model->copyDataFrom($data) Copy data from object or array

QueryBuilder

Code Description
$query->distinct() Use DISTINCT
$query->selectAll() Select all data (default)
$query->select($column[, $as]) Select specific column
$query->selectExpr($expr[, $as]) Select expression
$query->where($column, $value) Add WHERE c = ?
$query->whereNot($column, $value) Add WHERE c != ?
$query->whereId($id) Add WHERE id = ?
$query->whereExpr($column, $expr) Add WHERE c = EXPR()
$query->whereRaw($where[, $params]) Add custom where clause
$query->whereLt($column, $value) Add WHERE c < ?
$query->whereLte($column, $value) Add WHERE c <= ?
$query->whereGt($column, $value) Add WHERE c > ?
$query->whereGte($column, $value) Add WHERE c >= ?
$query->whereNull($column) Add WHERE c IS NULL ?
$query->whereNotNull($column) Add WHERE c IS NOT NULL ?
$query->whereIn($column, $data) Add WHERE c IN (?, ?, ?)
$query->orderByAsc($column) Add ORDER BY c ASC
$query->orderByDesc($column) Add ORDER BY c DESC
$query->orderByExpr($column[, $params]) Add ORDER BY EXPR()
$query->limit(10) Add LIMIT 10
$query->offset(10) Add OFFSET 10
$query->findColumn() Retrieve first column of first entry
$query->findMany() Retrieve entries via an iterator
$query->findAll() Retrieve entries as array
$query->count() Count the results

Relations

There is no special support for relationships, but its easy to integrate them yourself., (*5)

Error handling

It is recommended to use the PDO exception error mode. Rorm has no special error handling and does not catch thrown PDOException's!, (*6)

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Unbuffered queries

You can use unbuffered queries with the findMany method, but you have to be aware that no queries can be executed until the iteration is finished., (*7)

No special methods are supplied for configure unbuffered queries. You may use the PDO attributes yourself., (*8)

Multiple database connections

You can add multiple database connections to the Rorm config with the setDatabase($dbh, 'name') method., (*9)

Each model can have a different database connection which can be configure with the $_connection property., (*10)

The Versions

12/10 2017

dev-dev

dev-dev

Simple lightweight ORM

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by Rémy M. Böhler

08/12 2016

dev-master

9999999-dev

Simple lightweight ORM

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Rémy M. Böhler

21/02 2016

1.0.0

1.0.0.0

Simple lightweight ORM

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Rémy M. Böhler