Skip to content

Commit

Permalink
test: nullable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwoon committed Apr 25, 2024
1 parent 660515e commit 015ee37
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/node/src/safe-empty-where-in.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ for (const dialect of DIALECTS) {
interface Person {
id: Generated<number>
firstName: string
nullableColumn: null | string
}

interface Database {
Expand All @@ -42,24 +43,74 @@ for (const dialect of DIALECTS) {
await db.schema.dropTable('safeEmptyArrayPerson').ifExists().execute()
await createTableWithId(db.schema, dialect, 'safeEmptyArrayPerson')
.addColumn('firstName', 'varchar(255)')
.addColumn('nullableColumn', 'varchar(255)')
.execute()

await db
.insertInto('safeEmptyArrayPerson')
.values([
{
firstName: 'John',
nullableColumn: '1',
},
{
firstName: 'Mary',
nullableColumn: null,
},
{
firstName: 'Tom',
nullableColumn: null,
},
])
.execute()
})

it('nullable columns should still return empty as it is a no-op', async () => {
const query = db
.selectFrom('safeEmptyArrayPerson')
.where('nullableColumn', 'in', [])
.select('safeEmptyArrayPerson.nullableColumn')

testSql(query, dialect, {
postgres: {
sql: [
`select "safeEmptyArrayPerson"."nullableColumn"`,
`from "safeEmptyArrayPerson"`,
`where "nullableColumn" in ($1)`,
],
parameters: [null],
},
mysql: {
sql: [
'select `safeEmptyArrayPerson`.`nullableColumn`',
'from `safeEmptyArrayPerson`',
'where `nullableColumn` in (?)',
],
parameters: [null],
},
mssql: {
sql: [
`select "safeEmptyArrayPerson"."nullableColumn"`,
`from "safeEmptyArrayPerson"`,
`where "nullableColumn" in (@1)`,
],
parameters: [null],
},
sqlite: {
sql: [
`select "safeEmptyArrayPerson"."nullableColumn"`,
`from "safeEmptyArrayPerson"`,
`where "nullableColumn" in (?)`,
],
parameters: [null],
},
})

const result = await query.execute()

expect(result).to.deep.equal([])
})

it('should handle empty array select from statements without throwing runtime errors', async () => {
const query = db
.selectFrom('safeEmptyArrayPerson')
Expand Down

0 comments on commit 015ee37

Please sign in to comment.