Skip to content

Commit

Permalink
fix: value 'is' or 'is not' null not working (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ezesinachi <ezesinachijim@gmail.com>
  • Loading branch information
jimezesinachi authored Oct 23, 2024
1 parent 5ec6ef8 commit eea50c2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,54 @@ describe('PgExecutor', () => {
]);
});

it('single provider is null', async () => {
const q = from('film')
.columns('film_id', 'original_language_id', 'title', 'rating')
.where({ original_language_id: { is: null } })
.take(2);

const result = await executor.execute(q, executeProps);

expect(result).toEqual([
{
film_id: 1,
original_language_id: null,
title: 'ACADEMY DINOSAUR',
rating: 'PG',
},
{
film_id: 2,
original_language_id: null,
title: 'ACE GOLDFINGER',
rating: 'G',
},
]);
});

it('single provider is not null', async () => {
const q = from('customer')
.columns('customer_id', 'email', 'first_name', 'last_name')
.where({ email: { 'is not': null } })
.take(2);

const result = await executor.execute(q, executeProps);

expect(result).toEqual([
{
customer_id: 1,
email: 'MARY.SMITH@sakilacustomer.org',
first_name: 'MARY',
last_name: 'SMITH',
},
{
customer_id: 2,
email: 'PATRICIA.JOHNSON@sakilacustomer.org',
first_name: 'PATRICIA',
last_name: 'JOHNSON',
},
]);
});

const language = from('language')
.columns('language_id', 'name')
.where({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ export class SqlBuilder {
`Expected value ${JSON.stringify(value)} to be a primitive in ${JSON.stringify(op)}`,
);

if (value === null) {
return ['op', opName, quotedColumn, ['const', null]];
}

if (opName === 'in') {
return ['op', '= any', quotedColumn, ['param', value]];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/static/reference/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/docs/static/reference/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eea50c2

Please sign in to comment.