Skip to content

Commit 13fcde7

Browse files
committed
Fixed key persistence
1 parent 1a93922 commit 13fcde7

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
![enter image description here](http://i.imgur.com/VQlJKOc.png)
1+
[![jSQL Logo](http://i.imgur.com/VQlJKOc.png)](http://pamblam.github.io/jSQL/)
22

3-
jSQL - Version 2.0 - *Now gluten free!*
3+
jSQL - Version 2.1 - *Now gluten free!*
44

55
<hr>
66

examples/keys/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
// Create a non-compound key using high-level syntax
3232
jSQL.query("create table if not exists myTable (ID int primary, Name varchar, FOOD varchar)").execute(data);
3333

34-
//jSQL.insertInto('myTable').values({ID:0, Name:'Nerd', FOOD: "Bagels"}).ignore().execute();
34+
// Insert ignore low level syntax
35+
// jSQL.insertInto('myTable').values({ID:0, Name:'Nerd', FOOD: "Bagels"}).ignore().execute();
3536

36-
jSQL.query("insert into myTable VALUES (0, 'nerd', 'bagel')").execute();
37+
// This will the primary key, adding "ignore" prevents it from throwing an error
38+
jSQL.query("insert ignore into myTable VALUES (0, 'nerd', 'bagel')").execute();
39+
40+
jSQL.commit();
3741

3842
console.log("done");
3943
});

jSQL.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* jSQL.js v2
2+
* jSQL.js v2.1
33
* A Javascript Query Language Database Engine
44
* @author Robert Parham
5-
* @website https://github.com/Pamblam/jSQL#jsql
5+
* @website http://pamblam.github.io/jSQL/
66
* @license http://www.apache.org/licenses/LICENSE-2.0
77
*/
88

@@ -2085,14 +2085,21 @@
20852085
var rows = [];
20862086
for(var tbl in jSQL.tables){
20872087
if(!jSQL.tables.hasOwnProperty(tbl)) continue;
2088+
2089+
var keys = [];
2090+
for(var i=0; i<jSQL.tables[tbl].keys.unique.length; i++)
2091+
keys.push({column: jSQL.tables[tbl].keys.unique.column, type: "unique"});
2092+
if(jSQL.tables[tbl].keys.primary.column)
2093+
keys.push({column: jSQL.tables[tbl].keys.primary.column, type: "primary"});
2094+
20882095
var data = jSQL.select("*").from(tbl).execute().fetchAll();
20892096
for(var i=data.length; i--;){
20902097
var row = data[i];
20912098
for(var n in row){
20922099
if(!row.hasOwnProperty(n)) continue;
20932100
row[n] = jSQL.tables[tbl].normalizeColumnStoreValue(n, row[n]);
20942101
}
2095-
rows.push({table: tbl, data:JSON.stringify(row), colTypes: JSON.stringify(jSQL.tables[tbl].types)});
2102+
rows.push({table: tbl, data:JSON.stringify(row), colTypes: JSON.stringify(jSQL.tables[tbl].types), keys: JSON.stringify(keys)});
20962103
}
20972104
}
20982105
self.api.delete("jSQL_data_schema", function(){
@@ -2135,13 +2142,14 @@
21352142
var tablename = r[i].table;
21362143
var rowdata = JSON.parse(r[i].data);
21372144
var colTypes = JSON.parse(r[i].colTypes);
2145+
var keys = JSON.parse(r[i].keys);
21382146
// Create the table in memory if it doesn't exist yet
21392147
if(undefined === jSQL.tables[tablename]){
21402148
var cols = [];
21412149
for(var c in rowdata)
21422150
if(rowdata.hasOwnProperty(c))
21432151
cols.push(c);
2144-
jSQL.createTable(tablename, cols, colTypes).execute();
2152+
jSQL.createTable(tablename, cols, colTypes, keys).execute();
21452153
}
21462154

21472155
for(var c in rowdata){
@@ -2336,7 +2344,7 @@
23362344
////////////////////////////////////////////////////////////////////////////
23372345

23382346
return {
2339-
version: 2,
2347+
version: 2.1,
23402348
tables: {},
23412349
query: jSQLParseQuery,
23422350
createTable: createTable,

jSQL.min.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)