Skip to content

Commit

Permalink
fix no separator between default insert values. (#202)
Browse files Browse the repository at this point in the history
* fix no separator between default insert values.

* remove .only from test case.

* fix introspect tests following person schema change.
  • Loading branch information
igalklebanov authored Oct 22, 2022
1 parent 24779b3 commit 3f91374
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/query-compiler/default-query-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ export class DefaultQueryCompiler
nodes: ReadonlyArray<OperationNode>,
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)
}
}
Expand Down
10 changes: 6 additions & 4 deletions test/node/src/insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,25 +497,27 @@ for (const dialect of BUILT_IN_DIALECTS) {
{
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',
},
])
.returningAll()

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'],
},
})

Expand Down
21 changes: 21 additions & 0 deletions test/node/src/introspect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
{
Expand Down Expand Up @@ -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,
},
],
},
{
Expand Down Expand Up @@ -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,
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions test/node/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3f91374

Please sign in to comment.