Factor out StatementList to sqlutil and use it in userapi

It helps with the boilerplate.
This commit is contained in:
Kegan Dougal 2021-07-28 18:30:04 +01:00
parent 9e4618000e
commit ed4097825b
43 changed files with 145 additions and 264 deletions

View file

@ -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
}