Ruby on Rails like ActiveRecord for javascript using html5 localstorage on JS.Class
Every request is asynchronous, so you do not get a result back, but provide a callback that is called when the query is finished. Later Sync should be used, but so far openDatabaseSync is not implemented in any browser.
Just some basic plumbing done(see below), help appreciated!
- AR.connection().execute('SQL', function(resultAsHash){ ... })
- u = User.new({name:'xxx'}); u.name == 'xxx'; u.save
- User.create({name: 'Bla blub', foo: 1111})
- User.all(function(users){ ... })
- User.all({conditions: "name = 1", limit: 1, offset: 2, having: .... }, function(users){ ... })
- User.find(id, function(user){ ... })
<script src="vendor/js.class/core.js"></script>
<script src="lib/ar.js"></script>
<script>
AR.connection().execute("DROP TABLE User")
User = new JS.Class(AR, {extend: {
tableName:'User',
columns: [
['id', 'REAL UNIQUE'],
['name', 'STRING'],
['foo', 'INTEGER'],
['bar', 'TEXT']
]
}})
User.createTable()
- example test.html needs to be accessed as root on e.g. localhost
- if you have rack: go into folder and
rackup
, then go to localhost:9292/test.html
- first / count / sum
- joining
- associations (belongsTo / HasMany)