Last active
July 11, 2020 14:07
Revisions
-
aaronksaunders revised this gist
May 28, 2014 . 1 changed file with 75 additions and 73 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,97 +1,99 @@ exports.definition = { config : { "columns" : { "name" : "TEXT", "captured" : "integer", "url" : "TEXT", "capturedLat" : "real", "capturedLong" : "real" }, "defaults" : { "name" : "", "captured" : 0, "url" : "", "capturedLat" : "", "capturedLong" : "" }, "adapter" : { "type" : "sql", "collection_name" : "fugitives" } }, extendModel : function(Model) { _.extend(Model.prototype, { }); // end extend return Model; }, extendCollection : function(Collection) { // helper functions function S4() { return (0 | 65536 * (1 + Math.random())).toString(16).substring(1); } function guid() { return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4(); } _.extend(Collection.prototype, { deleteAll : function() { var collection = this; var sql = "DELETE FROM " + collection.config.adapter.collection_name; db = Ti.Database.open(collection.config.adapter.db_name); db.execute(sql); db.close(); collection.trigger('sync'); }, saveAll : function() { var collection = this; var dbName = collection.config.adapter.db_name; var table = collection.config.adapter.collection_name; var columns = collection.config.columns; db = Ti.Database.open(dbName); db.execute("BEGIN;"); collection.each(function(model) { if (!model.id) { model.id = guid(); model.attributes[model.idAttribute] = model.id; } var names = [], values = [], q = []; for (var k in columns) { names.push(k); values.push(model.get(k)); q.push("?"); } var sqlInsert = "INSERT INTO " + table + " (" + names.join(",") + ") VALUES (" + q.join(",") + ");"; db.execute(sqlInsert, values); }); db.execute("COMMIT;"); db.close(); collection.trigger('sync'); } }); // end extend return Collection; } }; -
aaronksaunders revised this gist
Feb 22, 2014 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,13 @@ exports.definition = { function S4() { return (0 | 65536 * (1 + Math.random())).toString(16).substring(1); } function guid() { return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4(); } config : { "columns" : { "name" : "TEXT", @@ -48,8 +56,6 @@ exports.definition = { saveAll : function() { var collection = this; var dbName = collection.config.adapter.db_name; var table = collection.config.adapter.collection_name; @@ -62,7 +68,7 @@ exports.definition = { collection.each(function(model) { if (!model.id) { model.id = guid(); model.attributes[model.idAttribute ] = model.id; } -
aaronksaunders revised this gist
Mar 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ exports.definition = { var sql = "DELETE FROM " + collection.config.adapter.collection_name; db = Ti.Database.open(collection.config.adapter.db_name); db.execute(sql); db.close(); collection.trigger('sync'); -
aaronksaunders revised this gist
Mar 4, 2013 . 1 changed file with 10 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -55,6 +55,10 @@ exports.definition = { var table = collection.config.adapter.collection_name; var columns = collection.config.columns; db = Ti.Database.open(dbName); db.execute("BEGIN;"); collection.each(function(model) { if (!model.id) { @@ -69,16 +73,15 @@ exports.definition = { q.push("?"); } var sqlInsert = "INSERT INTO " + table + " (" + names.join(",") + ") VALUES (" + q.join(",") + ");"; db.execute(sqlInsert, values); }); db.execute("COMMIT;"); db.close(); collection.trigger('sync'); } }); // end extend -
aaronksaunders revised this gist
Mar 1, 2013 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,20 @@ // add all items to collection Alloy.Collections.Fugitive.reset([{ "name" : "Jeff Haynie" }, { "name" : "Nolan Wright" }, { "name" : "Don Thorp" }, { "name" : "Marshall Culpepper" }, { "name" : "Blain Hamon" }]); // save all the items Alloy.Collections.Fugitive.saveAll(); // get the collection object Alloy.Collections.instance("Fugitive"); -
aaronksaunders revised this gist
Mar 1, 2013 . 1 changed file with 40 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,10 +37,48 @@ exports.definition = { var collection = this; var sql = "DELETE FROM " + collection.config.adapter.collection_name; db = Ti.Database.open(collection.config.adapter.db_name); db.execute(sql, model.id); db.close(); collection.trigger('sync'); }, saveAll : function() { var collection = this; var util = require("alloy/sync/util"); var dbName = collection.config.adapter.db_name; var table = collection.config.adapter.collection_name; var columns = collection.config.columns; collection.each(function(model) { if (!model.id) { model.id = util.guid(); model.attributes[model.idAttribute ] = model.id; } var names = [], values = [], q = []; for (var k in columns) { names.push(k); values.push(model.get(k)); q.push("?"); } var sqlInsert = "INSERT INTO " + table + " (" + names.join(",") + ") VALUES (" + q.join(",") + ");"; db = Ti.Database.open(dbName); db.execute("BEGIN;"); db.execute(sqlInsert, values); db.execute("COMMIT;"); db.close(); collection.trigger('sync'); }); } }); // end extend -
aaronksaunders created this gist
Mar 1, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ // get the collection object Alloy.Collections.instance("Fugitive"); // delete all items Alloy.Collections.Fugitive.deleteAll(); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ exports.definition = { config : { "columns" : { "name" : "TEXT", "captured" : "integer", "url" : "TEXT", "capturedLat" : "real", "capturedLong" : "real" }, "defaults" : { "name" : "", "captured" : 0, "url" : "", "capturedLat" : "", "capturedLong" : "" }, "adapter" : { "type" : "sql", "collection_name" : "fugitives" } }, extendModel : function(Model) { _.extend(Model.prototype, { }); // end extend return Model; }, extendCollection : function(Collection) { _.extend(Collection.prototype, { deleteAll : function() { var collection = this; var sql = "DELETE FROM " + collection.config.adapter.collection_name ; db = Ti.Database.open(collection.config.adapter.db_name); db.execute(sql); db.close(); } }); // end extend return Collection; } }