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

Insert select statements #16

Merged
merged 2 commits into from
Jul 1, 2013
Merged

Conversation

samanklesaria
Copy link

Hi Felipe,
I really like esqueleto, but I was disappointed that it didn't support insert statements. True, you can insert individual records through Persistant, but this doesn't allow you to do things like INSERT INTO table_a SELECT (val_x, val_y) FROM table_b.

I added this functionality to Esqueleto, trying to keep my changes as self contained as possible. The only caveat is that toRawSql now requires an additional argument, which may break some users' code. Also Feel free to change the operator names I defined to create insertions (currently <# and <&>).

I hope this functionality can make it into the next version.

Thanks!
Sam

@meteficha
Copy link
Member

Great! esqueleto lacks basic INSERT support on purpose because it would duplicate persistent's own insert. However, it lacks the more general INSERT support because no one has written code for it before. So, thanks for the pull request!

I've written some comments on your commit that I'd like you to address. Besides that, I'd like you to add some user-facing docs about how one would use the new insertSelect.

Cheers!

@samanklesaria
Copy link
Author

I've followed your advice, and changed the class into a datatype. Also, I added an example in the "getting started" section of the documentation.

meteficha added a commit that referenced this pull request Jul 1, 2013
Insert select statements
@meteficha meteficha merged commit 4b776dd into prowdsponsor:master Jul 1, 2013
@meteficha
Copy link
Member

Amazing, thanks a lot! Released as esqueleto-1.2.3.

@jcristovao
Copy link
Contributor

Hi,
I was running the esqueleto testsuite in Postgres, which required some adaptations, but the test related to this feature still fails.I noticed that insertSelect does not properly escape the table and column names, but I cannot quickly find where/how this should be done.

To exemplify, the previous test (EXISTS works for subList_select) generates the SQL query:

SELECT \"Person\".\"id\", \"Person\".\"name\", \"Person\".\"age\" FROM \"Person\"\n WHERE NOT EXISTS (SELECT ? FROM \"BlogPost\" WHERE \"BlogPost\".\"authorId\" = \"Person\".\"id\")

While the (IN works for insertSelect) test generates:

INSERT INTO BlogPost(title, authorId)
SELECT ?, \"Person\".\"id\"
FROM \"Person\"

Thanks

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.

3 participants