Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support MySql INTERVAL #3074

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

Merged
merged 2 commits into from
Apr 13, 2022
Merged

Conversation

eygraber
Copy link
Contributor

Closes #2969

@@ -63,6 +63,7 @@ internal class MySqlTypeResolver(
"unix_timestamp" -> IntermediateType(TEXT)
"to_seconds" -> IntermediateType(INTEGER)
"json_arrayagg" -> IntermediateType(TEXT)
"date_add", "date_sub" -> encapsulatingType(exprList, TEXT, MySqlType.TIME, MySqlType.DATE, MySqlType.DATETIME, MySqlType.TIMESTAMP)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not fully sure about how this works, i.e. should it just return IntermediateType(TEXT)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you give it a list of types where if you have two types in the expression list it will pick the type closer to the front of the list. So I think this is good. I mean if tests pass you probably did it right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the integration test is failing but I can't see what the failure is, and I can't run it locally (something about docker not being detected)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yea you need docker to run the integration tests, it's pretty easy to set up if you're keane to try it locally.

You can see test reports on CI by downloading the build report at the bottom here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have docker installed but I didn't want to go down the rabbit hole debugging why it wasn't working 😅

In any case I think I misunderstood how the functions work. It looks like the rules for what gets returned might be a little too complicated for SQLDelight to infer.

The options I can think of are:

  1. Return TEXT
  2. If it's possible to rewrite the arguments, always casting it to a DATETIME will ensure that a DATETIME is always returned

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think just returning text for now is fine

Copy link
Collaborator

@AlecKazakova AlecKazakova left a comment

Choose a reason for hiding this comment

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

really nice

@@ -71,4 +79,26 @@ class MySqlTest {
)
)
}

@Test
fun testDates() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

awesome

@@ -63,6 +63,7 @@ internal class MySqlTypeResolver(
"unix_timestamp" -> IntermediateType(TEXT)
"to_seconds" -> IntermediateType(INTEGER)
"json_arrayagg" -> IntermediateType(TEXT)
"date_add", "date_sub" -> encapsulatingType(exprList, TEXT, MySqlType.TIME, MySqlType.DATE, MySqlType.DATETIME, MySqlType.TIMESTAMP)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you give it a list of types where if you have two types in the expression list it will pick the type closer to the front of the list. So I think this is good. I mean if tests pass you probably did it right

@eygraber eygraber force-pushed the mysql-interval branch 4 times, most recently from 965ed72 to 7f0b846 Compare April 13, 2022 03:58
@AlecKazakova AlecKazakova merged commit f3ffbef into sqldelight:master Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support MySQL INTERVAL function type
2 participants