Add named parameters support

SQLite supports named parameters in either of these forms:
- $NAME
- :NAME
- @NAME

These parameters should be supplied to the query either in a form of a map
or as a list, the key is always iodata:
- #{":myparam" => "value"}
- [{"$myparam", 1}]
- [{text, "@myparam", "value"}]
This commit is contained in:
Dmitry Matveyev
2023-01-08 13:54:27 +06:00
parent c71ad3eb6b
commit 16580ce11d
5 changed files with 99 additions and 1 deletions

View File

@@ -42,6 +42,7 @@
bind_text/3,
bind_blob/3,
bind_null/2,
bind_parameter_index/2,
step/1,
@@ -194,6 +195,13 @@ bind_blob(_Statement, _Index, _Value) ->
bind_null(_Statement, _Index) ->
erlang:nif_error(nif_library_not_loaded).
-spec bind_parameter_index(Statement, ParameterName) -> Result when
Statement :: esqlite3_stmt_ref(),
ParameterName :: iodata(),
Result :: {ok, integer()} | error.
bind_parameter_index(_Statement, _ParameterName) ->
erlang:nif_error(nif_library_not_loaded).
-spec step(Statement) -> StepResult when
Statement :: esqlite3_stmt_ref(),
StepResult :: row() | '$done' | error().