2017 © Pedro Peláez
 

library orm

ORM with relations and performance in mind.

image

nochso/orm

ORM with relations and performance in mind.

  • Saturday, February 20, 2016
  • by nochso
  • Repository
  • 2 Watchers
  • 0 Stars
  • 242 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

nochso/orm

License GitHub tag Build Status SensioLabs Insight Coverage Status Dependency Status, (*1)

A stable ActiveRecord implementation:, (*2)

  • fluent query builder
  • tested with MySQL and SQLite
  • inspired by Paris but with less magic for better autocompletion

The following conventions are used:, (*3)

  • Every table requires a class inheriting from nochso\ORM\Model.
  • Class names are snaked_cased to table names by default.
    • Otherwise you can override protected static $_tableName
  • Public properties of model classes correspond to column names.

Select all rows from table blog_post with title matching "Hello %" ordered by creation_date. Then update all titles at once., (*4)

$posts = BlogPost::select()
    ->like('title', 'Hello %')
    ->orderAsc('creation_date')
    ->all();
foreach ($posts as $primaryKey => $post) {
    $post->title .= ' and goodbye';
}
$posts->save();

Installation

Get composer and require nochso/orm., (*5)

composer require nochso/orm

Example

use nochso\ORM\Model;
use nochso\ORM\Relation;

class User extends Model {
    /* Actual database table name */
    protected static $_tableName = 'user';
    /* The Subscription class must have a field "user_id" to identify the user's subscriptions */
    protected static $_relations = array(
        'subscriptions' => array(Relation::HAS_MANY, '\TV\Model\Subscription')
    );
    public $id;
    public $name;
    public $password;
    public $token;

    /* Lets you access the relation to the user's subscriptions.
     * Names must match with the key in $_relations */
    public $subscriptions;
}
// Fetch a user by his name
$john = User::select()->eq('name', 'john doe')->one();

// or achieve the same using the primary key
$sameJohn = User::select()->one($john->id);

echo $john->name; // 'john doe'

// Change and save his name
$john->name = 'herbert';
$john->save();

// Loads the related list of \TV\Model\Subscription instances as defined in User::$_relations['subscriptions']
$john->subscriptions->fetch();

if (count($john->subscriptions) > 0) {
  $john->subscriptions[0]->delete();
}

// Update certain columns of certain users
User::select()
    ->in('user_id', array(3, 6, 15))
    ->update(array('banned' => 1));

Change log

See the CHANGELOG for the full history of changes between releases., (*6)

The Versions

20/02 2016

dev-master

9999999-dev http://github.com/nochso/ORM2/

ORM with relations and performance in mind.

  Sources   Download

MIT

The Development Requires

orm database crud mapper mysql storage sqlite query builder chaining active record fluent relations relational

04/11 2015

1.3.5

1.3.5.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

MIT

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

14/08 2015

1.3.4

1.3.4.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

MIT

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

10/08 2015

1.3.3

1.3.3.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

MIT

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

03/08 2015

1.3.2

1.3.2.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

MIT

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

14/06 2015

1.3.1

1.3.1.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

14/06 2015

1.3.0

1.3.0.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

01/01 2015

1.2.0

1.2.0.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

07/12 2014

1.1.0

1.1.0.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

06/12 2014

1.0.1

1.0.1.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational

06/12 2014

1.0

1.0.0.0 http://localhost/orm/

ORM with relations and performance in mind.

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

orm database crud mapper mysql storage sqlite active record relations relational