Skip to content

Instantly share code, notes, and snippets.

@hungryzi
Created January 20, 2013 07:20
Show Gist options
  • Save hungryzi/4577128 to your computer and use it in GitHub Desktop.
Save hungryzi/4577128 to your computer and use it in GitHub Desktop.
Using superfeedr/indexeddb-backbone-adapter
# Defining schema
schema =
id: 'todos-database'
migrations: [
{
version: '1',
migrate: (db, req, next) ->
store = db.createObjectStore('todos')
next();
},
{
version: '2',
migrate: (db, req, next) ->
store = req.transaction.objectStore('todos')
store.createIndex('nameIndex', 'name', unique: false)
next()
}
]
# Modifying Backbone objects
app.Todos = Backbone.Collection.extend
database: schema
storeName: 'todos'
# ...
app.Todo = Backbone.Model.extend
database: schema
storeName: 'todos'
# ...
# Querying
todos = new app.Todos()
todos.fetch
conditions:
format: ["a", "f"]
offset: 10
limit: 5
success: ->
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment