mirror of https://github.com/VinGarcia/ksql.git
Change type of Client.db to be an interface
This will be helpful soon when we add the Transactions featurepull/2/head
parent
ea7a23f32f
commit
f72ccb1664
|
@ -13,7 +13,12 @@ type DB struct {
|
||||||
driver string
|
driver string
|
||||||
dialect dialect
|
dialect dialect
|
||||||
tableName string
|
tableName string
|
||||||
db *sql.DB
|
db sqlProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
type sqlProvider interface {
|
||||||
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
||||||
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New instantiates a new client
|
// New instantiates a new client
|
||||||
|
|
|
@ -952,7 +952,9 @@ func shiftErrSlice(errs *[]error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsersByID(db *sql.DB, dialect dialect, resultsPtr *[]User, ids ...uint) error {
|
func getUsersByID(dbi sqlProvider, dialect dialect, resultsPtr *[]User, ids ...uint) error {
|
||||||
|
db := dbi.(*sql.DB)
|
||||||
|
|
||||||
placeholders := make([]string, len(ids))
|
placeholders := make([]string, len(ids))
|
||||||
params := make([]interface{}, len(ids))
|
params := make([]interface{}, len(ids))
|
||||||
for i := range ids {
|
for i := range ids {
|
||||||
|
@ -992,7 +994,9 @@ func getUsersByID(db *sql.DB, dialect dialect, resultsPtr *[]User, ids ...uint)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUserByID(db *sql.DB, dialect dialect, result *User, id uint) error {
|
func getUserByID(dbi sqlProvider, dialect dialect, result *User, id uint) error {
|
||||||
|
db := dbi.(*sql.DB)
|
||||||
|
|
||||||
row := db.QueryRow(`SELECT id, name, age FROM users WHERE id=`+dialect.Placeholder(0), id)
|
row := db.QueryRow(`SELECT id, name, age FROM users WHERE id=`+dialect.Placeholder(0), id)
|
||||||
if row.Err() != nil {
|
if row.Err() != nil {
|
||||||
return row.Err()
|
return row.Err()
|
||||||
|
|
Loading…
Reference in New Issue