Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix no separator between default insert values. #202

Merged
merged 3 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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