// add back execl because it's been removed from sqlx for a long time func execl(db sqlx.Execer, q string, args ...interface{}) sql.Result { res, err := db.Exec(q, args...) if err != nil { log.Printf("Error executing %s %#v: %s", q, args, err) } return res }
func Execf(e sqlx.Execer, query string, args ...interface{}) (sql.Result, error) { res, err := e.Exec(query, args...) if err != nil { log.Fatalln(query, res, err) } return res, err }
// MultiExec is a helper function for running multiple queries. func MultiExec(e sqlx.Execer, query string) { stmts := strings.Split(query, ";\n") if len(strings.Trim(stmts[len(stmts)-1], " \n\t\r")) == 0 { stmts = stmts[:len(stmts)-1] } for _, s := range stmts { _, err := e.Exec(s) if err != nil { fmt.Println(err, s) } } }
func MultiExec(e sqlx.Execer, query string) error { stmts := strings.Split(query, ";\n") if len(strings.Trim(stmts[len(stmts)-1], " \n\t\r")) == 0 { stmts = stmts[:len(stmts)-1] } for _, s := range stmts { if _, err := e.Exec(s); err != nil { return err } } return nil }
func DestroyAuthorizationWithCode(e sqlx.Execer, code string) error { const ( Q = `DELETE FROM authorizations WHERE code = $1;` ) _, err := e.Exec(Q, code) if err == sql.ErrNoRows { return nil } if err != nil { return err } return nil }
func DestroyAccessTokenWithRefreshToken(e sqlx.Execer, token string) error { const ( Q = `DELETE FROM access_tokens WHERE refresh_token = $1;` ) _, err := e.Exec(Q, token) if err == sql.ErrNoRows { return nil } if err != nil { return err } return nil }