How to execute same query with different bindings within same transaction in Rust SQLx?

Viewed 22

I need to insert multiple rows into a table, so I've got a query like INSERT INTO table (col1, col2) VALUES (?, ?) and arguments as list of pairs. Is there a way to execute it in SQLx without constructing a new string like INSERT ... VALUES ((?, ?), ..., (?, ?)) each time?

I found Query::execute_many, but I'm not sure if it's doing what, say, Python's executemany() from mysql adaptor is doing.

1 Answers

Actually MySql Python Connector's execute_many constructs VALUES ((?, ?), ..., (?, ?)) internally. If you want do that in sqlx, QueryBuilder::push_values can construct SQL VALUES strings for you.

Related