From 2a853cfcb45da0a723c3ae981742255770bfda6a Mon Sep 17 00:00:00 2001 From: Igal Klebanov Date: Sat, 22 Oct 2022 12:12:39 +0300 Subject: [PATCH 1/3] fix no separator between default insert values. --- src/query-compiler/default-query-compiler.ts | 8 ++++---- test/node/src/insert.test.ts | 12 +++++++----- test/node/src/test-setup.ts | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/query-compiler/default-query-compiler.ts b/src/query-compiler/default-query-compiler.ts index be9682a9c..0a6480777 100644 --- a/src/query-compiler/default-query-compiler.ts +++ b/src/query-compiler/default-query-compiler.ts @@ -234,12 +234,12 @@ export class DefaultQueryCompiler nodes: ReadonlyArray, separator = ', ' ): void { - const lastNode = getLast(nodes) + const lastIndex = nodes.length - 1 - for (const node of nodes) { - this.visitNode(node) + for (let i = 0; i <= lastIndex; i++) { + this.visitNode(nodes[i]) - if (node !== lastNode) { + if (i < lastIndex) { this.append(separator) } } diff --git a/test/node/src/insert.test.ts b/test/node/src/insert.test.ts index 44d9a5e39..47b2f1a4f 100644 --- a/test/node/src/insert.test.ts +++ b/test/node/src/insert.test.ts @@ -490,18 +490,20 @@ for (const dialect of BUILT_IN_DIALECTS) { } if (dialect === 'postgres' || dialect === 'sqlite') { - it('should insert multiple rows', async () => { + it.only('should insert multiple rows', async () => { const query = ctx.db .insertInto('person') .values([ { first_name: 'Foo', // last_name is missing on purpose + // middle_name is missing on purpose gender: 'other', }, { first_name: 'Baz', last_name: 'Spam', + middle_name: 'Bo', gender: 'other', }, ]) @@ -509,13 +511,13 @@ for (const dialect of BUILT_IN_DIALECTS) { testSql(query, dialect, { postgres: { - sql: 'insert into "person" ("first_name", "gender", "last_name") values ($1, $2, default), ($3, $4, $5) returning *', - parameters: ['Foo', 'other', 'Baz', 'other', 'Spam'], + sql: 'insert into "person" ("first_name", "gender", "last_name", "middle_name") values ($1, $2, default, default), ($3, $4, $5, $6) returning *', + parameters: ['Foo', 'other', 'Baz', 'other', 'Spam', 'Bo'], }, mysql: NOT_SUPPORTED, sqlite: { - sql: 'insert into "person" ("first_name", "gender", "last_name") values (?, ?, null), (?, ?, ?) returning *', - parameters: ['Foo', 'other', 'Baz', 'other', 'Spam'], + sql: 'insert into "person" ("first_name", "gender", "last_name", "middle_name") values (?, ?, null, null), (?, ?, ?, ?) returning *', + parameters: ['Foo', 'other', 'Baz', 'other', 'Spam', 'Bo'], }, }) diff --git a/test/node/src/test-setup.ts b/test/node/src/test-setup.ts index 866a33c5a..6836918a5 100644 --- a/test/node/src/test-setup.ts +++ b/test/node/src/test-setup.ts @@ -245,6 +245,7 @@ async function createDatabase( await createTableWithId(db.schema, dialect, 'person') .addColumn('first_name', 'varchar(255)') + .addColumn('middle_name', 'varchar(255)') .addColumn('last_name', 'varchar(255)') .addColumn('gender', 'varchar(50)', (col) => col.notNull()) .execute() From f50cc843e8bdc34e160f7b67117624b7e55ebc1b Mon Sep 17 00:00:00 2001 From: Igal Klebanov Date: Sat, 22 Oct 2022 12:18:42 +0300 Subject: [PATCH 2/3] remove .only from test case. --- test/node/src/insert.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/node/src/insert.test.ts b/test/node/src/insert.test.ts index 47b2f1a4f..474949a45 100644 --- a/test/node/src/insert.test.ts +++ b/test/node/src/insert.test.ts @@ -490,7 +490,7 @@ for (const dialect of BUILT_IN_DIALECTS) { } if (dialect === 'postgres' || dialect === 'sqlite') { - it.only('should insert multiple rows', async () => { + it('should insert multiple rows', async () => { const query = ctx.db .insertInto('person') .values([ From 342cc958f59648d47a6f822714a514a9b6acbf1d Mon Sep 17 00:00:00 2001 From: Igal Klebanov Date: Sat, 22 Oct 2022 12:34:03 +0300 Subject: [PATCH 3/3] fix introspect tests following person schema change. --- test/node/src/introspect.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/node/src/introspect.test.ts b/test/node/src/introspect.test.ts index 756dbf88c..a071f9f1a 100644 --- a/test/node/src/introspect.test.ts +++ b/test/node/src/introspect.test.ts @@ -74,6 +74,13 @@ for (const dialect of BUILT_IN_DIALECTS) { isAutoIncrementing: false, hasDefaultValue: false, }, + { + name: 'middle_name', + dataType: 'varchar', + isNullable: true, + isAutoIncrementing: false, + hasDefaultValue: false, + }, ], }, { @@ -192,6 +199,13 @@ for (const dialect of BUILT_IN_DIALECTS) { isAutoIncrementing: false, hasDefaultValue: false, }, + { + name: 'middle_name', + dataType: 'varchar', + isNullable: true, + isAutoIncrementing: false, + hasDefaultValue: false, + }, ], }, { @@ -296,6 +310,13 @@ for (const dialect of BUILT_IN_DIALECTS) { isAutoIncrementing: false, hasDefaultValue: false, }, + { + name: 'middle_name', + dataType: 'varchar(255)', + isNullable: true, + isAutoIncrementing: false, + hasDefaultValue: false, + }, ], }, {