Last active
December 11, 2015 08:58
-
-
Save hungryzi/4577117 to your computer and use it in GitHub Desktop.
Using neo/indexeddb-backbone-adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defining schema | |
IndexedDBBackbone.describe('todos') | |
.createStore('todos', { keyPath: 'id' }) | |
.createIndex('todos', 'nameIndex', 'name', unique: false) | |
# Models & Collections | |
app.Todos = Backbone.Collection.extend | |
database: 'todos' | |
storeName: 'todos' | |
# ... | |
app.Todo = Backbone.Model.extend | |
database: 'todos' | |
storeName: 'todos' | |
# ... | |
# Querying | |
query = new IndexedDBBackbone.IDBQuery('todos', 'nameIndex') | |
.bounds("a", "f").limit(5).offset(10) | |
todos = new app.Todos() | |
todos.fetch | |
query: query | |
success: -> | |
# ... | |
# Transaction | |
Backbone.transaction [accounts], () -> | |
accountA.withdraw(amount); | |
accountB.deposit(amount); | |
if (something_goes_wrong) | |
return false # this rollbacks the transaction | |
else | |
return true # this commits the transaction, | |
, { | |
success: -> | |
# successful | |
error: -> | |
# something went wrong. everything's rollbacked. $ stay where it was. | |
abort: -> | |
# everything's rollbacked. $ stay where it was | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment