Skip to content
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

special support for constants in prepared statements #34

Open
crawshaw opened this issue Aug 7, 2018 · 1 comment
Open

special support for constants in prepared statements #34

crawshaw opened this issue Aug 7, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@crawshaw
Copy link
Owner

crawshaw commented Aug 7, 2018

(Thinking aloud.)

One of the more annoying aspects of my queries is using constants defined in Go as part of a statement:

type Role int

const (
        RoleAdmin Role = 1
        RoleGuest Role = 2
)
stmt := conn.Prep("SELECT ... WHERE Role = $role")
stmt.SetInt64("$role", int64(RoleAdmin))
...

One possibility would be pre-processing SQL literals through another package that has registered enum names, and can fill out values. That's nice, because I want to pile as little stuff into the sqlite package as possible.

Another possibility would be to leverage some uncommon component of SQLite's parameter naming, and make it possible to pre-register constant parameter names with a connection (and a pool).

It might look something like this:

conn.RegisterConst("mypkg.RoleAdmin", mypkg.RoleAdmin)
conn.RegisterConst("mypkg.RoleGuest", mypkg.RoleGuest)

then it could be used as:

stmt := conn.Prep("SELECT ... WHERE Role = $const(mypkg.RoleAdmin)")

The sqlite package would then ban the use of the parameter name $const if it's not referring to a registered constant (by inspecting the query when it is first prepared).

Hmm.

@crawshaw crawshaw changed the title special support for constants and prepared statements special support for constants in prepared statements Aug 7, 2018
@AdamSLevy AdamSLevy added the enhancement New feature or request label Dec 12, 2019
@AdamSLevy
Copy link
Collaborator

What feature of SQLite were you considering using for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants