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

New feature?: Bind a bean to an Insert or Update query #19

Closed
jsnoriegam opened this issue Sep 22, 2013 · 5 comments
Closed

New feature?: Bind a bean to an Insert or Update query #19

jsnoriegam opened this issue Sep 22, 2013 · 5 comments

Comments

@jsnoriegam
Copy link
Contributor

I know this is not a ORM and that's what is good about this project, but just as you can map a bean from a select result, i think it would be good to bind a bean to an update or insert query...

Something like .createQuery("UPDATE clients SET date = :date, name = :name, regn = :regn, active = :active WHERE id = :id").bind(client).executeUpdate();

bindig all the attributes of client as paramaters (Asuming client has id, date, name, regn, active attributes).

I know it can be done, but i don't know if this goes against what you are aiming for with this project.

Tell me what you think.

Thanks.

@aaberg
Copy link
Owner

aaberg commented Sep 22, 2013

Hi jsnoriegam,

I have had these thoughts myself. The only reason I haven't implemented it, is because I haven't had the time, and no one (before you) have asked for it.

If you feel like implementing it, you are more than welcome :) Otherwise I will put it in the todo list for one of the next versions.

@jsnoriegam
Copy link
Contributor Author

This is a draft implementation but it works for me:
https://github.com/jsnoriegam/sql2o/blob/master/src/main/java/org/sql2o/Query.java#L206
Right now it works only with lowercase params...

@aaberg
Copy link
Owner

aaberg commented Sep 23, 2013

Nice :)
Could you write a unittest? Then I will merge it into the official repo.

@jsnoriegam
Copy link
Contributor Author

Unit test ready, and a few corrections to the new bind method.

@aaberg
Copy link
Owner

aaberg commented Sep 23, 2013

Merged into master.

Thanks a lot :)

@aaberg aaberg closed this as completed Sep 23, 2013
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

No branches or pull requests

2 participants