Description
To bind a named parameter to a prepared statement, you need to first call parameterIndex(parameterName)
for each named parameter to get the indexes, then then make a separate bind
call, passing in the index, for each parameter. This works, but is awkward. It would be more natural to be able to pass an object with the parameter names as keys and the data values to bind as values.
It would also be convenient to be able to pass an array of values for positional or auto-increment parameters.
A challenge for both of these is how to specify the data type for each value. For example, if a JS number
is supplied, it's not clear which DuckDB data type that should be bound as. INTEGER? DOUBLE? One of the many other numeric types? Perhaps a reasonable default could be selected, and then an optional map or array of types could be passed if more control is desired.
It would also be nice to add convenience functions that take a parameterized SQL string plus some arguments (positional or named) and do the prepare, bind, and run all in one call.
See pg-promise for one example of an API that does this well.