< Prev: SQL escape hatch
Up: Basics
Next: Struct Mapping >

Basics: Database connection

sq's .Fetch() and .Exec() accept any database connection matching this interface
type DB interface {
    Query(query string, args ...interface{}) (*sql.Rows, error)
    QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
    Exec(query string, args ...interface{}) (sql.Result, error)
    ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
This means you can use database/sql and sqlx's connections out of the box.
< Prev: SQL escape hatch
Up: Basics
Next: Struct Mapping >