ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Gas ORM

October 23, 2011 4:00pm

Subscribe [45]
  • #1 / Oct 23, 2011 4:00pm

    toopay

    1583 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

  • #2 / Oct 24, 2011 4:34pm

    JonoB

    133 posts

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

    You guys should all contribute together.

  • #3 / Oct 25, 2011 12:44am

    toopay

    1583 posts

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

    You guys should all contribute together.

    😊 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 😊

  • #4 / Oct 25, 2011 5:48am

    Stefano G

    62 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 😊

    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 😉

  • #5 / Oct 25, 2011 8:28pm

    toopay

    1583 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.

  • #6 / Oct 26, 2011 5:04am

    Stefano G

    62 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.

  • #7 / Oct 26, 2011 8:32am

    JonoB

    133 posts

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

    You guys should all contribute together.

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

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

  • #8 / Oct 26, 2011 12:14pm

    sineld

    14 posts

    Cool work. Thanks.

  • #9 / Oct 26, 2011 1:48pm

    toopay

    1583 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 😊 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.

  • #10 / Oct 27, 2011 2:44am

    Stefano G

    62 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 😉

    I’ll wait for the fix also 😊

    Stefano

  • #11 / Oct 28, 2011 2:34am

    Stefano G

    62 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! 😊


    Stefano

  • #12 / Nov 01, 2011 8:35pm

    toopay

    1583 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.

     

     

  • #13 / Nov 03, 2011 6:20am

    toopay

    1583 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.

  • #14 / Nov 03, 2011 6:01pm

    ardinotow

    162 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

  • #15 / Nov 03, 2011 10:56pm

    toopay

    1583 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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases