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
Copy file name to clipboardExpand all lines: test/index.js
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,41 @@ describe("Queries", () => {
95
95
expect(deparsed).to.eq(`INSERT INTO people (name, age) VALUES ('John', 28), ('Jane', 22)`)
96
96
});
97
97
98
+
it("sync function should return a same SQL (update)",async()=>{
99
+
consttestQuery="UPDATE people SET age = age + 1 WHERE name = 'John';";
100
+
constparsed=query.parseQuerySync(testQuery);
101
+
constdeparsed=query.deparseSync(parsed);
102
+
expect(deparsed).to.eq("UPDATE people SET age = age + 1 WHERE name = 'John'");
103
+
});
104
+
105
+
it("sync function should return a same SQL (join and where)",async()=>{
106
+
consttestQuery="select a.id, b.name from table_a a join table_b b on a.id = b.a_id where b.status = 'active';";
107
+
constparsed=query.parseQuerySync(testQuery);
108
+
constdeparsed=query.deparseSync(parsed);
109
+
expect(deparsed).to.eq("SELECT a.id, b.name FROM table_a a JOIN table_b b ON a.id = b.a_id WHERE b.status = 'active'");
110
+
});
111
+
112
+
it("sync function should return a same SQL (CTE)",async()=>{
113
+
consttestQuery="with recent as (select * from people where age > 30) select name from recent;";
114
+
constparsed=query.parseQuerySync(testQuery);
115
+
constdeparsed=query.deparseSync(parsed);
116
+
expect(deparsed).to.eq("WITH recent AS (SELECT * FROM people WHERE age > 30) SELECT name FROM recent");
117
+
});
118
+
119
+
it("sync function should return a same SQL (create table)",async()=>{
120
+
consttestQuery=`CREATE TABLE orders (
121
+
id serial PRIMARY KEY,
122
+
user_id integer NOT NULL,
123
+
total numeric(10,2) DEFAULT 0.00,
124
+
ordered_at timestamp with time zone DEFAULT now(),
125
+
description text,
126
+
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
127
+
);`;
128
+
constparsed=query.parseQuerySync(testQuery);
129
+
constdeparsed=query.deparseSync(parsed);
130
+
expect(deparsed).to.eq(`CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) DEFAULT 0.00, ordered_at timestamp with time zone DEFAULT now(), description text, CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE)`);
0 commit comments