Skip to content

Commit

Permalink
Add TODO and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hall committed Feb 3, 2011
1 parent 4991cc1 commit 69f172b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Error handling
* Nicer API with beforeSave and afterSave hooks for each table
* Table structure modification
33 changes: 11 additions & 22 deletions titaniorm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

var db = function(database, table) {

// Private

var database = Titanium.Database.open(database);
var db_schema = [];

Expand All @@ -15,7 +17,7 @@ var db = function(database, table) {
var createTable = function(schema) {
db_schema = schema;

var sql = 'CREATE TABLE ' + table + ' (';
var sql = 'CREATE TABLE IF NOT EXISTS ' + table + ' (';
sql += "\n\tid INTEGER PRIMARY KEY";
for(var field in schema) {
sql += ",\n\t" + schema[field] + ' TEXT'; //SQLite has dynamic typing, so everything can be text :D
Expand All @@ -25,6 +27,8 @@ var db = function(database, table) {
execute(sql);
}


// @TODO: Finish this and run when table already exists and schema differs
var updateTable = function(schema) {
var sql = 'BEGIN TRANSACTION;';
sql += 'CREATE TEMPORARY TABLE ' + table + '_backup(a,b);';
Expand Down Expand Up @@ -105,6 +109,12 @@ var db = function(database, table) {
execute(sql, values);
}

function deleteQuery(id) {
var sql = 'DELETE FROM ' + table + ' WHERE id = ?';

execute(sql, [id]);
}

return {

// Public properties
Expand All @@ -128,24 +138,3 @@ var db = function(database, table) {
}
}
}

//db.execute('INSERT INTO scrapbooks (ID, LABEL, IMAGE, GPS, ORDINAL) VALUES(?,?,?,?,?)'




/*
var db = Titanium.Database.open('fishingscrapbook');
var rows = db.execute('SELECT * FROM scrapbooks');
var newOrdinal = 0;
while (rows.isValidRow()) {
var ordinal = rows.fieldByName('ORDINAL');
if (ordinal > newOrdinal) {
newOrdinal = ordinal;
}
rows.next();
}
*/

0 comments on commit 69f172b

Please sign in to comment.