Created
September 6, 2012 14:30
-
-
Save ograycode/3656872 to your computer and use it in GitHub Desktop.
Persistence.js Quirk -- ids are universal
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
| Output: | |
| wrong.setUp(); | |
| undefined | |
| CREATE TABLE IF NOT EXISTS `TABLE_FOUR` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_THREE` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_TWO` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_ONE` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| SELECT `root`.id AS TABLE_FOUR_id, `root`.`C1` AS `TABLE_FOUR_C1`, `root`.`C2` AS `TABLE_FOUR_C2`, `root`.`C3` AS `TABLE_FOUR_C3`, `root`.`C4` AS `TABLE_FOUR_C4` FROM `TABLE_FOUR` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| no ref data found, populating... wrong.js:120 | |
| Finished updating reference data. wrong.js:155 | |
| wrong.queryFast(); | |
| undefined | |
| SELECT `root`.id AS TABLE_ONE_id, `root`.`C1` AS `TABLE_ONE_C1`, `root`.`C2` AS `TABLE_ONE_C2`, `root`.`C3` AS `TABLE_ONE_C3`, `root`.`C4` AS `TABLE_ONE_C4` FROM `TABLE_ONE` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| SELECT `root`.id AS TABLE_TWO_id, `root`.`C1` AS `TABLE_TWO_C1`, `root`.`C2` AS `TABLE_TWO_C2`, `root`.`C3` AS `TABLE_TWO_C3`, `root`.`C4` AS `TABLE_TWO_C4` FROM `TABLE_TWO` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Two type: TABLE_ONE wrong.js:93 | |
| Table_Two type: TABLE_ONE wrong.js:93 | |
| Table_Two type: TABLE_ONE wrong.js:93 | |
| Table_Two type: TABLE_ONE wrong.js:93 | |
| Table_Two type: TABLE_ONE wrong.js:93 | |
| SELECT `root`.id AS TABLE_THREE_id, `root`.`C1` AS `TABLE_THREE_C1`, `root`.`C2` AS `TABLE_THREE_C2`, `root`.`C3` AS `TABLE_THREE_C3`, `root`.`C4` AS `TABLE_THREE_C4` FROM `TABLE_THREE` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Three type: TABLE_ONE wrong.js:99 | |
| Table_Three type: TABLE_ONE wrong.js:99 | |
| Table_Three type: TABLE_ONE wrong.js:99 | |
| Table_Three type: TABLE_ONE wrong.js:99 | |
| Table_Three type: TABLE_ONE wrong.js:99 | |
| SELECT `root`.id AS TABLE_FOUR_id, `root`.`C1` AS `TABLE_FOUR_C1`, `root`.`C2` AS `TABLE_FOUR_C2`, `root`.`C3` AS `TABLE_FOUR_C3`, `root`.`C4` AS `TABLE_FOUR_C4` FROM `TABLE_FOUR` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Four type: TABLE_ONE wrong.js:105 | |
| Table_Four type: TABLE_ONE wrong.js:105 | |
| Table_Four type: TABLE_ONE wrong.js:105 | |
| Table_Four type: TABLE_ONE wrong.js:105 | |
| Table_Four type: TABLE_ONE |
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
| wrong.setUp(); | |
| undefined | |
| CREATE TABLE IF NOT EXISTS `TABLE_FOUR` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_THREE` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_TWO` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| CREATE TABLE IF NOT EXISTS `TABLE_ONE` (`C1` TEXT, `C2` TEXT, `C3` TEXT, `C4` TEXT, `id` VARCHAR(32) PRIMARY KEY) null persistence.store.websql.js:78 | |
| SELECT `root`.id AS TABLE_FOUR_id, `root`.`C1` AS `TABLE_FOUR_C1`, `root`.`C2` AS `TABLE_FOUR_C2`, `root`.`C3` AS `TABLE_FOUR_C3`, `root`.`C4` AS `TABLE_FOUR_C4` FROM `TABLE_FOUR` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| no ref data found, populating... wrong.js:120 | |
| Finished updating reference data. wrong.js:155 | |
| wrong.queryFast(); | |
| undefined | |
| SELECT `root`.id AS TABLE_ONE_id, `root`.`C1` AS `TABLE_ONE_C1`, `root`.`C2` AS `TABLE_ONE_C2`, `root`.`C3` AS `TABLE_ONE_C3`, `root`.`C4` AS `TABLE_ONE_C4` FROM `TABLE_ONE` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| Table_One type: TABLE_ONE wrong.js:87 | |
| SELECT `root`.id AS TABLE_TWO_id, `root`.`C1` AS `TABLE_TWO_C1`, `root`.`C2` AS `TABLE_TWO_C2`, `root`.`C3` AS `TABLE_TWO_C3`, `root`.`C4` AS `TABLE_TWO_C4` FROM `TABLE_TWO` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Two type: TABLE_TWO wrong.js:93 | |
| Table_Two type: TABLE_TWO wrong.js:93 | |
| Table_Two type: TABLE_TWO wrong.js:93 | |
| Table_Two type: TABLE_TWO wrong.js:93 | |
| Table_Two type: TABLE_TWO wrong.js:93 | |
| SELECT `root`.id AS TABLE_THREE_id, `root`.`C1` AS `TABLE_THREE_C1`, `root`.`C2` AS `TABLE_THREE_C2`, `root`.`C3` AS `TABLE_THREE_C3`, `root`.`C4` AS `TABLE_THREE_C4` FROM `TABLE_THREE` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Three type: TABLE_THREE wrong.js:99 | |
| Table_Three type: TABLE_THREE wrong.js:99 | |
| Table_Three type: TABLE_THREE wrong.js:99 | |
| Table_Three type: TABLE_THREE wrong.js:99 | |
| Table_Three type: TABLE_THREE wrong.js:99 | |
| SELECT `root`.id AS TABLE_FOUR_id, `root`.`C1` AS `TABLE_FOUR_C1`, `root`.`C2` AS `TABLE_FOUR_C2`, `root`.`C3` AS `TABLE_FOUR_C3`, `root`.`C4` AS `TABLE_FOUR_C4` FROM `TABLE_FOUR` AS `root` WHERE 1=1 [] persistence.store.websql.js:78 | |
| Table_Four type: TABLE_FOUR wrong.js:105 | |
| Table_Four type: TABLE_FOUR wrong.js:105 | |
| Table_Four type: TABLE_FOUR wrong.js:105 | |
| Table_Four type: TABLE_FOUR wrong.js:105 | |
| Table_Four type: TABLE_FOUR |
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
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"> </script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/zefhemel/persistencejs/master/lib/persistence.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/zefhemel/persistencejs/master/lib/persistence.store.sql.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/zefhemel/persistencejs/master/lib/persistence.store.websql.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="wrong.js"></script> | |
| </head> | |
| <body> | |
| Run these commands: | |
| <br/> | |
| wrong.setUp();<br/> | |
| wrong.queryFast(); | |
| </body> | |
| </html> |
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
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"> </script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/zefhemel/persistencejs/master/lib/persistence.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/ograycode/persistencejs/master/lib/persistence.store.sql.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="https://raw.github.com/zefhemel/persistencejs/master/lib/persistence.store.websql.js"></script> | |
| <script type="text/javascript" charset="utf-8" src="wrong.js"></script> | |
| </head> | |
| <body> | |
| Run these commands: | |
| <br/> | |
| wrong.setUp();<br/> | |
| wrong.queryFast(); | |
| </body> | |
| </html> |
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
| var wrong = { | |
| db : { | |
| dbObj : '', | |
| openDb : function () { | |
| if (wrong.db.dbObj === '') { | |
| wrong.db.dbObj = persistence.store.websql.config(persistence,'NAME', '1.0', 'D_NAME', 2 * 1024 * 1024); | |
| } | |
| return wrong.db.dbObj; | |
| }, | |
| tableOne : function () { | |
| wrong.db.openDb(); | |
| var tableOne = persistence.define('TABLE_ONE', { | |
| C1 : 'TEXT', | |
| C2 : 'TEXT', | |
| C3 : 'TEXT', | |
| C4 : 'TEXT', | |
| }); | |
| return { | |
| new_tableOne : function () { | |
| return new tableOne(); | |
| }, | |
| tableOne : function () { | |
| return tableOne; | |
| } | |
| }; | |
| }, | |
| tableTwo : function () { | |
| wrong.db.openDb(); | |
| var tableTwo = persistence.define('TABLE_TWO', { | |
| C1 : 'TEXT', | |
| C2 : 'TEXT', | |
| C3 : 'TEXT', | |
| C4 : 'TEXT', | |
| }); | |
| return { | |
| new_tableTwo : function () { | |
| return new tableTwo(); | |
| }, | |
| tableTwo : function () { | |
| return tableTwo; | |
| } | |
| }; | |
| }, | |
| tableThree : function () { | |
| wrong.db.openDb(); | |
| var tableThree = persistence.define('TABLE_THREE', { | |
| C1 : 'TEXT', | |
| C2 : 'TEXT', | |
| C3 : 'TEXT', | |
| C4 : 'TEXT', | |
| }); | |
| return { | |
| new_tableThree : function () { | |
| return new tableThree(); | |
| }, | |
| tableThree : function () { | |
| return tableThree; | |
| } | |
| }; | |
| }, | |
| tableFour : function () { | |
| wrong.db.openDb(); | |
| var tableFour = persistence.define('TABLE_FOUR', { | |
| C1 : 'TEXT', | |
| C2 : 'TEXT', | |
| C3 : 'TEXT', | |
| C4 : 'TEXT', | |
| }); | |
| return { | |
| new_tableFour : function () { | |
| return new tableFour(); | |
| }, | |
| tableFour : function () { | |
| return tableFour; | |
| } | |
| }; | |
| }, | |
| }, | |
| queryFast : function () { | |
| wrong.db.tableOne().tableOne().all().list(null, function (tableOneResults){ | |
| tableOneResults.forEach(function(tor){ | |
| console.log("Table_One type: " + tor._type); | |
| }); | |
| }); | |
| wrong.db.tableTwo().tableTwo().all().list(null, function (tableTwoResults){ | |
| tableTwoResults.forEach(function(ttr){ | |
| console.log("Table_Two type: " + ttr._type); | |
| }); | |
| }); | |
| wrong.db.tableThree().tableThree().all().list(null, function (tableThreeResults){ | |
| tableThreeResults.forEach(function(ttrr){ | |
| console.log("Table_Three type: " + ttrr._type); | |
| }); | |
| }); | |
| wrong.db.tableFour().tableFour().all().list(null, function (tableFourResults){ | |
| tableFourResults.forEach(function(tfr){ | |
| console.log("Table_Four type: " + tfr._type); | |
| }); | |
| }); | |
| }, | |
| setUp : function () { | |
| wrong.db.tableOne().tableOne(); | |
| wrong.db.tableTwo().tableTwo() | |
| wrong.db.tableThree().tableThree() | |
| wrong.db.tableFour().tableFour() | |
| persistence.schemaSync(); | |
| wrong.db.tableFour().tableFour().all().list(null, function(rows){ | |
| if (rows.length <= 0){ | |
| console.log("no ref data found, populating...") | |
| var data = []; | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "0")'); | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "1")'); | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "2")'); | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "3")'); | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "4")'); | |
| data.push('insert into TABLE_ONE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "5")'); | |
| data.push('insert into TABLE_TWO (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "0")'); | |
| data.push('insert into TABLE_TWO (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "1")'); | |
| data.push('insert into TABLE_TWO (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "2")'); | |
| data.push('insert into TABLE_TWO (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "3")'); | |
| data.push('insert into TABLE_TWO (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "4")'); | |
| data.push('insert into TABLE_THREE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "0")'); | |
| data.push('insert into TABLE_THREE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "1")'); | |
| data.push('insert into TABLE_THREE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "2")'); | |
| data.push('insert into TABLE_THREE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "3")'); | |
| data.push('insert into TABLE_THREE (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "4")'); | |
| data.push('insert into TABLE_FOUR (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "0")'); | |
| data.push('insert into TABLE_FOUR (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "1")'); | |
| data.push('insert into TABLE_FOUR (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "2")'); | |
| data.push('insert into TABLE_FOUR (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "3")'); | |
| data.push('insert into TABLE_FOUR (C1, C2, C3, C4, id) values ("1", "2", "3", "4", "4")'); | |
| var db = window.openDatabase('NAME', '1.0', 'D_NAME', 2 * 1024 * 1024); | |
| db.transaction(populateDB, errorCB, successCB); | |
| function errorCB(err) { | |
| alert("Error "+err.message); | |
| } | |
| function successCB() { | |
| console.log("Finished updating reference data.") | |
| } | |
| function populateDB(tx) { | |
| for (var index in data){ | |
| tx.executeSql(data[index]); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment