-
Notifications
You must be signed in to change notification settings - Fork 12
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
How to use placeholders in where clauses? #10
Comments
ping @s-panferov |
@gsingh93 hello. sorry for the delay with answer. you can't actually fill placeholders in a SQL Query itself. Instead, you need to pass your query to your database adapter and receive a prepared statement. See https://github.com/sfackler/rust-postgres for examples. |
Ok, that's what I thought. I don't have experience with databases other than MySQL, will the SQL generated by deuterium be compatible with MySQL? What about other databases like SQLite? If not, do you have plans to create a backend independent query builder? |
@gsingh93 mysql has another placeholder format, so it needs its own adapter. I have no time right now to make it, but it's quite simple. See example in https://github.com/deuterium-orm/deuterium/blob/master/src/sql/adapter/mod.rs. All outer stuff in deuterium is standard for all the databases. |
@s-panferov I added a mysql adapter in #11, take a look. Also, why do the predicates take values if the values aren't used when building the SQL statement? |
The idea was to hold them until they can be used at the final stage. Look at the file: https://github.com/deuterium-orm/deuterium-orm/blob/master/src/adapter/postgres.rs You can extract them and pass to the placeholders: https://github.com/deuterium-orm/deuterium-orm/blob/master/src/adapter/postgres.rs#L38-L58 |
Ok, I think I finally understand what's going on. I think a simple example like this should be added to the README:
But now even though I can print out the arguments, I can't actually convert them into types other libraries can use to actually execute the statements (assuming I'm not using the postgres adapter). Is there a way to convert the context data into primitive types, like strings and integers (for the case when the |
Looking at some examples, I can see how to build a query with placeholders, but I don't see how to actually fill in those place holders. It looks like I need to make a new
SqlContext
that wraps anSqlAdapter
, and I can construct new, empty ones, but can I use the values I already supplied in thewhere
clause?Unrelated question, does this only work for postgres or should this work for any SQL implementation?
The text was updated successfully, but these errors were encountered: