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 /userapi/storage/accounts/postgres/accounts_table.go | |
parent | 9e4618000e0347741eac1279bf6c94c3b9980785 (diff) |
Factor out StatementList to `sqlutil` and use it in `userapi`
It helps with the boilerplate.
Diffstat (limited to 'userapi/storage/accounts/postgres/accounts_table.go')
-rw-r--r-- | userapi/storage/accounts/postgres/accounts_table.go | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/userapi/storage/accounts/postgres/accounts_table.go b/userapi/storage/accounts/postgres/accounts_table.go index 4eaa5b58..b57aa901 100644 --- a/userapi/storage/accounts/postgres/accounts_table.go +++ b/userapi/storage/accounts/postgres/accounts_table.go @@ -81,26 +81,15 @@ func (s *accountsStatements) execSchema(db *sql.DB) error { } func (s *accountsStatements) prepare(db *sql.DB, server gomatrixserverlib.ServerName) (err error) { - if s.insertAccountStmt, err = db.Prepare(insertAccountSQL); err != nil { - return - } - if s.updatePasswordStmt, err = db.Prepare(updatePasswordSQL); err != nil { - return - } - if s.deactivateAccountStmt, err = db.Prepare(deactivateAccountSQL); err != nil { - return - } - if s.selectAccountByLocalpartStmt, err = db.Prepare(selectAccountByLocalpartSQL); err != nil { - return - } - if s.selectPasswordHashStmt, err = db.Prepare(selectPasswordHashSQL); err != nil { - return - } - if s.selectNewNumericLocalpartStmt, err = db.Prepare(selectNewNumericLocalpartSQL); err != nil { - return - } s.serverName = server - return + return sqlutil.StatementList{ + {&s.insertAccountStmt, insertAccountSQL}, + {&s.updatePasswordStmt, updatePasswordSQL}, + {&s.deactivateAccountStmt, deactivateAccountSQL}, + {&s.selectAccountByLocalpartStmt, selectAccountByLocalpartSQL}, + {&s.selectPasswordHashStmt, selectPasswordHashSQL}, + {&s.selectNewNumericLocalpartStmt, selectNewNumericLocalpartSQL}, + }.Prepare(db) } // insertAccount creates a new account. 'hash' should be the password hash for this account. If it is missing, |