EllisLab text mark
Advanced Search
1 of 18
1
   
Gas ORM
Posted: 23 October 2011 04:00 PM   [ Ignore ]
Avatar
Joined: 2010-12-20
1590 posts

A lighweight and easy-to-use ORM for CodeIgniter. Gas was built specifically for CodeIgniter app. It uses standard CI DB packages, also take anvantages of its validator class. Gas provide methods that will map your database table and its relation, into accesible object.

For download or recent update, look at GasORM @ GitHub. This library also available at Sparks. For guide and example go to Documentation for version 1.x.x.

Requirements

1. PHP v.5.2.x
2. CodeIgniter v.2.x.x

Features

1. Supported databases : cubrid, mssql, mysql, oci8, odbc, postgre, sqlite, sqlsrv.
2. Support multiple database connection.
3. Support modular models directories and sub-models directories.
4. Multiple relationship (has_one, has_many, belongs_to, has_and_belongs_to) with custom relationship setting (through, foreign_key, foreign_table, self).
5. Auto-create models from database tables and vice versa, and auto-synchronize models-tables by creating migrations file.
6 Per-request caching.
7. Self-referential and adjacency column/data (hierarchical data).
8. Eager Loading.
9. Various finder method (can chained with most of CI AR syntax) and aggregates.
10. Validation and auto-mapping input collection, with minimal setup.
11. Hooks points, to control over your model.
12. Extensions, to share your common function/library/helper/plugin across your model instances.
13. Transaction and other CI AR goodness.
14. Command Line Interface.

Planned Features

1. Support for tree traversal data.
More useful features.

NOTE : latest version is v.1.4.3 (also compatible with the latest CI 2.1.0), if you using < v.1.3.0, please update. Also note that Auto-create models from tables and vice versa require CI v.2.1.x

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 24 October 2011 04:34 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-08-15
154 posts

Two weeks and two new CI orms….what is the world coming to? smile

You guys should all contribute together.

 
Posted: 25 October 2011 12:44 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts
JonoB - 24 October 2011 04:34 PM

Two weeks and two new CI orms….what is the world coming to? smile

You guys should all contribute together.

smile JonoB, i dont know what you mean or refer, by stating “two new CI ORMS”. Actually, in CI world, there was already great ORM, which is DataMapper. If i should choose, between Doctrine, PHP AR or that (DataMapper), i will actually choose DataMapper. Because it utilize all CI goodness, rather than bring feoreign packages (a huge one) into your codebase. So, by using semi-native ORM like this(DataMapper, or Gas), you remove yourself from the duplication carried by foreign code/packages from your codebase, such as Doctrine or PHP AR, which each have their own database and validator package(s).

But for some reasons, especially easy-to-use part, i found DataMapper slightly “obsolete” compared with recent popular ORM, in terms how they utilize and make user easier to implement their ORM methods. Thats why for my recent CI app, i create my own. Feel free to submit any issue/bugs you found, and thats why i publish this library for.

Because some user which test it last night, send me a message that they have an issue when running in PHP < 5.3, and i found it because in my initial version, i have some line that passing…

func_get_args(); 

directly as a function’s parameter, and that will fail in PHP under 5.3, so i know whats wrong, and my recent app avoid future potential bugs early.

So when i wrote this (and other library i have in my signature), i have a business case smile

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 25 October 2011 05:48 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-05
65 posts

Just a quick note, when you retrieve a relationship

$user->kid 
that returns no rows, the resulting array is not empty so
count($user->kid

always returns 1.

This behaviour can also be noticed when doing a foreach loop on the same relation.

Also, a way of sorting/ordering the results would be very welcome grin

Stefano

PS I know I am stressing you but I like the fact that your ORM is very lightweight compared to others, so I’d really like to use it in my next projects wink

 Signature 

Visit my CodeIgnited webpage @ http://www.stefanogiordano.it

 
Posted: 25 October 2011 08:28 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@Stefano, thanks for doing some research/test on it, i appreciate that. I just merge several commits, beside fixes some issue which reported by some user, iam also adding a controller contain unit-testing procedure to performing test : evaluate all available implementation to determine if it is producing the correct data type and result, feel free to submit any issue(s) if you still found any.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 26 October 2011 05:04 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-05
65 posts

The main issue I still have, is the “empty relations” problem

count($user->kid

that always returns 1 even if the User has no Kids.

 Signature 

Visit my CodeIgnited webpage @ http://www.stefanogiordano.it

 
Posted: 26 October 2011 08:32 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-08-15
154 posts
toopay - 25 October 2011 12:44 AM
JonoB - 24 October 2011 04:34 PM

Two weeks and two new CI orms….what is the world coming to? smile

You guys should all contribute together.

smile JonoB, i dont know what you mean or refer, by stating “two new CI ORMS”.

http://ellislab.com/forums/viewthread/202060/

 
Posted: 26 October 2011 12:14 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2011-07-13
15 posts

Cool work. Thanks.

 Signature 

I love CI !

Send E-mails with Gmail Account:
https://github.com/sineld/CI-Gmail

 
Posted: 26 October 2011 01:48 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@Stefano G :
You may notice that because you are try to fetch a child object from a user resources which has one-to-many or many-to-many relationship, you should expect to accept an array (just like if you go with PHP AR, for example). So actually, if you do

var_dump(empty($user->kid));
// Because $user->kid actually contain : array( 0 => FALSE) 

It will returns true, mean that user really didnt have kid smile But you are right, it should be just empty array, so i will ship this fix in next commit maybe in upcoming day.

Also regarding order_by clause, this was easily can achieve by chaining those method (eg:order_by) with one of available finder method (all, find_by_something, etc).

@JonoB, ah, ok.

@sineld, you’re welcome.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 27 October 2011 02:44 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-05
65 posts

Ok thanks I will check the order_by clause, maybe some more examples in the readme file would be great as ordering the results is something really important wink

I’ll wait for the fix also smile

Stefano

 Signature 

Visit my CodeIgnited webpage @ http://www.stefanogiordano.it

 
Posted: 28 October 2011 02:34 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-05
65 posts

I can confirm that this fragment actually works as a charm:

$user = new User;
$u1 $user->order_by('is_author''asc')
           ->
order_by('id''desc')
           ->
all();
if (
$user->has_result()) {      
foreach ($u1 as $u)
   
print_r($u->to_array()) ."\n";

Maybe you should mention in the userguide that mixing GAS/CI Active Records clauses DOES work! an ORM library that weights 26Kb is terrific! smile


Stefano

 Signature 

Visit my CodeIgnited webpage @ http://www.stefanogiordano.it

 
Posted: 01 November 2011 08:35 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Updated to v.1.0.3

Changes :
1. Add factory pattern implementation, via static function.
2. Add fill() method, to automaticly mapped $_POST data for next save() method
3. Design and performance improvement.

 

 

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 03 November 2011 06:20 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

For license compatibility reasons, i ended up change all my library license, including Gas ORM from GPL to compatible license. By latest commit, Gas ORM is now also compatibility with PHP v.5.2.x, since some issues reporting by user based by previous commit (same version) under PHP 5.2, which apparently caused by Scope Resolution Operator.

Oh btw, i’m start adding language files, so if your language isn’t there, dont hesitate to add/pull request your language on it.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 03 November 2011 06:01 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
163 posts

Taufan, I can’t use has_result() to catch empty result. I’ve got an error when trying to get data that isn’t exist (should return empty value), my script is

$user Gas::factory('users_data');
$profile $user->find(2)->user_profiles

. How to solve that? Thanks

edited: p.s I use CI 2.0.3, HMVC 5.4, and Gas 1.0.3

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 03 November 2011 10:56 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@ardinotow, In earlier version, when we try to fetch record(s) from a table using a finder with Gas ORM, either we try to fetch a set of records or just a single record which didnt exist, Gas will return an instance with empty record, so we could use ‘has_result’ method. This could be a problems, since if the records exist, find() will return an object while all() will return a set/array of object. To resolve this non uniformal behaviour, i had encourage people to use empty(), because Gas will return FALSE(for single record method) or empty array(for all(), or any finder which expect more than one records) if queries return an empty response.

So, you could do something like this instead:

$user Gas::factory('users_data')->find(2);

$profile = empty($user) ? 'User not found.' $user->user_profiles

Soon, i will remove ‘has_result’ method from Gas.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 04 November 2011 07:59 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
163 posts

Thanks, it works. I think you should write full documentation and should be easy to understand just like Codeigniter’s user guide on Active Record. Sukses slalu Mas!

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
1 of 18
1