TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
LEAP ORM for Kohana
  • After working with Kohana's ORM, Jelly, and Sprig for a while, I found that I needed some additional features as I worked on some big projects. I ended up having to write my own ORM module for Kohana and dubbed it, LEAP.

    The LEAP ORM has a number of features (many of which are not present in the other ORMs for Kohana):

    • Plugins for DB2, Firebird, MariaDB, MS SQL, MySQL, Oracle, PostgreSQL, and SQLite.
    • The ability to select a specific database driver (e.g. PDO).
    • Connection pooling.
    • Query building that sanitizes data to help prevent SQL insertion attack.
    • Validates field data.
    • Field aliases, adapters, and relationships.
    • Composite keys.
    • A companion Web site.

    The LEAP ORM module can be downloaded at https://github.com/spadefoot/kohana-orm-leap.

  • Hello Spadefoot,

    I had a quick look on Leap ORM and at the first glance I have a pretty serious problem with it: it creates and executes the model schema definition on every model instance creation, in the constructor. It must be fixed imo - the schema definition should be loaded once per model class, not for every single model object.

    Thanks for posting about your project, keep up the job :) and please write some more tutorials (first of all object querying, and using the active records' methods).

  • @Crystal Thanks for the feedback! I will put it in the improvements queue. As an FYI, I have tested it on large sets of data and performance is still good....but your suggestions will definitely improve it. Please feel free to log such issues in the project's issue tracker.

  • A few quick suggestions:

    1. Use tabs for indenting. Right now you are using a mix of tabs and spaces and it makes your code almost impossible to read. I would also recommend reading the Kohana coding style guide, following these rules will help make your code easier for others to read.

    2. Don't suppress errors using @, this makes debugging issues almost impossible. Kohana will convert these errors into exceptions and you can handle them using try/catch.

    3. As near as I can tell (I only looked quickly), you aren't escape your variables correctly. Where does the escaping happen? I don't see any calls to mysql_real_escape_string, maybe I'm missing something? You should make sure everything is escaped correctly using the methods provided by the database you are using. Sanitizing data isn't a replacement for escaping it.

    4. Unit tests. For a larger code base like this you need unit tests to make sure things are working correctly. Without them it is impossible to trust your code.

  • @Isaiah Much appreciated! I now have something to do this weekend. Heheh...

    As for your suggestions, I would like to ask you a few things:

    1. Could you recommend a way for me to fix the indentation problem because my text editor (i.e. TextMate) correctly aligns the code but Github does not? As for Kohana coding styling, I will look into what needs to be changed....but if you have specific styling corrections I will be happy to entertain them.

    2. I will look at replacing the @ sign with exceptions. However, when used, exception handling is still done to ensure debugging is possible but I will definitely look at changing such.

    3. I have done a lot of research as to what mysql_real_escape_string actually does and the code should address all of those concerns but I will be happy to revisit that.

    4. Unit tests are on the agenda as indicated in the README, but I will move that up in the queue of things to do. If you want, please submit any unit tests and I will include them.

    Again, I appreciate the feedback.....your feedback is making this project only better.

  • If you turn on white spaces in textmate you should be able to see where you used spaces and where tabs are used. You should replace all the spaces with tabs. I'm not sure if there is a way to automate this with textmate, but it shouldn't be too hard to do by hand.

    Yeah I see that you are checking the return value after using @, but using exceptions (something Kohana provides for you), is much better.

    There is no replacement for mysql_real_escape_string if you are using the mysql_* methods. The only way you can avoid using it is if you use mysqli_* or pdo methods with prepared statements. It's impossible to escape your data correctly without mysql_real_escape_string because you don't have the correct charset from the database to know how to escape your data.

    Glad you hear you are working on unit tests. I hope I didn't give you too much work for this weekend ;) Looks like an interesting project!

  • I have added these issues to LEAP's issue tracker. Thanks for taking the time to review it.

  • @Crystal I addressed your concern with regards to loading field meta data over the weekend.... I did a performance test using the following two queries and Leap consistently out performed Kohana's ORM:

        $results = DB_ORM::select('user')->query();
        $results = ORM::factory('user')->find_all();

    @Isaiah I made all spaces tabs now and have made a number of changes to the codebase in accordance with Kohana's Conventions and Styling, and have started on adding some unit tests....

  • Those two lines don't really seem to be the same thing. One looks like the query builder (no specific model class) and the other is loading specifically user models.

    Or at least the syntax is confusing to me.

  • @zombor Both return models. The syntax is different because they follow different design patterns.

  • @spadefoot, looks better but I would be very concerned about how you are escaping data. It doesn't seem safe at all to me. You really should be using native database methods like mysql_real_escape_string.

  • @Isaiah I have that in the queue as per our previous conversation....

  • Okay good. I just didn't (still don't in fact) see it on the github issue tracker. It's kind of an important issue because nobody should use this until you have that working ;)

  • @Isaiah I just added it to the issue tracker. I thought I had added it already. This problem is not being ignored....it will be addressed here shortly..... The only way I learn of these issues is from feedback.....which I much appreciate!!!!

    I would encourage anyone finding problems with the module to please fork it and send me a pull request with the fix, or at least add the problem to the project's issue tracker. The more people we have looking at it, the more robust it will be and the better the project will be. Like all projects, it has its bugs....especially since it is so new....

    I will solve this problem asap.....so please continue testing it out for your feedback is much appreciated..... A few hipcups, but we are smoothing them out.

  • Another ORM! Fuck.

  • Haha. If I had the time there's be yet another too :P (Or I'd work on Jelly some more)

  • @Isaiah I added the mysql_real_escape_string (and the like functions).

  • How can I define many-to-many relations?

  • The plan is to release the many-to-many relationship soon along with the leap-auth module. I will add this feature to Leap's issue tracker.

  • What about auto form builder like sprig, is have?

  • @angelside Good idea....I will look into adding this feature. Thanks for the suggestion.

  • @angelside FYI, LEAP ORM models can now generate HTML form labels and controls. Just specify which control you want to use in the model's field definitions.

  • I was wondering how the callback functions work for field definitions. Are they called before save/ after load? Other than that I'm loving Leap ^^

  • just found out it's just a validation callback, never mind my previous post ^^

  • Hello, am pretty interested by your module but i got stopped at the first trial.am using kohana 3.2 am quite new on kohana, but i've used zend and doctrine for php and hibernate/jpa for java. i'am having session corrupt exception.i've found that the session schema included in the leap is a little different

    //default orm version
    CREATE TABLE `sessions` (
      `session_id` VARCHAR(24) NOT NULL,
      `last_active` INT(10) UNSIGNED NOT NULL,
      `contents` TEXT NOT NULL,
      PRIMARY KEY (`session_id`),
      KEY `last_active` (`last_active`)
    //leap version
    CREATE TABLE `sessions` (
      `id` VARCHAR(24) NOT NULL,
      `last_active` INT(11) NOT NULL,
      `contents` LONGTEXT NOT NULL,
      PRIMARY KEY (`id`)

    after i run the default orm version the error is gone. Please advise

  • @blacksensei I just added this issue to LEAP's issue tracker. I will have a look at what might be causing the problem and get back to you shortly.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion