Documentation ¶
Overview ¶
Package sqlz contains core types such as Kind and Record.
Index ¶
- Constants
- Variables
- func ConnectorWith(impl driver.Connector, fn func(ctx context.Context, conn driver.Conn) error) driver.Connector
- func ExecAffected(ctx context.Context, db Execer, query string, args ...any) (affected int64, err error)
- func RequireSingleConn(db DB) error
- func RowsScanColumn[T any](ctx context.Context, rows *sql.Rows) (vals []T, err error)
- type DB
- type Execer
- type NullBool
- type Preparer
- type Queryer
Constants ¶
const ( TableTypeTable = "table" TableTypeView = "view" TableTypeVirtual = "virtual" )
Canonical driver-independent names for table types.
Variables ¶
var ( RTypeInt = reflect.TypeOf(0) RTypeInt8 = reflect.TypeOf(int8(0)) RTypeInt16 = reflect.TypeOf(int16(0)) RTypeInt32 = reflect.TypeOf(int32(0)) RTypeInt64 = reflect.TypeOf(int64(0)) RTypeNullInt64 = reflect.TypeOf(sql.NullInt64{}) RTypeDecimal = reflect.TypeOf(decimal.Decimal{}) RTypeNullDecimal = reflect.TypeOf(decimal.NullDecimal{}) RTypeFloat32 = reflect.TypeOf(float32(0)) RTypeFloat64 = reflect.TypeOf(float64(0)) RTypeNullFloat64 = reflect.TypeOf(sql.NullFloat64{}) RTypeBool = reflect.TypeOf(true) RTypeNullBool = reflect.TypeOf(sql.NullBool{}) RTypeString = reflect.TypeOf("") RTypeNullString = reflect.TypeOf(sql.NullString{}) RTypeTime = reflect.TypeOf(time.Time{}) RTypeNullTime = reflect.TypeOf(sql.NullTime{}) RTypeBytes = reflect.TypeOf([]byte{}) RTypeNil = reflect.TypeOf(nil) RTypeAny = reflect.TypeOf((any)(nil)) )
Cached results from reflect.TypeOf for commonly used types.
Functions ¶
func ConnectorWith ¶ added in v0.43.0
func ConnectorWith(impl driver.Connector, fn func(ctx context.Context, conn driver.Conn) error) driver.Connector
ConnectorWith returns a stdlib driver.Connector that wraps the supplied impl, applying the non-nil fn to the connection returned by Connect. If fn is nil, impl is returned unchanged.
If impl implements io.Closer, the returned connector will also implement io.Closer. This behavior conforms to the expectations of driver.Connector:
If a Connector implements io.Closer, the sql package's DB.Close method will call Close and return error (if any).
func ExecAffected ¶ added in v0.15.0
func ExecAffected(ctx context.Context, db Execer, query string, args ...any) (affected int64, err error)
ExecAffected invokes db.ExecContext, returning the count of rows affected and any error.
func RequireSingleConn ¶ added in v0.43.0
RequireSingleConn returns nil if db is a type that guarantees a single database connection. That is, RequireSingleConn returns an error if db does not have type *sql.Conn or *sql.Tx.
func RowsScanColumn ¶ added in v0.47.4
RowsScanColumn scans a single-column *sql.Rows into a slice of T. If the returned value could be null, use a nullable type, e.g. sql.NullString. Arg rows is always closed. On any error, the returned slice is nil.
Types ¶
type DB ¶
DB is a union of Execer, Queryer and Preparer. DB's method set is implemented by sql.DB, sql.Conn and sql.Tx. This can probably be better named, as it conflicts with sql.DB.
type Execer ¶
type Execer interface { // ExecContext is documented by sql.DB.ExecContext. ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) }
Execer abstracts the ExecContext method from sql.DB and friends.
type NullBool ¶
NullBool is similar to sql.NullBool, but accepts more boolean representations, e.g. "YES", "Y", "NO", "N", etc. These boolean values are returned by SQL Server and Postgres at times.
type Preparer ¶
type Preparer interface { // PrepareContext is documented by sql.DB.PrepareContext. PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
Preparer abstracts the PrepareContext method from sql.DB and friends.
type Queryer ¶
type Queryer interface { // QueryContext is documented by sql.DB.QueryContext. QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) // QueryRowContext is documented by sql.DB.QueryRowContext. QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }
Queryer abstracts the QueryContext and QueryRowContext methods from sql.DB and friends.