This blog is a knowledge base...where I clip cool tricks and urls

ORM by Urielka

clipped from www.urielkatz.com

  • transactions - used inside GearsORM itself

  • self relations(i.e. a relation to the same table/model) - very useful when working with Tree-like structures in the database

  • count method - so now u can do Person.count() instead of Person.select().toArray().length

The most important update in this version is of course transaction support.
SQLite is known for really bad write preformence when not working with transactions.
While developing transaction support for GearsORM i had to write a test,in that test it execute 100 inserts and 100 updates,this test take about 15 seconds for the inserts and about 10 seconds for the updates without transactions,when using transactions for each set it takes about 377ms for the inserts and 200ms for the updates that is about 39 times faster!

 blog it

SQL : coalesce to avoid OR in optional parameters

SQL : coalesce to avoid OR in optional parameters
clipped from weblogs.sqlteam.com

Next, we have a string comparison based on product code.  These also can be very efficiently rewritten by using LIKE.  Normally, LIKE is much slower than using equals, but if you do not use any wild cards and it allows you to eliminate an "OR" in your WHERE clause, it may actually be more efficient:

    select *
    from Data
    where
        Date between coalesce(@MinDate, '1/1/1900') and coalesce(@MaxDate, '12/31/2999') and
        Amount between coalesce(@MinAmount,-999999999) and coalesce(@MaxAmount,999999999) and
        ProductCode like coalesce(@ProductCode,'%') and ...
 blog it