Skip to content

Commit

Permalink
addressed issue #18 - fixed support for negative integers and floats …
Browse files Browse the repository at this point in the history
…- force check for floats before ints - improved coverage, added testing for export and import functionality - other minor fixes/improvements
  • Loading branch information
Pamblam committed Feb 6, 2018
1 parent 2dccd92 commit 6dd2fb8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function(grunt) {
},
options: {
replacements: [{
pattern: /\d.\d.\d/g,
pattern: /\d+.\d+.\d+/g,
replacement: '<%= pkg.version %>'
}]
}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2018 Rob Parham

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![jSQL Logo](http://i.imgur.com/VQlJKOc.png)](http://pamblam.github.io/jSQL/)

jSQL (Official) - Version 3.2.2 - *Now available without a prescription!*
jSQL (Official) - Version 3.2.9 - *Now available without a prescription!*

[![npm version](https://badge.fury.io/js/jsql-official.svg)](https://badge.fury.io/js/jsql-official) [![Build Status](https://travis-ci.org/Pamblam/jSQL.svg?branch=master)](https://travis-ci.org/Pamblam/jSQL) [![Inline docs](http://inch-ci.org/github/Pamblam/jSQL.svg?branch=master)](https://github.com/Pamblam/jSQL/wiki) [![Coverage Status](https://coveralls.io/repos/github/Pamblam/jSQL/badge.svg?branch=master)](https://coveralls.io/github/Pamblam/jSQL?branch=master)

Expand Down Expand Up @@ -81,7 +81,7 @@ jSQL is fully documented in the [jSQL Wiki](https://github.com/Pamblam/jSQL/wiki

## Browser Support

Works in basically all browsers. jSQL degrades gracefully because it falls back on cookies for persistence if localStorage, IndexedDB and WebSQL are not available. To that end, the library itself does not take advantage of any ES6 features, if you want something that does, have a look at [alaSQL](https://github.com/agershun/alasql).
Works in basically all browsers. jSQL degrades gracefully because it falls back on cookies for persistence if localStorage, IndexedDB and WebSQL are not available.

While jSQL will work in basically all browsers, these ones are preferred:

Expand Down
16 changes: 8 additions & 8 deletions jSQL.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* jsql-official - v3.2.2
* jsql-official - v3.2.9
* A persistent SQL database.
* @author Rob Parham
* @website http://pamblam.github.io/jSQL/
Expand Down Expand Up @@ -1028,15 +1028,15 @@ function jSQLUpdateQuery(){
if(!this.table.keys.primary.map.hasOwnProperty(col) ||
this.table.keys.primary.map[col] != new_rows[i].rowIndex) continue;
delete this.table.keys.primary.map[col];
this.table.keys.primary.map[new_rows[i].pk_vals] = rowIndex;
this.table.keys.primary.map[new_rows[i].pk_vals] = new_rows[i].rowIndex;
break;
}
for(var k=0; ukey=this.table.keys.unique[k]; k++){
for(var col in this.table.keys.unique[k].map){
if(!this.table.keys.unique[k].map.hasOwnProperty(col) ||
this.table.keys.unique[k].map[col] != new_rows[i].rowIndex) continue;
delete this.table.keys.unique[k].map[col];
this.table.keys.unique[k].map[new_rows[i].uni_vals[k]] = rowIndex;
this.table.keys.unique[k].map[new_rows[i].uni_vals[k]] = new_rows[i].rowIndex;
break;
}
}
Expand Down Expand Up @@ -1156,12 +1156,12 @@ jSQLLexer.token_types = [
name: "WHITESPACE"},

// NUMBERs
{pattern: /\d+/g,
type: 'NUMBER',
name: 'INTEGER'},
{pattern: /\d+.\.\d+/g,
{pattern: /[?-]?\d+.\.\d+/g,
type: 'NUMBER',
name: 'FLOAT'},
{pattern: /[?-]?\d+/g,
type: 'NUMBER',
name: 'INTEGER'},

// QUALIFIERs
{pattern: /if not exists/gi,
Expand Down Expand Up @@ -2816,7 +2816,7 @@ function jsql_import(dump){
}

return {
version: "3.2.2",
version: "3.2.9",
tables: {},
query: jSQLParseQuery,
createTable: createTable,
Expand Down
4 changes: 2 additions & 2 deletions jSQL.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsql-official",
"version": "3.2.2",
"version": "3.3.0",
"description": "A persistent SQL database.",
"main": "jSQL.min.js",
"directories": {
Expand Down
8 changes: 4 additions & 4 deletions src/lexer/token_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jSQLLexer.token_types = [
name: "WHITESPACE"},

// NUMBERs
{pattern: /\d+/g,
type: 'NUMBER',
name: 'INTEGER'},
{pattern: /\d+.\.\d+/g,
{pattern: /[?-]?\d+.\.\d+/g,
type: 'NUMBER',
name: 'FLOAT'},
{pattern: /[?-]?\d+/g,
type: 'NUMBER',
name: 'INTEGER'},

// QUALIFIERs
{pattern: /if not exists/gi,
Expand Down
4 changes: 2 additions & 2 deletions src/query_types/jSQLUpdateQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ function jSQLUpdateQuery(){
if(!this.table.keys.primary.map.hasOwnProperty(col) ||
this.table.keys.primary.map[col] != new_rows[i].rowIndex) continue;
delete this.table.keys.primary.map[col];
this.table.keys.primary.map[new_rows[i].pk_vals] = rowIndex;
this.table.keys.primary.map[new_rows[i].pk_vals] = new_rows[i].rowIndex;
break;
}
for(var k=0; ukey=this.table.keys.unique[k]; k++){
for(var col in this.table.keys.unique[k].map){
if(!this.table.keys.unique[k].map.hasOwnProperty(col) ||
this.table.keys.unique[k].map[col] != new_rows[i].rowIndex) continue;
delete this.table.keys.unique[k].map[col];
this.table.keys.unique[k].map[new_rows[i].uni_vals[k]] = rowIndex;
this.table.keys.unique[k].map[new_rows[i].uni_vals[k]] = new_rows[i].rowIndex;
break;
}
}
Expand Down
42 changes: 42 additions & 0 deletions test/test5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var expect = require('chai').expect;
var jSQL = require("../jSQL.js");

jSQL.load(()=>{
jSQL.query("-- Generated with jSQL Devel on Tuesday, February 6th 2018, 3:31pm \n\
CREATE TABLE IF NOT EXISTS `testeroo` (\n\
`id` INT(5) NOT NULL,\n\
`name` VARCHAR(5) NULL,\n\
`another_id` NUMERIC(6) NOT NULL,\n\
`uni1` INT(3) NOT NULL UNIQUE KEY,\n\
`uni2` INT(3) NOT NULL UNIQUE KEY,\n\
PRIMARY KEY (`id`, `another_id`)\n\
)").execute();

var sql = "insert into testeroo values(?, ?, ?, ?, ?)";
jSQL.query(sql).execute([0,'farts',1,5,9]);
jSQL.query(sql).execute([1,'tird',2,6,8]);
jSQL.query(sql).execute([1,'berb',3,7,7]);
jSQL.query(sql).execute([5,'farts',4,1,6]);

var exp = jSQL.export(true, ['testeroo']);

jSQL.reset();

setTimeout(()=>{
jSQL.import(exp);

describe('Export Test', function () {

it('Testing Export up in this biaaatch', function(){
var q = jSQL.query("select * from testeroo where id = 1").execute().fetchAll("ASSOC").length;
expect(q.length === 2).to.be.true;
});

});
}, 1000);


});



0 comments on commit 6dd2fb8

Please sign in to comment.