Help us shape the future of Go! Take the 2026 Go Developer Survey

database

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: PostgreSQL Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Source = catalogKey("source")
	Target = catalogKey("target")
)
View Source
var (
	SourceConnect int
	TargetConnect int
)

Functions

func Close

func Close()

Close waits for connection releases and close them

func CollectAndAssociateContext added in v1.0.0

func CollectAndAssociateContext[P associer[C, P], C any](ctx context.Context, n string, args any, parents []P, rowto rowToFunc[C]) ([]P, int, error)

CollectAndAssociateContext queries child objects

Returns parents with associated components and the count of components.

If a component does not match an existing parent, skip to next component and search starting from last associated parent. Fails after 8 unassociated components.

Use this to query table columns, keys, etc.

func CollectMapContext added in v1.0.0

func CollectMapContext(ctx context.Context, n string, data any) (map[string]any, error)

func CollectObjectsContext added in v1.0.0

func CollectObjectsContext[T any](ctx context.Context, n string, args any, rowto rowToFunc[T]) ([]T, error)

CollectObjectsContext accumulates rows

func Connection

func Connection(ctx context.Context, key catalogKey) *sql.Conn

Connection return SQL connection from context

panics if context does not have a connection.

func DecodeValue added in v1.0.0

func DecodeValue(v any) any

DecodeValue tries to decode network data to go

Useful when scanning RawBytes or any.

func Execute

func Execute(ctx context.Context, id string, sn int, statement string, stdin io.Reader, msg string, logArgs ...any) error

Execute immediatly a SQL statement

Uses statement executor to send query to stdout, files or Postgres.

func ExecuteSourceTask added in v1.0.0

func ExecuteSourceTask(id string, reqs []string, statement, message string) executeSourceTask

ExecuteSourceTask instanciate a dispatch task for a single statement on source

func ExecuteTask

func ExecuteTask(id string, priority int, reqs []string, statement, message string, logArgs ...any) dispatch.Task

ExecuteTask instanciate a dispatch task for a single statement

Use SetupExecution to globally configure query execution.

func ForEachContext added in v1.0.0

func ForEachContext(ctx context.Context, n string, args any, f func(*sql.Rows) error) (int, error)

func ForEachItemAssociateContext added in v1.0.0

func ForEachItemAssociateContext[P associer[C, P], C any](ctx context.Context, parents []P, query func(P) string, rowto rowToFunc[C]) ([]P, int, error)

ForEachItemAssociateContext execute a query for each item

Use it to inspect extra information for item with per-item query like `SHOW CREATE`.

func Get added in v1.0.0

func Get(ctx context.Context, key catalogKey) (conn *sql.Conn, release func(), err error)

Get database connection from one pool

Always return release function, even on error. You must call release function to recycle connection back in pool.

func QueryRowContext added in v1.0.0

func QueryRowContext(ctx context.Context, n string, args any) *sql.Row

QueryRowContext executes a query that is expected to return a single row

Panics if connexion to database is not already established.

func Render added in v1.0.0

func Render(name string, o any) string

Render execute an SQL template

func RowToMap added in v1.0.0

func RowToMap(r *sql.Rows) (map[string]any, error)

RowToMap scan a row as map using column name

func Setup added in v1.0.0

func Setup(sqlFS fs.FS, f func(int) string)

Setup initialize catalog inspection for a specific RDMS

Not calling Setup() before inspecting is a bug.

func SetupExecution

func SetupExecution(f Executer)

SetupExecution saves query executor

func WaitReleased

func WaitReleased()

WaitReleased waits for all connection to close.

func WithConnection

func WithConnection(ctx context.Context, key catalogKey) (context.Context, error)

WithConnection ensure context has a db connection

Connection is released when context is done. You should defer cancel() func before adding connexion to context.

Use Connection() to get connection on success.

Types

type Executer

type Executer interface {
	Execute(ctx context.Context, t Task) error
}

func PostgresExecutor

func PostgresExecutor() Executer

PostgresExecutor sends queries to Postgres.

Requires a Target connection in context as set by WithConnection.

func StreamExecutor

func StreamExecutor(w io.Writer) Executer

StreamExecutor writes queries to stream. Prevents concurrent writes.

func TreeExecutor added in v1.0.0

func TreeExecutor(directory string) Executer

TreeExecutor writes queries to files.

File order depends on scheduling. Creates directory if not exists. Does not clean directory.

type Task added in v1.2.0

type Task struct {
	dispatch.Header
	SerialNumber int
	Statement    string
	// contains filtered or unexported fields
}

func (Task) Run added in v1.2.0

func (t Task) Run(ctx context.Context) error

func (Task) Serial added in v1.2.0

func (t Task) Serial() int

func (*Task) WithProgress added in v1.2.0

func (t *Task) WithProgress(todo int64) Task

Jump to

Keyboard shortcuts

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