2017 © Pedro Peláez
 

library orm

An ORM implementation

image

vakata/orm

An ORM implementation

  • Friday, May 25, 2018
  • by vakata
  • Repository
  • 2 Watchers
  • 5 Stars
  • 644 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 54 Versions
  • 13 % Grown

The README.md

orm

Latest Version on Packagist ![Software License][ico-license] Build Status Scrutinizer Code Quality ![Code Coverage][ico-scrutinizer], (*1)

A orm abstraction with support for various drivers., (*2)

Install

Via Composer, (*3)

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


## Usage ``` php // first you need a database instance $db = new \vakata\database\DB('mysql://root@127.0.0.1/test'); // then you can create the manager object $manager = new \vakata\orm\Manager($db); // assuming there is a book table with a name column foreach ($manager->book() as $book) { echo $book->name . "\n"; } // you could of course filter and order foreach ($manager->book()->filter('year', 2016)->sort('name') as $book) { // iterate over the books from 2016 } // if using mySQL foreign keys are automatically detected // for example if there is an author table and the book table references it foreach ($manager->book() as $book) { echo $book->author->name . "\n"; } // you can solve the n+1 queries problem like this foreach ($manager->fromQuery($db->book()->with('author')) as $book) { echo $book->author->name . "\n"; } // provided there is a linking table book_tag and a tag table and each book has many tags you can do this foreach ($manager->book()->with('author') as $book) { echo $book->tag[0]->name . "\n"; // the name of the first tag which the current book has } // which means you can do something like this echo $manager->book()[0]->author->book[0]->tag[0]->book[0]->author->name; // as for removing objects $authors = $manager->author(); $author = $authors[0]; $authors->remove($author); // you can also create new objects $book = new \StdClass(); $book->name = 'Test'; $manager->books()->add($book); // you can also use your own classes // just make sure you provide getters and setters for all table columns and relations class Author { protected $data = []; public function __get($key) { return $this->data[$key] ?? null; } public function __set($key, $value) { $this->data[$key] = $value; } } $manager->registerGenericMapperWithClassName('author', Author::class); // you can also add custom mappers (check the docs) $author = $manager->author()[0]; // this is an Author instance // as for changing objects // one way is to do it manually $authors = $manager->author(); $author = $authors[0]; $author->name = "Test"; $manager->getMapper('author')->update($author); // or use the unit of work manager and have all changes automatically saved $manager = new \vakata\orm\UnitOfWorkManager($db, new \vakata\orm\UnitOfWork($db)); $book = new Book(); $book->name = "Book name"; $book->author = $manager->author()->find(1); $tag = new Tag('tag'); $book->tags = $tag; $book->author->name = "Changed name"; $manager->books()->add($book); $manager->tags()->add($tag); // all you need to do is call this line $manager->save();

Read more in the API docs, (*5)

Testing

bash $ composer test, (*6)

Contributing

Please see CONTRIBUTING for details., (*7)

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker., (*8)

Credits

License

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

The Versions

25/05 2018

dev-master

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

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

25/05 2018

7.3.0

7.3.0.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

04/05 2018

7.2.1

7.2.1.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

16/04 2018

7.2.0

7.2.0.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

13/12 2017

7.1.3

7.1.3.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

13/12 2017

7.1.2

7.1.2.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

18/06 2017
18/06 2017
19/05 2017
13/05 2017
03/05 2017
02/05 2017
02/05 2017
26/04 2017
26/04 2017
26/04 2017
25/04 2017
05/04 2017
05/04 2017
02/03 2017
01/02 2017
26/01 2017
26/01 2017
16/12 2016
15/12 2016
06/12 2016
02/12 2016
30/11 2016

4.0.4

4.0.4.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

30/11 2016

4.0.3

4.0.3.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

30/11 2016

4.0.2

4.0.2.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

30/11 2016

4.0.1

4.0.1.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

24/11 2016

4.0.0

4.0.0.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata

19/11 2016
19/11 2016
01/11 2016
28/10 2016
27/10 2016
21/10 2016
21/10 2016
26/09 2016
26/09 2016
17/09 2016
17/09 2016
15/09 2016
15/09 2016
13/09 2016
13/09 2016
13/09 2016
18/07 2016
18/07 2016
04/07 2016
16/04 2016
15/12 2015
29/11 2015

1.0.0

1.0.0.0 https://github.com/vakata/orm

An ORM implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

orm vakata