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

Add boolean as a column value type in join #3121

Merged
merged 1 commit into from Mar 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/knex.d.ts
Expand Up @@ -239,7 +239,7 @@ declare namespace Knex {
(tableName: TableName | Identifier | QueryCallback, clause: JoinCallback): QueryBuilder;
(
tableName: TableName | Identifier | QueryCallback,
columns: { [key: string]: string | number | Raw }
columns: { [key: string]: string | number | boolean | Raw }
Copy link
Collaborator

Choose a reason for hiding this comment

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

When would it be a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?
The value of join can be boolean :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please provide example code that was invalid before this change?
The way I'm reading this binding is this:

knex('users')
  .join('contacts', 'users.id', '=', 'contacts.user_id')
  .select('users.id', 'contacts.phone')

columns are these: 'users.id', '=', 'contacts.user_id'
Why would they ever be boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pay attention to the interface that I've fixed, it is the one that accepts an object.

db('tableName')
    .leftJoin('otherTable', {
      'tableName.isDefault': true
    })

image

It tries to resolve it using the Raw interface because there is no boolean.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough. And if typing is fixed, DB understands boolean value correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it works, it converts it into tinyInt automatically

Copy link
Member

Choose a reason for hiding this comment

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

Actually that depends highly on db that is used, but something like that :) I had big problems trying to write cross db compatible code that had used boolean column type.

): QueryBuilder;
(tableName: TableName | Identifier | QueryCallback, raw: Raw): QueryBuilder;
(
Expand Down