xavierlacot / joli.js

joli.js is an Activerecord-like javascript ORM, particularly suited for being used in the Appcelerator Titanium Mobile framework.
MIT License
267 stars 60 forks source link

can set SQL computed value to a field #33

Open iamyellow opened 11 years ago

iamyellow commented 11 years ago

Maybe others find interesting some changes I made to joli.js in order to (for example) create a new record setting its properties with SQL statements. Well, I think an example will explain this better than me:

var data = this.newRecord({
  id: "SQL(strftime('%Y%m%d%H%M%f', 'now'))",
  userId: 33,
  message: 'hi',
  flag: 0
});

In this example the 'id' field will be a timestamp generated using SQLite time functions. Then:

data.save();
Ti.API.info(data.get('id')); // this prints something like '20121019070437.809'

Hope you find useful enough :)