diff options
author | Kegan Dougal <kegan@matrix.org> | 2021-07-28 18:30:04 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2021-07-28 18:30:04 +0100 |
commit | ed4097825bc65f2332bcdc975ed201841221ff7c (patch) | |
tree | 4ac6270fa282b1d13ac73c97e4078f1961dbdf4e /internal | |
parent | 9e4618000e0347741eac1279bf6c94c3b9980785 (diff) |
Factor out StatementList to `sqlutil` and use it in `userapi`
It helps with the boilerplate.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/sqlutil/sql.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/internal/sqlutil/sql.go b/internal/sqlutil/sql.go index 6cf17bea..98cc396a 100644 --- a/internal/sqlutil/sql.go +++ b/internal/sqlutil/sql.go @@ -152,3 +152,19 @@ func RunLimitedVariablesQuery(ctx context.Context, query string, qp QueryProvide } return nil } + +// StatementList is a list of SQL statements to prepare and a pointer to where to store the resulting prepared statement. +type StatementList []struct { + Statement **sql.Stmt + SQL string +} + +// Prepare the SQL for each statement in the list and assign the result to the prepared statement. +func (s StatementList) Prepare(db *sql.DB) (err error) { + for _, statement := range s { + if *statement.Statement, err = db.Prepare(statement.SQL); err != nil { + return + } + } + return +} |