Alex Rivera | Logout

Are there any ORM frameworks for Web SQL (javascript)?

Asked 2010-08-31T20:26:27.167
9

Anyone knows if there's one available now or will be in a near future?

Edit
Report

2 Answers

7

There's a new one called JayData library, this one is like EntityFramework (or NHibernate) for the JavaScript platform: provides JavaScript Language Query (JSLQ) and JavaScript CRUD. Also supports model definitions, navigationProperties and 1..1.0, 1..m, m..n relations.

I copy a short codesnippet on how to use it:

//define storage model: Department and Employee in a 1..m relation

$data.Entity.extend("$org.types.Department", {
  Id: { type: "int", key: true, computed: true },
  Name: { type: "string", required: true },
  Address: { type: "string" },
  Employees: { type: "Array", elementType: "$org.types.Employee", inverseProperty:"Department" }
});


$data.Entity.extend("$org.types.Employee", {
  Id: { type: "int", key: true, computed: true },
  FirstName: { type: "string", required: true },
  LastName: { type: "string", required: true }, 
  Department: { type: "$org.types.Department", inverseProperty:"Employees"}
});

$data.EntityContext.extend("$org.types.OrgContext", {
  Department: { type: $data.EntitySet, elementType: $org.types.Department },
  Employee: { type: $data.EntitySet, elementType: $org.types.Employee }
});

You can code against the OrdContext and the collections in it. The following line will create a context instance that is backed by local WebSQL (you have other options like indexeddb or OData)

var context = new $org.types.OrgContext({ name: "webSql", databaseName: "OrgDB" });

Add some data

var department = new $org.types.Department({ Name: 'Finance', Employees: [] });

var emp1 = new $org.types.Employee({ FirstName: 'John', LastName: 'Smith'});
department.Employees.push(emp1);

var emp2 = new $org.types.Employee({ FirstName: 'Jane', LastName: 'Smith'});
emp2.Department = department;

context.add(department);
context.
answered 2012-05-19T07:47:35.883
3

I am looking for the same thing. It seems like slim pickings. The one that looked the most promising to me is persistence.js. Impel also looks good but, unfortunately, it looks like it hasn't been updated in a year and a half. ActiveRecord.js could end up working out, but it doesn't seem like they are supporting Web SQL yet. Hopefully someone will post some more options.

answered 2010-11-05T17:42:33.160

Your Answer