diff --git a/build_helper/build.js b/build_helper/build.js index ce0a8ab..79b745e 100644 --- a/build_helper/build.js +++ b/build_helper/build.js @@ -44,7 +44,6 @@ generateParser = function () { 'src/grammar/select_join.pegjs', 'src/grammar/update.pegjs', 'src/grammar/open.pegjs', - 'src/grammar/is_db_exist.pegjs', 'src/grammar/common.pegjs', 'src/grammar/constant.pegjs' ]); diff --git a/package-lock.json b/package-lock.json index d92b3f8..aac2688 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sqlweb", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3668,9 +3668,9 @@ "dev": true }, "jsstore": { - "version": "3.11.0", - "resolved": "https://registry.npmjs.org/jsstore/-/jsstore-3.11.0.tgz", - "integrity": "sha512-GpbzcIomtBtpeW76pf2tOdHA6+lroudVseoanruDjh94gf453GRRcTrA1qtCREMVDBgIcz0fSmaKYFX/pBQ5HQ==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/jsstore/-/jsstore-4.0.4.tgz", + "integrity": "sha512-JowsFZc2VQ28/ZJy/kFZNA6C3o1yRRcqgQ1E6fPoyMXQrRyLkiPOlxSgtZBOFm0A8w9NrL4NXV/evSX2H75n0A==", "dev": true }, "karma": { diff --git a/package.json b/package.json index 008b3eb..b308368 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "devDependencies": { "chai": "^4.2.0", "fs-extra": "^7.0.1", - "jsstore": "^3.11.0", + "jsstore": "^4.0.4", "karma": "^4.1.0", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^2.2.0", @@ -57,6 +57,6 @@ "webpack-merge": "^4.2.1" }, "peerDependencies": { - "jsstore": ">=3.11.0" + "jsstore": ">=4.0.3" } } diff --git a/src/grammar/index.pegjs b/src/grammar/index.pegjs index b4d12ce..cc5c659 100644 --- a/src/grammar/index.pegjs +++ b/src/grammar/index.pegjs @@ -1,2 +1,2 @@ -query = selectQuery/countQuery/insertQuery/updateQuery/removeQuery/createQuery/openQuery/isDbExistQuery ; +query = selectQuery/countQuery/insertQuery/updateQuery/removeQuery/createQuery/openQuery ; diff --git a/src/grammar/is_db_exist.pegjs b/src/grammar/is_db_exist.pegjs deleted file mode 100644 index f83b863..0000000 --- a/src/grammar/is_db_exist.pegjs +++ /dev/null @@ -1,23 +0,0 @@ -isDbExistQuery = ISDBEXIST _* name:dbName _* tblInfo: tableInfo? { - var result = { - api:'isDbExist' - } - if(tblInfo==null){ - result.data=name; - } - else{ - result.data={ - dbName:name, - table:tblInfo - } - } - return result; -} - -tableInfo = TABLE _* table:tableName _* ver:version { - return { - name:table, - version:ver - } -} - diff --git a/test/cases/create/demo.js b/test/cases/create/demo.js index 3494a61..86b008d 100644 --- a/test/cases/create/demo.js +++ b/test/cases/create/demo.js @@ -1,24 +1,15 @@ describe('create demo database', function () { it('use isexist and then open/create db', function (done) { console.log('initiate database'); - con.$sql.run('isDbExist Demo').then(function (isExist) { - console.log('db exist :' + isExist); - if (isExist) { - con.$sql.run('openDb Demo').then(function () { - console.log('Database opened'); - done(); - }); - } else { - var query = getDbSchema(); - con.$sql.run(query).then(function () { - console.log('Database created'); - done(); - }); - } + var query = getDbSchema(); + con.$sql.run(query).then(function (isDbCreated) { + console.log('Database created'); + expect(isDbCreated).equal(true); + done(); }).catch(function (err) { done(err); }); - }); + }) }); // con.jsStoreCon_.isDbExist('Demo').then(function (exist) { diff --git a/test/cases/delete/delete.js b/test/cases/delete/delete.js index 732bc00..29be9f1 100644 --- a/test/cases/delete/delete.js +++ b/test/cases/delete/delete.js @@ -1,263 +1,266 @@ describe('Test delete Api', function () { it('delete with where', function (done) { var count; + con.logStatus = true; con.$sql.run("count from Customers where Country = 'Sweden'"). - then(function (results) { - count = results - }).catch(function (err) { - done(err); - }) + then(function (results) { + count = results + }).catch(function (err) { + done(err); + }) con.$sql.run("delete from Customers where Country = 'Sweden'"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }) + + // console.log("request queue", con.req) }); it('remove with or', function (done) { var count; con.$sql.run("Count * from Customers where Country='Mexico' || City='Madrid'"). - then(function (results) { - count = results; - }).catch(function (err) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (err) { + done(err); + }) con.$sql.run("deLete from Customers where Country='Mexico' || City='Madrid'"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }) }); it('remove with in', function (done) { var count; con.$sql.run("count from Customers where Country in ('Germany', 'France', 'UK')"). - then(function (results) { - count = results; - }).catch(function (err) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (err) { + done(err); + }) con.$sql.run("delete from Customers where Country in ('Germany', 'France', 'UK')"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }) }); it('remove with operator - != (for string)', function (done) { var count; con.$sql.run("count from Customers where Country != 'Mexico'"). - then(function (results) { - count = results; - }).catch(function (err) { - done(err); - }); + then(function (results) { + count = results; + }).catch(function (err) { + done(err); + }); con.$sql.run("delete from Customers where Country != 'Mexico'"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }); + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }); }); it('remove with operator - != (for number)', function (done) { var count; con.$sql.run("count from Products where Price!=20"). - then(function (results) { - count = results; - }).catch(function (err) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (err) { + done(err); + }) con.$sql.run("delete from Products where Price!=20"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }) }); it('remove with operator - >', function (done) { var count; con.$sql.run("count from Products where Price>20"). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("delete from Products where Price>20"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove with operator - >=', function (done) { var count; con.$sql.run("count from Products where Price>=20"). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("delete from Products where Price>=20"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove with operator - <', function (done) { var count; con.$sql.run("count from Products where Price<20"). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("DELETE from Products where Price<20"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove with operator - <=', function (done) { var count; con.$sql.run("count from Products where Price<=20"). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("DELETE from Products where Price<=20"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove with operator - between', function (done) { var count; con.$sql.run("count from Products where Price betWeen (10,20)"). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("delete from Products where Price betWeen (10,20)"). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove with like- "%or%"', function (done) { var count; con.$sql.run("count from Customers where CustomerName like '%or%' "). - then(function (results) { - count = results; - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + count = results; + done(); + }).catch(function (err) { + done(err); + }) con.$sql.run("delete from Customers where CustomerName like '%or%' "). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (err) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (err) { + done(err); + }) }); it('remove with like- "%or"', function (done) { var count; con.$sql.run("count from Customers where CustomerName like '%or' "). - then(function (results) { - count = results; - con.$sql.run("delete from Customers where CustomerName like '%or' "). then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); + count = results; + con.$sql.run("delete from Customers where CustomerName like '%or' "). + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }).catch(function (results) { done(err); - }) - }).catch(function (results) { - done(err); - }); + }); }); it('remove with like- "or%"', function (done) { var count; con.$sql.run("count from Customers where CustomerName like 'or%' "). - then(function (results) { - count = results; - }).catch(function (results) { - done(err); - }) + then(function (results) { + count = results; + }).catch(function (results) { + done(err); + }) con.$sql.run("delete from Customers where CustomerName like 'or%' "). - then(function (results) { - expect(results).to.be.an('number').to.equal(count); - done(); - }).catch(function (results) { - done(err); - }) + then(function (results) { + expect(results).to.be.an('number').to.equal(count); + done(); + }).catch(function (results) { + done(err); + }) }); it('remove all - using promise', function (done) { var Count; con.$sql.run("count from Customers"). - then(function (results) { - Count = results; - }).catch(function (results) { - done(err); - }); + then(function (results) { + Count = results; + }).catch(function (results) { + done(err); + }); con.$sql.run("delete from Customers"). - then(function (results) { - expect(results).to.be.an('number').to.equal(Count); - done(); - }). - catch(function (err) { - done(err); - }); + then(function (results) { + expect(results).to.be.an('number').to.equal(Count); + done(); + }). + catch(function (err) { + done(err); + }); }); diff --git a/test/cases/update/update_with_operator.js b/test/cases/update/update_with_operator.js index 14a8bfc..20534f7 100644 --- a/test/cases/update/update_with_operator.js +++ b/test/cases/update/update_with_operator.js @@ -8,13 +8,14 @@ describe('Test update with operator option', function () { ProductID: 1 } }). - then(function (results) { - Price = results[0].Price; - }).catch(function (err) { - done(err); - }); + then(function (results) { + Price = results[0].Price; + }).catch(function (err) { + done(err); + }); - con.update({ in: "Products", + con.update({ + in: "Products", set: { Price: { '+': 5 @@ -55,7 +56,8 @@ describe('Test update with operator option', function () { done(err); }); - con.update({ in: "Products", + con.update({ + in: "Products", set: { Price: { '-': 5 @@ -95,7 +97,8 @@ describe('Test update with operator option', function () { }).catch(function (err) { done(err); }); - con.update({ in: "Products", + con.update({ + in: "Products", set: { Price: { '*': 5 @@ -135,7 +138,8 @@ describe('Test update with operator option', function () { }).catch(function (err) { done(err); }); - con.update({ in: "Products", + con.update({ + in: "Products", set: { Price: { '/': 5 @@ -175,7 +179,8 @@ describe('Test update with operator option', function () { }).catch(function (err) { done(err); }); - con.update({ in: "Products", + con.update({ + in: "Products", set: { ProductName: { '+': 'temp' @@ -204,7 +209,8 @@ describe('Test update with operator option', function () { }); it('update with wrong operator - #', function (done) { - con.update({ in: "Products", + con.update({ + in: "Products", set: { ProductName: { '#': 'temp' @@ -213,8 +219,6 @@ describe('Test update with operator option', function () { where: { ProductID: 1 } - }).then(function (results) { - expect(results).to.be.an('number').to.equal(1); }).catch(function (err) { var error = { "message": "Supplied value for column 'ProductName' have wrong data type",