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

Returning Record #1489

Merged
merged 4 commits into from Jul 5, 2019
Merged

Conversation

deusaquilus
Copy link
Collaborator

@deusaquilus deusaquilus commented Jun 21, 2019

Trying out build similar to #1383 (fix for #572).

  • Unit test all changes
  • Update README.md if applicable
  • Add [WIP] to the pull request title if it's work in progress
  • Squash commits that aren't meaningful changes
  • Run sbt scalariformFormat test:scalariformFormat to make sure that the source files are formatted

@getquill/maintainers

@deusaquilus deusaquilus force-pushed the returning_record_redo branch 11 times, most recently from 838eb41 to 7219984 Compare July 4, 2019 06:56
@deusaquilus deusaquilus changed the title [WIP] Returning Record Redo #2 Returning Record Redo #2 Jul 4, 2019
@deusaquilus deusaquilus changed the title Returning Record Redo #2 Returning Record RC Jul 4, 2019
Copy link
Collaborator

@mosyp mosyp left a comment

Choose a reason for hiding this comment

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

At the middle of PR I've lost on various changes, it really makes sense to me to split this PR (more in a comment below).
Also I've notice that in a lot of places returning itself is changed to returningGenerated, but the first one is not deleted from codebase, so it means that both will be in use? A short summary of a returning design in PR as well as in readme would be nice

@@ -175,6 +181,9 @@ trait CqlIdiom extends Idiom {
case _: Returning =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: _: ReturningGenerated | _: Returning

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call!

@@ -69,6 +69,10 @@ case class Function(params: List[Ident], body: Ast) extends Ast

case class Ident(name: String) extends Ast

// Like identity but is but defined in a clause external to the query. Currently this is used
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm suffering from "The Curse of Knowledge" here. What part do you mean?

@@ -0,0 +1,139 @@
package io.getquill.dsl
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd make a separate commit for such refactor before introducing returning record feature. So it'd be easy to track

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This makes sense. I'll try to separate it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. There are 4 commits now.

case ret: io.getquill.ast.ReturningAction =>
io.getquill.norm.ExpandReturning.applyMap(ret)(
(ast, statement) => io.getquill.context.Expand(${c.prefix}, ast, statement, idiom, naming).string
)(idiom, naming)
case ast =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing case io.getquill.ast.Returning ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So ReturningAction is a de-composer that matches Returning or ReturningGenerated, I defined it in Ast.scala. I decide to write it since their structure is identical. I'm not sure I like the name "ReturningAction" though. Maybe "ReturningAst"? Or maybe it shouldn't start with a capital letter. Any thoughts?

@deusaquilus
Copy link
Collaborator Author

Im sorry that I forgot to mention something important. The insert(entity).returning(_.id) API used to not only add id SQL RETURNING clause but also removed It from the Insert clause as well. After a few conversations with Flavio and others, we concluded that if we want to support returning tuples etc.. in the returning clause eg .returning(r => (r.foo, r.bar)) it is very unclear that the behavior of returning is to exclude foo and bar from the initial insertion. Also, we wanted to have an API that does not exclude records at all. Therefore, we decided to make .returning do exactly that and .returningGenerated return generated columns I.e. columns that are auto-generated therefore should be excluded from the Insert.

@deusaquilus deusaquilus force-pushed the returning_record_redo branch 2 times, most recently from 7d31c72 to f58be32 Compare July 5, 2019 06:50
@deusaquilus deusaquilus force-pushed the returning_record_redo branch 2 times, most recently from da165c8 to 341016f Compare July 5, 2019 07:44
@deusaquilus
Copy link
Collaborator Author

The other thing that we realized was that whether a single column (MySQL, Sqlite etc...), multiple columns (Oracle) or multiple columns with an actual RETURNING clause that supports sql operations (Postgres) is supported has to be controlled by the idiom as opposed to the context. MirrorContext for instance has to generate RETURNING clauses for only Postgres but... allow multiple column tuples/case-classes for Oracle and allow only one return variable for other databases the same way in MirrorContext as well as JdbcContext. So the dialect has to control these things. Also,
we need to know all of this during compile time during. For the reason we introduced the RuturnCapability types. These live in the dialects but can be inspected from anything that has access to the context including the Parser, the Metas etc...

@mosyp
Copy link
Collaborator

mosyp commented Jul 5, 2019

@deusaquilus Okay, now it's clear, great work! Except missing readme update, everything else lgtm.

@deusaquilus deusaquilus merged commit ca23d3c into zio:master Jul 5, 2019
@deusaquilus deusaquilus changed the title Returning Record RC Returning Record Jul 14, 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

2 participants