Skip to content

Instantly share code, notes, and snippets.

@animista01
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save animista01/9993966 to your computer and use it in GitHub Desktop.

Select an option

Save animista01/9993966 to your computer and use it in GitHub Desktop.
WebSQL implemented in Coffeescript
db = null
constructor: ->
# WebSQL Database
db = openDatabase('myDB', '1.0', 'this is my DB', 2 * 1024 * 1024)
db.transaction (tx) =>
tx.executeSql("CREATE TABLE IF NOT EXISTS mytable (id, name, stuff)",
[],
(tx, results) => console.log(results),
(tx, error) => console.error(error),
)
anInsert: ->
db.transaction (tx) =>
tx.executeSql("INSERT INTO mytable (id, name, stuff) VALUES (?, ?, ?)",
[1, 'Test', 'a stuff'],
(tx, results) => console.log(results),
(tx, error) => console.error(error)
)
aDelete: ->
db.transaction (tx) =>
tx.executeSql("DELETE FROM mytable WHERE (id = ?)", [1], (tx, results) =>
#Do something
, (tx, error) => console.error(error))
aSelect: ->
db.transaction (tx) =>
tx.executeSql("SELECT * FROM mytable WHERE id=?", [1], (tx, results) =>
rLength = results.rows
for i in rLength
name = results.rows.item(_i).name
console.log name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment