Documentation
¶
Index ¶
- Constants
- func Drivers() []string
- func NewStruct(typ reflect.Type) reflect.Value
- func Register(name string, dbType DbType)
- func ScanRows[T any](rows *sql.Rows, schema *CachedSchema) ([]T, error)
- func TypeOf(v any) reflect.Type
- func TypeOfT[T any]() reflect.Type
- func UnwrapValueOf(v any) reflect.Value
- type CachedSchema
- func (s *CachedSchema) BuildInsertQueryMysql(tableName string) string
- func (s *CachedSchema) BuildInsertQueryPG(tableName string) string
- func (s *CachedSchema) BuildWhereClause(val reflect.Value, whereFields []string, paramStyle string) (string, []any, error)
- func (s *CachedSchema) ExtractValues(val reflect.Value) []any
- type Config
- type Database
- type DbType
- type FieldInfo
- type FieldNotFoundError
- type ScanTypeError
- type Table
Constants ¶
const KindStruct = reflect.Struct
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register associates a driver name with a DbType. It is intended to be called from a backend package's init function. Registering the same name twice is a no-op; registering a name that maps to a different DbType panics, since that indicates a programming error rather than a runtime condition.
func ScanRows ¶
func ScanRows[T any](rows *sql.Rows, schema *CachedSchema) ([]T, error)
ScanRows reads every row into a T and returns them.
It is shared by the SQL backends so that column mapping and value materialisation live in exactly one place.
T may be either the struct type (User) or a pointer to it (*User); both are handled. Columns returned by the query that are absent from the schema are discarded.
func TypeOfT ¶
TypeOfT returns the struct type of T, dereferencing pointer types. It is the type-safe counterpart of TypeOf for generic code paths.
func UnwrapValueOf ¶
Types ¶
type CachedSchema ¶
type CachedSchema struct {
Type reflect.Type
Fields []FieldInfo
Insertable []FieldInfo
PKIndex int
FieldMap map[string]FieldInfo
InsertColsMysql string
InsertPlaceMysql string
InsertColsPG string
InsertPlacePG string
}
func GetOrBuildSchema ¶
func GetOrBuildSchema(typ reflect.Type) *CachedSchema
func SchemaOfT ¶
func SchemaOfT[T any]() *CachedSchema
SchemaOfT returns the cached schema for T, building it on first use.
func (*CachedSchema) BuildInsertQueryMysql ¶
func (s *CachedSchema) BuildInsertQueryMysql(tableName string) string
func (*CachedSchema) BuildInsertQueryPG ¶
func (s *CachedSchema) BuildInsertQueryPG(tableName string) string
func (*CachedSchema) BuildWhereClause ¶
func (*CachedSchema) ExtractValues ¶
func (s *CachedSchema) ExtractValues(val reflect.Value) []any
type FieldNotFoundError ¶
type FieldNotFoundError struct {
Name string
}
func (*FieldNotFoundError) Error ¶
func (e *FieldNotFoundError) Error() string
type ScanTypeError ¶
ScanTypeError reports that rows could not be materialised into T.
func (*ScanTypeError) Error ¶
func (e *ScanTypeError) Error() string