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

feat: add safe empty where in plugin #925

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

austinwoon
Copy link

Addresses concerns #709 with a plugin.

Copy link

vercel bot commented Mar 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2024 4:13pm

@igalklebanov igalklebanov added enhancement New feature or request built-in plugin Related to a built-in plugin labels Mar 30, 2024
...binaryOperatorNode,
rightOperand: {
...rightOperand,
values: [null],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about situations where the value in db is null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in (null) should always return nothing, its the equivalent of 1=0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK let's make sure this is correct across all 4 dialects:

  1. have a record in data that has a null in that column.
  2. run query against db and expect results are empty.

But do it once. No need to communicate with DB for all test cases.. just not cost effective.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, could just alter the tree to 1=0 or equivalent and call it a day.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

015ee37 added tests here. Let me know if it is sufficient

Comment on lines 42 to 60
await db.schema.dropTable('safeEmptyArrayPerson').ifExists().execute()
await createTableWithId(db.schema, dialect, 'safeEmptyArrayPerson')
.addColumn('firstName', 'varchar(255)')
.execute()

await db
.insertInto('safeEmptyArrayPerson')
.values([
{
firstName: 'John',
},
{
firstName: 'Mary',
},
{
firstName: 'Tom',
},
])
.execute()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a special table for this suite?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the convention in this project? im doing this just so to avoid collisions with other tests suites if things are run in parallel

Comment on lines 105 to 107
let result = await query.execute()

expect(result).to.deep.equal([])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to execute really, testing the compiled sql is more than enough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should execute to make sure there are no run-time errors, which was the case before.

Comment on lines 195 to 201
let result = await query.execute()

expect(result).to.have.length(2)
expect(result).to.deep.equal([
{ firstName: 'John' },
{ firstName: 'Mary' },
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to execute really, testing the compiled sql is more than enough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we opt to keep to test for runtime errors?

Comment on lines 287 to 289
let result = await query.execute()

expect(result).to.deep.equal([new DeleteResult(BigInt(0))])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to execute really, testing the compiled sql is more than enough.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, can i leave it here since its already there? Would be good for us to know side-effects if any for results as well.

@austinwoon
Copy link
Author

@igalklebanov ive addressed all of the PR comments, could i check if this is ready to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
built-in plugin Related to a built-in plugin enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants