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

Conversation

felixmosh
Copy link
Contributor

Added missing type

@@ -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.

@kibertoad kibertoad merged commit 1948c3d into knex:master Mar 30, 2019
@kibertoad kibertoad changed the title Add boolean as a column name in join Add boolean as a column value type in join Mar 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants