Documentation ¶
Overview ¶
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Package database - Content managed by Project Forge, see [projectforge.md] for details.
Index ¶
- Constants
- Variables
- func ArrayToString(a []string) string
- func MapScan(row *sqlx.Rows) (util.ValueMap, error)
- func QueryFieldDescs(fields util.FieldDescs, query string, argOffset int) (string, []any, error)
- func RegistryKeys() []string
- func SQLDelete(table string, where string, _ *DBType) string
- func SQLInClause(column string, numParams int, offset int, dbt *DBType) string
- func SQLInsert(table string, columns []string, rows int, dbt *DBType) string
- func SQLInsertReturning(table string, columns []string, rows int, returning []string, dbt *DBType) string
- func SQLSelect(columns string, tables string, where string, orderBy string, limit int, ...) string
- func SQLSelectGrouped(columns string, tables string, where string, groupBy string, orderBy string, ...) string
- func SQLSelectSimple(columns string, tables string, dbt *DBType, where ...string) string
- func SQLUpdate(table string, columns []string, where string, dbt *DBType) string
- func SQLUpdateReturning(table string, columns []string, where string, returned []string, dbt *DBType) string
- func SQLUpsert(table string, columns []string, rows int, conflicts []string, updates []string, ...) string
- func StringToArray(s string) []string
- func UUIDFromGUID(x any) *uuid.UUID
- type DBType
- type MySQLParams
- type PostgresParams
- type SQLServerParams
- type SQLiteParams
- type Service
- func NewService(typ *DBType, key string, dbName string, schName string, username string, ...) (*Service, error)
- func OpenDefaultMySQL(ctx context.Context, logger util.Logger) (*Service, error)
- func OpenDefaultPostgres(ctx context.Context, logger util.Logger) (*Service, error)
- func OpenDefaultSQLServer(ctx context.Context, logger util.Logger) (*Service, error)
- func OpenDefaultSQLite(ctx context.Context, logger util.Logger) (*Service, error)
- func OpenMySQL(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)
- func OpenMySQLDatabase(ctx context.Context, key string, params *MySQLParams, logger util.Logger) (*Service, error)
- func OpenPostgres(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)
- func OpenPostgresDatabase(ctx context.Context, key string, params *PostgresParams, logger util.Logger) (*Service, error)
- func OpenSQLServer(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)
- func OpenSQLServerDatabase(ctx context.Context, key string, params *SQLServerParams, logger util.Logger) (*Service, error)
- func OpenSQLite(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)
- func OpenSQLiteDatabase(ctx context.Context, key string, params *SQLiteParams, logger util.Logger) (*Service, error)
- func RegistryGet(key string) (*Service, error)
- func (s *Service) Close() error
- func (s *Service) Conn(ctx context.Context) (*sql.Conn, error)
- func (s *Service) Delete(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, ...) (int, error)
- func (s *Service) DeleteOne(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error
- func (s *Service) Exec(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, ...) (int, error)
- func (s *Service) Get(ctx context.Context, row any, q string, tx *sqlx.Tx, logger util.Logger, ...) error
- func (s *Service) Healthcheck(dbName string, db *sqlx.DB) error
- func (s *Service) Insert(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error
- func (s *Service) InsertMap(ctx context.Context, table string, m util.ValueMap, tx *sqlx.Tx, ...) error
- func (s *Service) Prepare(ctx context.Context, q string) (*sqlx.Stmt, error)
- func (s *Service) Query(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (*sqlx.Rows, error)
- func (s *Service) Query2DArray(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) ([][]any, error)
- func (s *Service) QueryKVMap(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (util.ValueMap, error)
- func (s *Service) QueryRows(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) ([]util.ValueMap, error)
- func (s *Service) QuerySingleRow(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (util.ValueMap, error)
- func (s *Service) Select(ctx context.Context, dest any, q string, tx *sqlx.Tx, logger util.Logger, ...) error
- func (s *Service) SingleBool(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (bool, error)
- func (s *Service) SingleInt(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (int64, error)
- func (s *Service) StartTransaction(logger util.Logger) (*sqlx.Tx, error)
- func (s *Service) Stats() sql.DBStats
- func (s *Service) String() string
- func (s *Service) Update(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, ...) (int, error)
- func (s *Service) UpdateOne(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error
Constants ¶
const SQLiteEnabled = true
Variables ¶
var AllTypes = []*DBType{ TypeMySQL, TypePostgres, TypeSQLite, TypeSQLServer, }
var TypeMySQL = &DBType{Key: "mysql", Title: "MySQL", Quote: "`", Placeholder: "?", SupportsReturning: false}
var TypePostgres = &DBType{Key: "postgres", Title: "PostgreSQL", Quote: `"`, Placeholder: "$", SupportsReturning: true}
var TypeSQLServer = &DBType{Key: "sqlserver", Title: "SQL Server", Quote: `"`, Placeholder: "@", SupportsReturning: true}
var TypeSQLite = &DBType{Key: "sqlite", Title: "SQLite", Quote: `"`, Placeholder: "$", SupportsReturning: true}
Functions ¶
func ArrayToString ¶
func QueryFieldDescs ¶ added in v0.4.4
func RegistryKeys ¶ added in v0.2.1
func RegistryKeys() []string
func SQLInsertReturning ¶
func SQLSelectGrouped ¶
func SQLSelectSimple ¶
func SQLUpdateReturning ¶
func StringToArray ¶
func UUIDFromGUID ¶ added in v0.2.12
Types ¶
type DBType ¶
type DBType struct { Key string `json:"key"` Title string `json:"title"` Quote string `json:"-"` Placeholder string `json:"-"` SupportsReturning bool `json:"-"` }
func (*DBType) PlaceholderFor ¶ added in v0.4.0
type MySQLParams ¶
type MySQLParams struct { Host string `json:"host"` Port int `json:"port,omitempty"` Username string `json:"username"` Password string `json:"password,omitempty"` Database string `json:"database,omitempty"` Schema string `json:"schema,omitempty"` MaxConns int `json:"maxConns,omitempty"` Debug bool `json:"debug,omitempty"` }
func MySQLParamsFromEnv ¶
func MySQLParamsFromEnv(key string, defaultUser string, prefix string) *MySQLParams
func MySQLParamsFromMap ¶ added in v0.4.4
func MySQLParamsFromMap(m util.ValueMap) *MySQLParams
type PostgresParams ¶
type PostgresParams struct { Host string `json:"host"` Port int `json:"port,omitempty"` Username string `json:"username"` Password string `json:"password,omitempty"` Database string `json:"database,omitempty"` Schema string `json:"schema,omitempty"` MaxConns int `json:"maxConns,omitempty"` Debug bool `json:"debug,omitempty"` }
func PostgresParamsFromEnv ¶
func PostgresParamsFromEnv(key string, defaultUser string, prefix string) *PostgresParams
func PostgresParamsFromMap ¶ added in v0.4.4
func PostgresParamsFromMap(m util.ValueMap) *PostgresParams
type SQLServerParams ¶ added in v0.2.12
type SQLServerParams struct { Host string `json:"host"` Port int `json:"port,omitempty"` Username string `json:"username"` Password string `json:"password,omitempty"` Database string `json:"database,omitempty"` Schema string `json:"schema,omitempty"` MaxConns int `json:"maxConns,omitempty"` Debug bool `json:"debug,omitempty"` }
func SQLServerParamsFromEnv ¶ added in v0.2.12
func SQLServerParamsFromEnv(key string, defaultUser string, prefix string) *SQLServerParams
func SQLServerParamsFromMap ¶ added in v0.4.4
func SQLServerParamsFromMap(m util.ValueMap) *SQLServerParams
type SQLiteParams ¶
type SQLiteParams struct { File string `json:"file"` User string `json:"user,omitempty"` Password string `json:"password,omitempty"` Schema string `json:"schema,omitempty"` Debug bool `json:"debug,omitempty"` }
func SQLiteParamsFromEnv ¶
func SQLiteParamsFromEnv(key string, prefix string) *SQLiteParams
func SQLiteParamsFromMap ¶ added in v0.4.4
func SQLiteParamsFromMap(m util.ValueMap) *SQLiteParams
type Service ¶
type Service struct { Key string `json:"key"` DatabaseName string `json:"database,omitempty"` SchemaName string `json:"schema,omitempty"` Username string `json:"username,omitempty"` Debug bool `json:"debug,omitempty"` Type *DBType `json:"type"` ReadOnly bool `json:"readonly,omitempty"` // contains filtered or unexported fields }