2017 © Pedro Peláez
 

library phormium

A minimalist ORM for PHP.

image

phormium/phormium

A minimalist ORM for PHP.

  • Sunday, December 25, 2016
  • by ihabunek
  • Repository
  • 5 Watchers
  • 55 Stars
  • 9,499 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 10 Open issues
  • 17 Versions
  • 1 % Grown

The README.md

Phormium

Phormium is a minimalist ORM for PHP., (*1)

Tested on Informix, MySQL, PosgreSQL and SQLite. Might work on other databases with a PDO driver or may require some work., (*2)

Warning: This is a work in progress. Test before using! Report any bugs here., (*3)

Latest Stable Version Total Downloads Build Status Coverage Status, (*4)

Features

  • CRUD operations made simple
  • batch update and delete
  • filtering
  • ordering
  • limiting
  • transactions
  • custom queries
  • events

Documentation

The documentation is hosted by ReadTheDocs.org., (*5)

Showcase

After initial setup, Phormium is very easy to use. Here's a quick overview of it's features:, (*6)

// Create a new person record
$person = new Person();
$person->name = "Frank Zappa";
$person->birthday = "1940-12-20";
$person->save();

// Get record by primary key
Person::get(10);   // Throws exception if the model doesn't exist
Person::find(10);  // Returns null if the model doesn't exist

// Check record exists by primary key
Person::exists(10);

// Also works for composite primary keys
Trade::get('2013-01-01', 100);
Trade::find('2013-01-01', 100);
Trade::exists('2013-01-01', 100);

// Primary keys can also be given as arrays
$tradePK = array('2013-01-01', 100);
Trade::get($tradePK);
Trade::find($tradePK);
Trade::exists($tradePK);

// Fetch, update, save
$person = Person::get(10);
$person->salary += 5000; // give the man a raise!
$person->save();

// Fetch, delete
Person::get(37)->delete();

// Intuitive filtering, ordering and limiting
$persons = Person::objects()
    ->filter('salary', '>', 10000)
    ->filter('birthday', 'between', ['2000-01-01', '2001-01-01'])
    ->orderBy('name', 'desc')
    ->limit(100)
    ->fetch();

// Count records
$count = Person::objects()
    ->filter('salary', '>', 10000)
    ->count();

// Distinct values
$count = Person::objects()
    ->distinct('name', 'email');

// Complex composite filters
$persons = Person::objects()->filter(
    Filter::_or(
        Filter::_and(
            array('id', '>=', 10),
            array('id', '<=', 20)
        ),
        Filter::_and(
            array('id', '>=', 50),
            array('id', '<=', 60)
        ),
        array('id', '>=', 100),
    )
)->fetch();

// Fetch a single record (otherwise throws an exeption)
$person = Person::objects()
    ->filter('email', '=', 'ivan@example.com')
    ->single();

// Batch update
Person::objects()
    ->filter('salary', '>', 10000)
    ->update(['salary' => 5000]);

// Batch delete
Person::objects()
    ->filter('salary', '>', 10000)
    ->delete();

// Aggregates
Person::objects()->filter('name', 'like', 'Ivan%')->avg('salary');
Person::objects()->filter('name', 'like', 'Marko%')->min('birthday');

// Custom queries
$conn = DB::getConnection('myconn');
$data1 = $conn->query("SELECT * FROM mytable;");
$data2 = $conn->preparedQuery("SELECT * FROM mytable WHERE mycol > :value", array("value" => 10))

See documentation for full reference, also check out the example directory for more examples., (*7)

Why?

"Why another ORM?!?", I hear you cry., (*8)

There are two reasons:, (*9)

  • I work a lot on Informix on my day job and no other ORM I found supports it.
  • Writing an ORM is a great experience. You should try it.

Phormium is greatly inspired by other ORMs, in particular:, (*10)

Let me know what you think!, (*11)

Ivan Habunek @ihabunek, (*12)

Praise

If you like it, buy me a beer (in Croatia, that's around €2 or $3)., (*13)

Flattr this, (*14)

License

Licensed under the MIT license. See LICENSE.md., (*15)

The Versions

25/12 2016

dev-develop

dev-develop https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

24/12 2016

dev-feature/exceptions

dev-feature/exceptions https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

08/10 2015

dev-rewrite

dev-rewrite https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

07/05 2015

dev-master

9999999-dev https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

07/05 2015

0.8.0

0.8.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

09/01 2015

dev-events

dev-events https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

05/12 2014

0.7.0

0.7.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

05/12 2014

dev-relations

dev-relations https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

30/11 2014

dev-restructuring

dev-restructuring https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

28/09 2014

0.6.2

0.6.2.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

13/09 2014

0.6.1

0.6.1.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database php mapping

10/04 2014

0.6

0.6.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

 

orm database php mapping

10/12 2013

0.5

0.5.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

orm database php mapping

17/07 2013

0.4

0.4.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

orm database php mapping

14/06 2013

0.3

0.3.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

orm database php mapping

10/05 2013

0.2

0.2.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

orm database php mapping

25/04 2013

0.1

0.1.0.0 https://github.com/ihabunek/phormium

A minimalist ORM for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-pdo *

 

The Development Requires

orm database php mapping