Introducing JStORM

UPDATE:Adobe AIR support is in svn trunk

I am happy to announce the first beta of JStORM,a complete rewrite of GearsORM to support multiple backends,currently supporting Jaxer(MySQL and Sqlite) and Google Gears(Sqlite).

This version is a complete rewrite of GearsORM,it changed the way it works internally and also the API.

The first change is that every model have it own connection to the database,this is in order to enable different models connected to different databases.

Another interesting change is the JStORM.Query class,this class allows for easily querying the models.
a query instance can be obtain by calling the all method of the model,lets define a simple model:

var Person = new JStORM.Model({
firstName:new JStORM.Field({type:"String",maxLength:25}),
lastName:new JStORM.Field({type:"String",maxLength:25}),

For example to print all the persons in the database:


What the all function do is to create a new instance of JStORM.Query for Person model.
Other function that return a query is filter,filter return a query filtered by a criteria,for example:

var katzFamily = Person.filter("lastName = ?","Katz");

A thing to note about Query is that it is lazy evaluated,so invoking the method filter or all doesn`t query the database until you start iterating over the result.

Queries can be filtered many times to create a AND expression between criterias(note that each call to filter create a new query object):

var uriels = Person.filter("firstName = ?","Uriel");
var urielKatzs = uriels.filter("lastName = ?","Katz");
console.log("People with first name Uriel: " + uriels.count());
console.log("People with name Uriel Katz: " + urielKatzs.count());

Query objects have various methods for example the count method:

var numberOfMembers = Person.filter("lastName = ?","Katz").count();
console.log("Katz family have " +numberOfFamilyMembers + " members");

The count method return the number of objects that matched the criteria of the Query object,it use the SQL COUNT function.

There is also the remove method,which delete all the objects that match the criteria:

Person.filter("firstName = ?","Uriel").remove();

The remove method uses the SQL DELETE statment.

This early release is to show the new api and support for Jaxer,there is some stuff lacking that were in GearsORM:

  • Many to many relations - still can be done but need to define tables manually(will be added in 0.4)
  • Foreign key constrains - this are a pain in Sqlite since they are implemented with triggers,i am considering dropping support for this

I can`t show the all api in this post,currently there is no documentation,so you can see examples for api usage in the unit tests.

In the next weeks i will focus on testing,writing documentation and improving JStORM for final release, keep checking the blog for updates on JStORM.



P.S.:As always bug reports and fixes are welcome,also if anyone wants to help either with the code and documentation(especially in this,since my english isn`t that good).


  1. Chris Thatcher Sep 30

    Very cool Uriel, I wondering what is the minimal additional work I can do to add support for using JStORM in a java environment via Rhino/Tomcat? I'll gladly contribute it back to you, but was hoping for a brief overview of the things I might need to understand to add MySQL support for a java container. Thanks! And awesome work. Thatcher

  2. philip andrew Oct 1

    This is really going to help with the Jaxer development, I'll be using this.

  3. uriel katz Oct 1

    @Philip: Good to hear,if you find any bug or have any question send me a e-mail @Chris: Thanks,basically to support a new backend you need to implement the JStORM.[YourProviderName].Connection and JStORM.[YourProviderName].ResultSet you can see a example for this in JStORM.AIR.js and JStORM.Gears.js(JStORM.Jaxer inherits almost everything from Gears since they have a really similar API).

  4. vpsivam Oct 1

    Great Work! This going to make the JS code easier to maintain and readable. Thanks Uriel.

  5. Derrick Burns Nov 7

    Please consider Google App Engine (BigTable) support. It is not backed by a SQL database, as you may know. And, while its server side API is very similar to yours (Django derivative), there is no client-side API. This is a big gap that hampers development.

  6. Uriel Katz Nov 11

    Google App Engine works with Python,while JStORM is a ORM for JavaScript so i don`t think this is possible unless there is a JavaScript API

  7. Joey Novak Dec 6

    Hi Uriel, I'd like to help out with documentation. Thin Server Thick Client web apps are the way of the future and this ORM project is a sweet jumpstart. Shoot me an email. Thanks! Joey

  8. Joey Novak Dec 6

    Here is a simple JStORM example using GoogleGears: Just look at the source.

  9. Argenis Leon Dec 14

    Check this out A ORM Active Record project from the Aptana team

  10. Mark Story Jan 14

    Very nice work, not to complain, but couldn't it be called JSTORM instead. That lowercase t would cause tons of errors for fast/sloppy typers like me.

  11. Max Mar 7

    This looks great but I can't get access to the repository ( It redirects to which does not exist. Am I missing something or is it not available.

  12. Uriel Katz Mar 7

    It works now. Thank you so much for noticing,after i upgraded my server OS some modules were removed one of them were libapache2-svn.

  13. Amit Sep 17

    I am extremely used JStORM and it's nice ORM. I have following questions 1. How can I declare "PRIMARY KEY"? 2. How can I declare "AUTOINCREMENT"? 3. How can I declare "NOT NULL" and "DEFAULT NULL"? Please let me know with example Regards Amit Pandya

  14. Amit Sep 17

    I tried following way but it can't work isPrimaryKey:true,allowNull:false example Person = new JStORM.Model({ name:"Person", fields: { remoteId:new JStORM.Field({type:"Integer",isPrimaryKey:true,allowNull:false}), firstName:new JStORM.Field({type:"String",maxLength:25}), lastName:new JStORM.Field({type:"String",maxLength:25}) } Regards Amit Pandya

  15. Nicolas Nov 14

    Is this project still alive ??? I'm really interested in it !!

  16. Uriel Katz Nov 14

    I don`t really have time to work on it but i can help you by e-mail in anything you need related to this project. The project code is very stable and has a rich feature-set,the problem is the docs.

  17. Lula Mar 9

    Does JStORM support compound primary keys. Primary key made of two or more fields?

  18. Uriel Katz Mar 10

    JStORM doesn`t support compound keys.