database

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 20 Imported by: 0

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.

Package database - Content managed by Project Forge, see [projectforge.md] for details.

Index

Constants

View Source
const SQLiteEnabled = true

Variables

This section is empty.

Functions

func ArrayToString

func ArrayToString(a []string) string

func RegistryKeys added in v0.2.1

func RegistryKeys() []string

func SQLDelete

func SQLDelete(table string, where string, _ *DBType) string

func SQLInClause

func SQLInClause(column string, numParams int, offset int, dbt *DBType) string

func SQLInsert

func SQLInsert(table string, columns []string, rows int, dbt *DBType) string

func SQLInsertReturning

func SQLInsertReturning(table string, columns []string, rows int, returning []string, dbt *DBType) string

func SQLSelect

func SQLSelect(columns string, tables string, where string, orderBy string, limit int, offset int, dbt *DBType) string

func SQLSelectGrouped

func SQLSelectGrouped(columns string, tables string, where string, groupBy string, orderBy string, limit int, offset int, dbt *DBType) string

func SQLSelectSimple

func SQLSelectSimple(columns string, tables string, dbt *DBType, where ...string) string

func SQLUpdate

func SQLUpdate(table string, columns []string, where string, dbt *DBType) string

func SQLUpdateReturning

func SQLUpdateReturning(table string, columns []string, where string, returned []string, dbt *DBType) string

func SQLUpsert

func SQLUpsert(table string, columns []string, rows int, conflicts []string, updates []string, dbt *DBType) string

func StringToArray

func StringToArray(s string) []string

func UUIDFromGUID added in v0.2.12

func UUIDFromGUID(x *any) *uuid.UUID

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

func (t *DBType) PlaceholderFor(idx int) string

func (*DBType) Quoted added in v0.4.0

func (t *DBType) Quoted(s string) string

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

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

type PostgresServiceParams

type PostgresServiceParams struct {
	Host        string `json:"host"`
	Port        int    `json:"port,omitempty"`
	Schema      string `json:"schema,omitempty"`
	Username    string `json:"username"`
	Password    string `json:"password,omitempty"`
	Database    string `json:"database,omitempty"`
	SSLMode     string `json:"sslmode,omitempty"`
	SSLKey      string `json:"sslkey,omitempty"`
	SSLCert     string `json:"sslcert,omitempty"`
	SSLRootCert string `json:"sslrootcert,omitempty"`
}

func PostgresParamsFromService

func PostgresParamsFromService() (*PostgresServiceParams, error)

PostgresParamsFromService parses connection service config from DB_SERVICE env var from file located at DB_SERVICEFILE. If DB_SERVICEFILE is not provided, it searches for the pg service conf file in home directory.

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

type SQLiteParams

type SQLiteParams struct {
	File   string `json:"file"`
	Schema string `json:"schema,omitempty"`
	Debug  bool   `json:"debug,omitempty"`
}

func SQLiteParamsFromEnv

func SQLiteParamsFromEnv(key string, prefix string) *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
}

func NewService

func NewService(typ *DBType, key string, dbName string, schName string, username string, debug bool, db *sqlx.DB, logger util.Logger) (*Service, error)

func OpenDefaultMySQL

func OpenDefaultMySQL(logger util.Logger) (*Service, error)

func OpenDefaultPostgres

func OpenDefaultPostgres(ctx context.Context, logger util.Logger) (*Service, error)

func OpenDefaultSQLServer added in v0.2.12

func OpenDefaultSQLServer(ctx context.Context, logger util.Logger) (*Service, error)

func OpenDefaultSQLite

func OpenDefaultSQLite(ctx context.Context, logger util.Logger) (*Service, error)

func OpenMySQL added in v0.4.3

func OpenMySQL(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)

func OpenMySQLDatabase

func OpenMySQLDatabase(ctx context.Context, key string, params *MySQLParams, logger util.Logger) (*Service, error)

func OpenPostgres

func OpenPostgres(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)

func OpenPostgresDatabase

func OpenPostgresDatabase(ctx context.Context, key string, params *PostgresParams, logger util.Logger) (*Service, error)

func OpenPostgresDatabaseSSL

func OpenPostgresDatabaseSSL(ctx context.Context, key string, ep *PostgresParams, sp *PostgresServiceParams, logger util.Logger) (*Service, error)

func OpenSQLServer added in v0.2.12

func OpenSQLServer(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)

func OpenSQLServerDatabase added in v0.2.12

func OpenSQLServerDatabase(ctx context.Context, key string, params *SQLServerParams, logger util.Logger) (*Service, error)

func OpenSQLite

func OpenSQLite(ctx context.Context, key string, prefix string, logger util.Logger) (*Service, error)

func OpenSQLiteDatabase

func OpenSQLiteDatabase(ctx context.Context, key string, params *SQLiteParams, logger util.Logger) (*Service, error)

func RegistryGet added in v0.2.1

func RegistryGet(key string) (*Service, error)

func (*Service) Close

func (s *Service) Close() error

func (*Service) Conn

func (s *Service) Conn(ctx context.Context) (*sql.Conn, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, values ...any) (int, error)

func (*Service) DeleteOne

func (s *Service) DeleteOne(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error

func (*Service) Exec

func (s *Service) Exec(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, values ...any) (int, error)

func (*Service) Get

func (s *Service) Get(ctx context.Context, row any, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error

func (*Service) Healthcheck

func (s *Service) Healthcheck(dbName string, db *sqlx.DB) error

func (*Service) Insert

func (s *Service) Insert(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error

func (*Service) Prepare added in v0.2.12

func (s *Service) Prepare(ctx context.Context, q string) (*sqlx.Stmt, error)

func (*Service) Query

func (s *Service) Query(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (*sqlx.Rows, error)

func (*Service) Query2DArray

func (s *Service) Query2DArray(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) ([][]any, error)

func (*Service) QueryKVMap

func (s *Service) QueryKVMap(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (util.ValueMap, error)

func (*Service) QueryRows

func (s *Service) QueryRows(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) ([]util.ValueMap, error)

func (*Service) QuerySingleRow

func (s *Service) QuerySingleRow(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (util.ValueMap, error)

func (*Service) Select

func (s *Service) Select(ctx context.Context, dest any, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error

func (*Service) SingleBool added in v0.2.1

func (s *Service) SingleBool(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (bool, error)

func (*Service) SingleInt

func (s *Service) SingleInt(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) (int64, error)

func (*Service) StartTransaction

func (s *Service) StartTransaction(logger util.Logger) (*sqlx.Tx, error)

func (*Service) Stats

func (s *Service) Stats() sql.DBStats

func (*Service) Update

func (s *Service) Update(ctx context.Context, q string, tx *sqlx.Tx, expected int, logger util.Logger, values ...any) (int, error)

func (*Service) UpdateOne

func (s *Service) UpdateOne(ctx context.Context, q string, tx *sqlx.Tx, logger util.Logger, values ...any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL