tursodatabase / libsql-client-go

Go client API for libSQL
MIT License
159 stars 23 forks source link

Improve SQLite parameter syntax support #100

Closed penberg closed 2 weeks ago

penberg commented 6 months ago

From Discord:

I have a question regarding the libsql-client-go library (https://github.com/tursodatabase/libsql-client-go), does it support "positional placeholders" (I am not sure if this is the right way to call them) in queries?
I mean, queries like this one:
db.Exec("INSERT INTO test_table (test_field) VALUES ($1)", fieldValue)
I tested it and it doesn't work, using github.com/mattn/go-sqlite3 it works (maybe this is an extended behavior)
using "question mark placeholders" it works without any problem
db.Exec("INSERT INTO test_table (test_field) VALUES (?)", fieldValue)
I am asking if it is expected this behavior because the query with positional placeholder is from an internal lib I am using 😅 

Let's add support for all the parameter templates:

https://www.sqlite.org/lang_expr.html#parameters

p0isonra1n commented 6 months ago

I have been looking at this issue and I just want to make sure I am understanding correct.

The below named parameter query does work libsql when a NamedArg is used as the arg.

db.exec("INSERT INTO "+t.name+" (a, b) VALUES ($Arg1, $Arg2)", sql.Named("Arg1", i), sql.Named("Arg2", i))

I have submitted a pull request to add tests for the three types of named parameters. #101

guergabo commented 1 month ago

The only missing parameter template was positional parameter with indexes. I have opened a PR to add support for it.