2017 © Pedro Peláez
 

library orm

Tiny ORM for simple CRUD operations.

image

forestry/orm

Tiny ORM for simple CRUD operations.

  • Friday, March 27, 2015
  • by daniel.melzer
  • Repository
  • 1 Watchers
  • 4 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Forestry ORM

Latest Version Software License Build Status Codacy Badge Total Downloads, (*1)

Small ORM for basic CRUD operations., (*2)

Install

Via Composer, (*3)

``` bash $ composer require forestry/orm, (*4)


## Usage ### Model #### Create a model Any model extends the class `\Forestry\Orm\BaseModel`. ```php class User extends \Forestry\Orm\BaseModel { public static $database = 'example'; public static $table = 'users'; }

You have to define at least the database and table name., (*5)

Using the model

You can define getters and setter for all table fields., (*6)

$user = new User();
$user->setName('Bob');
$user->save();

Getters/setters are not mandatory. You can access the properties directly:, (*7)

$user = new User();
$user->name = 'Bob';
$user->save();

Instead of calling the save() method, you can explicitly call insert() or update(). If you set the primary key on a new model object, you have to use the insert() method., (*8)

Connections

\Forestry\Orm\Storage provides a registry for PDO instances., (*9)

Set a connection

A connection is defined with the set() method:, (*10)

\Forestry\Orm\Storage::set('default', [
    'dsn' => 'mysql:host=localhost',
    'user' => 'root',
    'password' => '',
    'option' => [/*any PDO options can be defined here*/]
]);

A model could use another connection if you configure it:, (*11)

use \Forestry\Orm\Storage as Storage;
use \Forestry\Orm\BaseModel as BaseModel;

Storage::set('myOtherConnection', [
    'dsn' => 'mysql:host=127.0.0.1',
    'user' => 'root',
    'password' => ''
]);

class Acme extends BaseModel {

    public static $storage = 'myOtherConnection';
    public static $table = 'acme_table';

}

If you try to set an already defined connection set() throws a LogicException., (*12)

Get a defined connection

You can also freely use the PDO connection like this:, (*13)

Storage::get('myOtherConnection')->exec('SELECT * FROM example.users');

If you try to get an undefined connection get() throws a OutOfBoundsException., (*14)

Close a connection

To close a defined connection use the delete() method:, (*15)

Storage::delete('myOtherConnection');

If you try to close an undefined connection delte() throws a OutOfBoundsException., (*16)

Testing

bash $ phpunit, (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Credits

License

The MIT License (MIT). Please see License File for more information., (*19)

The Versions

27/03 2015

dev-master

9999999-dev https://github.com/ForestryCodes/orm

Tiny ORM for simple CRUD operations.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

orm database pdo forestry

27/03 2015

dev-develop

dev-develop https://github.com/ForestryCodes/orm

Tiny ORM for simple CRUD operations.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

orm database pdo forestry

27/03 2015

0.1.0

0.1.0.0 https://github.com/ForestryCodes/orm

Tiny ORM for simple CRUD operations.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

orm database pdo forestry