You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constsql="attach database 'c:\sqlite\db\contacts.db' as contacts;"
20
-
expect(getParsedSql(sql)).to.be.equal("ATTACH DATABASE 'c:\sqlite\db\contacts.db' AS `contacts`")
20
+
expect(getParsedSql(sql)).to.be.equal(`ATTACH DATABASE 'c:sqlitedbcontacts.db' AS "contacts"`)
21
21
})
22
22
23
23
it('should support json function in from clause',()=>{
@@ -27,7 +27,7 @@ describe('sqlite', () => {
27
27
json_each(post.author, '$')
28
28
GROUP BY
29
29
author_id;`
30
-
expect(getParsedSql(sql)).to.be.equal("SELECT json_extract(`value`, '$.id') AS `author_id` FROM `post`, json_each(`post`.`author`, '$') GROUP BY `author_id`")
30
+
expect(getParsedSql(sql)).to.be.equal(`SELECT json_extract("value", '$.id') AS "author_id" FROM "post", json_each("post"."author", '$') GROUP BY "author_id"`)
31
31
})
32
32
33
33
it('should support || in where clause',()=>{
@@ -39,7 +39,7 @@ describe('sqlite', () => {
39
39
WHERE user.name = "pepe" || "rone"
40
40
) u ON pets.owner = u.id
41
41
GROUP BY pets.id;`
42
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `pets` LEFT JOIN (SELECT * FROM `user` WHERE `user`.`name` = "pepe" || "rone") AS `u` ON `pets`.`owner` = `u`.`id` GROUP BY `pets`.`id`')
42
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "pets" LEFT JOIN (SELECT * FROM "user" WHERE "user"."name" = "pepe" || "rone") AS "u" ON "pets"."owner" = "u"."id" GROUP BY "pets"."id"')
43
43
})
44
44
45
45
it('should support or combine with )',()=>{
@@ -51,7 +51,7 @@ describe('sqlite', () => {
51
51
WHERE user.code = UPPER("test")
52
52
OR user.name = "pepe") u ON pets.owner = u.id
53
53
GROUP BY pets.id;`
54
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `pets` LEFT JOIN (SELECT * FROM `user` WHERE `user`.`code` = UPPER("test") OR `user`.`name` = "pepe") AS `u` ON `pets`.`owner` = `u`.`id` GROUP BY `pets`.`id`')
54
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "pets" LEFT JOIN (SELECT * FROM "user" WHERE "user"."code" = UPPER("test") OR "user"."name" = "pepe") AS "u" ON "pets"."owner" = "u"."id" GROUP BY "pets"."id"')
55
55
sql=`SELECT *
56
56
FROM
57
57
pets
@@ -62,7 +62,7 @@ describe('sqlite', () => {
62
62
OR user.code = UPPER("more_test")
63
63
) u ON pets.owner = u.id
64
64
GROUP BY pets.id;`
65
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `pets` LEFT JOIN (SELECT * FROM `user` WHERE `user`.`name` = "pepe" || "rone" OR `user`.`code` = UPPER("test") OR `user`.`code` = UPPER("more_test")) AS `u` ON `pets`.`owner` = `u`.`id` GROUP BY `pets`.`id`')
65
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "pets" LEFT JOIN (SELECT * FROM "user" WHERE "user"."name" = "pepe" || "rone" OR "user"."code" = UPPER("test") OR "user"."code" = UPPER("more_test")) AS "u" ON "pets"."owner" = "u"."id" GROUP BY "pets"."id"')
66
66
})
67
67
68
68
it('should support json as function name',()=>{
@@ -79,34 +79,34 @@ describe('sqlite', () => {
79
79
floor
80
80
WHERE
81
81
floor.id = 1;`
82
-
expect(getParsedSql(sql)).to.be.equal("SELECT `id`, json_object('hasGeometry', CASE WHEN json_extract(`floor`.`rect`, '$') IS '{\"boundariesList\":[]}' THEN json('false') ELSE json('true') END) AS `metadata` FROM `floor` WHERE `floor`.`id` = 1")
82
+
expect(getParsedSql(sql)).to.be.equal(`SELECT "id", json_object('hasGeometry', CASE WHEN json_extract("floor"."rect", '$') IS '{"boundariesList":[]}' THEN json('false') ELSE json('true') END) AS "metadata" FROM "floor" WHERE "floor"."id" = 1`)
83
83
})
84
84
85
85
it('should support glob operator',()=>{
86
86
constsql="SELECT device.id FROM device WHERE device.model GLOB '*XYZ';"
87
-
expect(getParsedSql(sql)).to.be.equal("SELECT `device`.`id` FROM `device` WHERE `device`.`model` GLOB '*XYZ'")
87
+
expect(getParsedSql(sql)).to.be.equal(`SELECT "device"."id" FROM "device" WHERE "device"."model" GLOB '*XYZ'`)
88
88
})
89
89
90
90
it('should support create table...as',()=>{
91
91
constsql=`CREATE TABLE IF NOT EXISTS stg_devices AS SELECT * FROM devices WHERE 1 = 0;`
92
-
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS `stg_devices` AS SELECT * FROM `devices` WHERE 1 = 0')
92
+
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS "stg_devices" AS SELECT * FROM "devices" WHERE 1 = 0')
93
93
})
94
94
95
95
it('should support escape single quote',()=>{
96
96
constsql="SELECT name, 'doesn''t smoke' FROM people WHERE name = 'John';"
97
-
expect(getParsedSql(sql)).to.be.equal("SELECT `name`, 'doesn''t smoke' FROM `people` WHERE `name` = 'John'")
97
+
expect(getParsedSql(sql)).to.be.equal(`SELECT "name", 'doesn''t smoke' FROM "people" WHERE "name" = 'John'`)
98
98
})
99
99
100
100
it('should support create with autoincrement, boolean type and definition could be empty',()=>{
constsql='with `e` as (select * from employees) SELECT name,`e`.`hired_on` FROM `e`'
109
-
expect(getParsedSql(sql)).to.be.equal('WITH `e` AS (SELECT * FROM `employees`) SELECT `name`, `e`.`hired_on` FROM `e`')
109
+
expect(getParsedSql(sql)).to.be.equal('WITH "e" AS (SELECT * FROM "employees") SELECT "name", "e"."hired_on" FROM "e"')
110
110
})
111
111
112
112
it('should support blob type',()=>{
@@ -116,36 +116,36 @@ describe('sqlite', () => {
116
116
"expires_at" INTEGER,
117
117
PRIMARY KEY("service_name","expires_at")
118
118
)`
119
-
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE `session_caches` (`service_name` TEXT NOT NULL, `session_data` BLOB NOT NULL, `expires_at` INTEGER, PRIMARY KEY (`service_name`, `expires_at`))')
119
+
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE "session_caches" ("service_name" TEXT NOT NULL, "session_data" BLOB NOT NULL, "expires_at" INTEGER, PRIMARY KEY ("service_name", "expires_at"))')
120
120
})
121
121
it('should support missing number after dot in number',()=>{
122
122
constsql='select count(*)*1. from abc'
123
-
expect(getParsedSql(sql)).to.be.equal('SELECT COUNT(*) * 1 FROM `abc`')
123
+
expect(getParsedSql(sql)).to.be.equal('SELECT COUNT(*) * 1 FROM "abc"')
124
124
})
125
125
it('should support create trigger',()=>{
126
126
letsql=`CREATE TRIGGER update_customer_address UPDATE OF address ON customers
127
127
BEGIN
128
128
UPDATE orders SET address = new.address WHERE customer_name = old.name;
129
129
END;`
130
-
expect(getParsedSql(sql)).to.be.equal('CREATE TRIGGER `update_customer_address` UPDATE OF `address` ON `customers` BEGIN UPDATE `orders` SET `address` = `new`.`address` WHERE `customer_name` = `old`.`name` END')
130
+
expect(getParsedSql(sql)).to.be.equal('CREATE TRIGGER "update_customer_address" UPDATE OF "address" ON "customers" BEGIN UPDATE "orders" SET "address" = "new"."address" WHERE "customer_name" = "old"."name" END')
131
131
})
132
132
133
133
it('should support union',()=>{
134
134
letsql=`SELECT * FROM a UNION SELECT * FROM b`
135
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `a` UNION SELECT * FROM `b`')
135
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "a" UNION SELECT * FROM "b"')
136
136
137
137
sql=`SELECT * FROM a UNION ALL SELECT * FROM b`
138
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `a` UNION ALL SELECT * FROM `b`')
138
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "a" UNION ALL SELECT * FROM "b"')
139
139
140
140
sql=`SELECT * FROM a UNION DISTINCT SELECT * FROM b`
141
-
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM `a` UNION DISTINCT SELECT * FROM `b`')
141
+
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "a" UNION DISTINCT SELECT * FROM "b"')
142
142
})
143
143
144
144
it('should support keyword as column name in create table sql',()=>{
145
145
letsql='CREATE TABLE IF NOT EXISTS "Test" (Id INTEGER NOT NULL PRIMARY KEY UNIQUE, like TEXT NOT NULL, Difficulty TEXT, percent real, PRIMARY KEY(Id));'
146
-
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS `Test` (`Id` INTEGER NOT NULL PRIMARY KEY UNIQUE, `like` TEXT NOT NULL, `Difficulty` TEXT, `percent` REAL, PRIMARY KEY (`Id`))')
146
+
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS "Test" ("Id" INTEGER NOT NULL PRIMARY KEY UNIQUE, "like" TEXT NOT NULL, "Difficulty" TEXT, "percent" REAL, PRIMARY KEY ("Id"))')
147
147
sql="SELECT * from tb WHERE NOT EXISTS (SELECT * FROM tb WHERE field1 = 'c' AND field2 = d)"
148
-
expect(getParsedSql(sql)).to.be.equal("SELECT * FROM `tb` WHERE NOT EXISTS (SELECT * FROM `tb` WHERE `field1` = 'c' AND `field2` = `d`)")
148
+
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "tb" WHERE NOT EXISTS (SELECT * FROM "tb" WHERE "field1" = 'c' AND "field2" = "d")`)
149
149
})
150
150
151
151
it('should support sqlify autoincrement to other db',()=>{
@@ -154,16 +154,16 @@ describe('sqlite', () => {
154
154
expect(parser.sqlify(ast,{database: 'mariadb'})).to.be.equal('CREATE TABLE IF NOT EXISTS `SampleTable` (`ID` INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY UNIQUE, `Name` TEXT NOT NULL)')
sql='ALTER TABLE customers RENAME COLUMN age TO customer_age;'
179
-
expect(getParsedSql(sql)).to.be.equal('ALTER TABLE `customers` RENAME COLUMN `age` TO `customer_age`')
179
+
expect(getParsedSql(sql)).to.be.equal('ALTER TABLE "customers" RENAME COLUMN "age" TO "customer_age"')
180
+
})
181
+
182
+
it('should support double equal',()=>{
183
+
constsql="SELECT * FROM sqlite_master WHERE name == 'test'"
184
+
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "sqlite_master" WHERE "name" == 'test'`)
185
+
})
186
+
187
+
it('should support subquery',()=>{
188
+
constsql=`SELECT SUM("Hours Spent") AS "Total Hours"
189
+
FROM "Work_Records"
190
+
WHERE "Partner ID" =
191
+
(SELECT "Partner ID"
192
+
FROM "Employees"
193
+
WHERE "Firstname" = 'John' AND "Lastname" = 'Smith')
194
+
`
195
+
expect(getParsedSql(sql)).to.be.equal(`SELECT SUM("Hours Spent") AS "Total Hours" FROM "Work_Records" WHERE "Partner ID" = (SELECT "Partner ID" FROM "Employees" WHERE "Firstname" = 'John' AND "Lastname" = 'Smith')`)
0 commit comments