Skip to content

Commit 8a65184

Browse files
Highlighted sql strings
1 parent 6e50a35 commit 8a65184

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/runner.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ function runTransactional(db, m, statements) {
146146
* @returns {void}
147147
*/
148148
function checkVersion(db, m, applyChanges) {
149-
const query = db.prepare(`select version from ${dbTable} where version = ?;`);
149+
const query = db.prepare(
150+
/* sql */ `select version from ${dbTable} where version = ?;`
151+
);
150152
const rows = query.all(m.version);
151153
if (rows.length === 0) {
152154
applyChanges();
153155

154156
const insert = db.prepare(
155-
`insert into ${dbTable} (version, name) values (?, ?);`
157+
/* sql */ `insert into ${dbTable} (version, name) values (?, ?);`
156158
);
157159
insert.run(m.version, m.name);
158160
}
@@ -165,13 +167,13 @@ function checkVersion(db, m, applyChanges) {
165167
function readCurrentVersions(db) {
166168
return db.transaction(() => {
167169
db.prepare(
168-
`create table if not exists ${dbTable} (
170+
/* sql */ `create table if not exists ${dbTable} (
169171
version integer primary key,
170172
name text not null
171173
);`
172174
).run();
173175

174-
const query = db.prepare(`select version from ${dbTable};`);
176+
const query = db.prepare(/* sql */ `select version from ${dbTable};`);
175177
const rows = query.all();
176178
return new Set(rows.map((r) => /** @type {number} */ (r.version)));
177179
})();

test/runner.test.mjs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const sqliteError = (() => {
2424

2525
const migration1 = {
2626
file: "V001__test_migration_1.SQL",
27-
content: `
27+
content: /* sql */ `
2828
-- comment 1
2929
-- comment 2
3030
create table test_migrations (
@@ -45,8 +45,7 @@ const migration1 = {
4545

4646
const migration2 = {
4747
file: "V002__test_migration_2.sql",
48-
content:
49-
"insert into test_migrations (new_name) values ('test 3'), ('test 4');",
48+
content: /* sql */ `insert into test_migrations (new_name) values ('test 3'), ('test 4');`,
5049
};
5150

5251
describe("runner.test.mjs", () => {
@@ -178,11 +177,11 @@ describe("runner.test.mjs", () => {
178177
migration1,
179178
{
180179
...migration2,
181-
content: `${migration2.content}; insert into test_migrations (new_name) values ('test 5'), ();`,
180+
content: /* sql */ `${migration2.content}; insert into test_migrations (new_name) values ('test 5'), ();`,
182181
},
183182
{
184183
file: "V003__test_migration_3.sql",
185-
content: "insert into test_migrations (new_name) values ('test 7');",
184+
content: /* sql */ `insert into test_migrations (new_name) values ('test 7');`,
186185
},
187186
]);
188187
} catch (error) {
@@ -221,7 +220,7 @@ describe("runner.test.mjs", () => {
221220
migration1,
222221
{
223222
...migration2,
224-
content: `${migration2.content}; insert into test_migrations (new_name) values ('test 5'), ();`,
223+
content: /* sql */ `${migration2.content}; insert into test_migrations (new_name) values ('test 5'), ();`,
225224
},
226225
]);
227226
} catch (error) {
@@ -234,7 +233,7 @@ describe("runner.test.mjs", () => {
234233
migration1,
235234
{
236235
...migration2,
237-
content: `${migration2.content}; insert into test_migrations (new_name) values ('test 5');`,
236+
content: /* sql */ `${migration2.content}; insert into test_migrations (new_name) values ('test 5');`,
238237
},
239238
]);
240239

@@ -275,7 +274,7 @@ describe("runner.test.mjs", () => {
275274
await runBundle(db, [
276275
{
277276
file: "V001__non-transactional_migration.sql",
278-
content: `
277+
content: /* sql */ `
279278
-- non-transactional
280279
PRAGMA foreign_keys = ON;
281280
`,
@@ -308,7 +307,7 @@ describe("runner.test.mjs", () => {
308307
await runBundle(db, [
309308
{
310309
file: "V001__non-transactional_migration.sql",
311-
content: `
310+
content: /* sql */ `
312311
-- non-transactional
313312
PRAGMA foreign_keys = ON;
314313
@@ -327,7 +326,7 @@ describe("runner.test.mjs", () => {
327326
},
328327
{
329328
file: "V002__transactional_migration.sql",
330-
content: `
329+
content: /* sql */ `
331330
insert into categories (name) values ('category 1'), ('category 2');
332331
insert into products (cat_id, name) values (3, 'product 1')
333332
`,
@@ -430,7 +429,9 @@ describe("runner.test.mjs", () => {
430429
*/
431430
function assertDb(db, expected) {
432431
const results = db.transaction(() => {
433-
const query = db.prepare(`select * from test_migrations order by id;`);
432+
const query = db.prepare(
433+
/* sql */ `select * from test_migrations order by id;`
434+
);
434435
const rows = query.all();
435436
return rows.map((r) => {
436437
return {
@@ -449,7 +450,9 @@ function assertDb(db, expected) {
449450
*/
450451
function assertSchema(db, expected) {
451452
const results = db.transaction(() => {
452-
const query = db.prepare(`select * from schema_versions order by version;`);
453+
const query = db.prepare(
454+
/* sql */ `select * from schema_versions order by version;`
455+
);
453456
const rows = query.all();
454457
return rows.map((r) => {
455458
return {

0 commit comments

Comments
 (0)