EllisLab text mark
Advanced Search
     
NitroORM (new ORM for CodeIgniter)
Posted: 13 October 2011 09:20 PM
Avatar
Joined: 2011-10-13
4 posts

Hi guys! I’m new to the forum but I’ve been a CI user for a long time now and I wanted to introduce you to a new ORM I made together with a friend/colleague.

We named it NitroORM (http://nitro-orm.net/), it’s 100% pure PHP, which means that declaring mapping is as easy as creating a PHP array, and even easier since Nitro can generate it for you. The Generator is a accessed through CI controller and it can generate the mapping and the models.

Here are some of it’s many cool features:

* Can be installed as a Spark (http://getsparks.org/packages/Nitro/versions/HEAD/show)
* Pure PHP Generator, no CLI or XML!
* Multiple database support
* Incredibly extensible: every core class extends from an empty user class
* Supported relations: Inheritance, OneToOne, OneToMany, ManyToOne, ManyToMany
* Easy creation of custom relations

Check out the wiki (https://bitbucket.org/___flatline___/nitro/wiki/) for the documentation.


We are using it in production right now and it’s working just fine, but if any of you decide to give it a try and find any bugs or have any suggestions, we are happy to hear them, just drop an issue on our bitbucket repo (https://bitbucket.org/___flatline___/nitro/) or drop us a line on our twitter (https://twitter.com/NitroORM).

I hope you like it! And any feedback is more than welcome!

 
Posted: 14 October 2011 08:38 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-08-15
154 posts

A ‘Base’ model class, let’s say BaseProduct, BaseUser, BaseWhatever.
This class has all the table settings parsed, like Active Record name (where the table belongs), the table name, and all getters/setters for its fields and defined relationships.
IMPORTANT: This class should never be hand-edited, NitroGen will overwrite this file each time it runs!

What is defined as ‘each time it runs’?

 
Posted: 14 October 2011 01:14 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2011-10-13
4 posts
JonoB - 14 October 2011 08:38 AM

A ‘Base’ model class, let’s say BaseProduct, BaseUser, BaseWhatever.
This class has all the table settings parsed, like Active Record name (where the table belongs), the table name, and all getters/setters for its fields and defined relationships.
IMPORTANT: This class should never be hand-edited, NitroGen will overwrite this file each time it runs!

What is defined as ‘each time it runs’?

Hi JonoB, what we tried to say (and failed raspberry) is that the Base entity classes are overwritten by Nitro each time you generate them (by running the Generator for that AR group or Entity) but not the user entity clases.

Let me know if you got it, we are still correcting the wiki, there are some things that aren’t well redacted and I’d like to be as clear as possible, thanks for making us note this one!

 
Posted: 14 October 2011 01:41 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-08-15
154 posts

I suspected (and hoped!) thats what you were trying to say…just checking smile

The Generator is what creates the Base class, and not when you use the user Class.

Next questions:

1. How does NitroOrm compare to DataMapper (http://datamapper.wanwizard.eu/)?
2. How do you treat the N+1 problem when loading associations?
3. Can you do validation in your models?

 
Posted: 14 October 2011 05:49 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2011-10-13
4 posts
JonoB - 14 October 2011 01:41 PM

I suspected (and hoped!) thats what you were trying to say…just checking smile

The Generator is what creates the Base class, and not when you use the user Class.

Next questions:

1. How does NitroOrm compare to DataMapper (http://datamapper.wanwizard.eu/)?
2. How do you treat the N+1 problem when loading associations?
3. Can you do validation in your models?

1)
I guess one of the main differences is that Nitro generates the entity models with all the getters/setters methods for it’s fields and relations leaving you an empty class to add your own methods or overload existing ones instead of giving you overloaded access to the fields as properties mapped by the magic __get/set methods, letting you overload them individually and give them a special functionality if you want.

Also, Nitro has a couple more relations Inheritance and ManyToOne, which in essence are very similar between them and OneToOne.

Inheritance is in charge of mapping which field/method/relation belongs to the child and which ones to the parents chain, besides Inheritance is a real PHP inheritance so if you have a Person and a User entities, custom methos that you declare in Person will also be available from User.

ManyToOne is the exact oposite of OneToMany and the main difference with OneToOne is that it does not require the relation to be made form a foreign key of the PKs.

There sure are a lot more differences.

2)
A collection’s data PKs are loaded in a single query and the data on each loop, but, if, while looping, the collection finds an instance that was used before in the execution it gets it from the instance pool thus improving performance and getting the latest data for that instance even if it wasn’t saved to the database yet.

The xToMany relations methods on the models have filter parameters to get collections with a subset of the data by passing them in the $params array, it supports ‘where’, ‘order_by’, ‘group_by’, ‘limit_value’ and ‘limit_offset’.

But the associations are loaded on user request. If you are looping through a collection of cars and want to get the list of wheels, the wheels are requested to the db on each loop, we still have to find an efficient way to solve this because it’s not true that you’ll want every association loaded beforehand all the time, that would just issue a monolithic query when it’s not necessary.

3)
Nitro models validation is one of the things that are on the development queue, as well as concurrency control (which will probably come first in the coming weeks).