Skip to content

Commit

Permalink
fix(inserts): resolve issues with undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Jan 5, 2025
1 parent 67e413e commit 15bcf77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/parser/insert-values-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function parseColumnNamesAndIndexes(
const cols = Object.keys(row)

for (const col of cols) {
if (!columns.has(col) && row[col] !== undefined) {
if (!columns.has(col)) {
columns.set(col, columns.size)
}
}
Expand Down
18 changes: 9 additions & 9 deletions test/node/src/insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ for (const dialect of DIALECTS) {
{
first_name: 'Foo',
last_name: 'Spam',
middle_name: 'Bo',
middle_name: undefined,
gender: 'other',
},
{
Expand All @@ -742,20 +742,20 @@ for (const dialect of DIALECTS) {

testSql(query, dialect, {
postgres: {
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values ($1, $2, $3, $4), ($5, default, default, $6)',
parameters: ['Foo', 'Spam', 'Bo', 'other', 'Baz', 'other'],
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values ($1, $2, default, $3), ($4, default, default, $5)',
parameters: ['Foo', 'Spam', 'other', 'Baz', 'other'],
},
mysql: {
sql: 'insert into `person` (`first_name`, `last_name`, `middle_name`, `gender`) values (?, ?, ?, ?), (?, default, default, ?)',
parameters: ['Foo', 'Spam', 'Bo', 'other', 'Baz', 'other'],
sql: 'insert into `person` (`first_name`, `last_name`, `middle_name`, `gender`) values (?, ?, default, ?), (?, default, default, ?)',
parameters: ['Foo', 'Spam', 'other', 'Baz', 'other'],
},
mssql: {
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values (@1, @2, @3, @4), (@5, default, default, @6)',
parameters: ['Foo', 'Spam', 'Bo', 'other', 'Baz', 'other'],
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values (@1, @2, default, @3), (@4, default, default, @5)',
parameters: ['Foo', 'Spam', 'other', 'Baz', 'other'],
},
sqlite: {
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values (?, ?, ?, ?), (?, null, null, ?)',
parameters: ['Foo', 'Spam', 'Bo', 'other', 'Baz', 'other'],
sql: 'insert into "person" ("first_name", "last_name", "middle_name", "gender") values (?, ?, null, ?), (?, null, null, ?)',
parameters: ['Foo', 'Spam', 'other', 'Baz', 'other'],
},
})

Expand Down

0 comments on commit 15bcf77

Please sign in to comment.