Chore: add/update sqlstore-related helper functions (#77408)

* add/update sqlstore-related helper functions

* add documentation & tests for InsertQuery and UpdateQuery, make generated SQL deterministic by sorting columns

* remove old log line
This commit is contained in:
Dan Cech
2023-11-03 10:30:52 -04:00
committed by GitHub
parent 6b729389b5
commit 67b2972052
9 changed files with 237 additions and 11 deletions
+9 -2
View File
@@ -42,7 +42,7 @@ func (gs *SessionDB) NamedExec(ctx context.Context, query string, arg any) (sql.
return gs.sqlxdb.NamedExecContext(ctx, gs.sqlxdb.Rebind(query), arg)
}
func (gs *SessionDB) driverName() string {
func (gs *SessionDB) DriverName() string {
return gs.sqlxdb.DriverName()
}
@@ -69,7 +69,7 @@ func (gs *SessionDB) WithTransaction(ctx context.Context, callback func(*Session
}
func (gs *SessionDB) ExecWithReturningId(ctx context.Context, query string, args ...any) (int64, error) {
return execWithReturningId(ctx, gs.driverName(), query, gs, args...)
return execWithReturningId(ctx, gs.DriverName(), query, gs, args...)
}
type SessionTx struct {
@@ -125,3 +125,10 @@ func execWithReturningId(ctx context.Context, driverName string, query string, s
}
return id, nil
}
type SessionQuerier interface {
Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
var _ SessionQuerier = &SessionDB{}
var _ SessionQuerier = &SessionTx{}