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

Is there a dynamic_do_update available? #493

Open
qbgbmpty opened this issue Jun 16, 2023 · 3 comments
Open

Is there a dynamic_do_update available? #493

qbgbmpty opened this issue Jun 16, 2023 · 3 comments

Comments

@qbgbmpty
Copy link

Is it possible to use a dynamic approach for the do_update called when encountering a conflict? Similar to dynamic_from, dynamic_where, and so on.

Alternatively, is there any way to pass fields from the database to a function using parameters? If I have a function like:

void gen_statement(DB_field...){
......
}

Since each field in each table in the header file generated by ddl2cpp will have a different data type, I'm not sure how to pass multiple fields into my custom function if I need to add them to my statement using parameters.

@rbock
Copy link
Owner

rbock commented Jun 17, 2023

I am not sure I understand the first part of the question. Would you like to use a dynamic form of on_conflict(x).do_update(y)? That's currently not implemented, but could be done.

As for the second part: Passing fields to a function is easiest if you make the function a template. Alternatively, you could make use of decltype to declare the parameter types.

@qbgbmpty
Copy link
Author

Yes, for the first part, I mean like:
auto x = insert_into(DB_foo).set(DB_foo.Id = parameter(DB_foo.Id)).dynamic_on_conflict().dynamic_do_update();
x.on_conflict.add(add_conflict);
x.do_update.add(add_update);

or maybe like boolean_expression:
auto x = boolean_expression(db, DB_foo.Id = "123");
insert_into(DB_foo).set(DB_foo.Id = parameter(DB_foo.Id)).on_conflict(DB_foo.Id).dynamic_do_update(x);

Regarding the second part, I think I may understand what you mean. I will try to implement it according to your suggestion and see how it works. Thank you very much.

@rbock
Copy link
Owner

rbock commented Jun 19, 2023

Thanks for confirming the first part. It would be possible to implement that in sqlpp11, but definitely take a while.

Fingers crossed that the first part works for you.

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