Last active
August 29, 2015 13:58
-
-
Save animista01/9993966 to your computer and use it in GitHub Desktop.
WebSQL implemented in Coffeescript
This file contains hidden or 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
| 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