db_client

package
v0.1.0-alpha.202401221713 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxConnLifeTime = 10 * time.Minute
	MaxConnIdleTime = 1 * time.Minute
)
View Source
const (
	DriverPostgres = "pgx"
	DriverMySQL    = "mysql"
	DriverDuckDB   = "duckdb"
	DriverSQLite   = "sqlite3"
	DriverUnknown  = "_unknown_"
)

Variables

This section is empty.

Functions

func ExecuteQuery

func ExecuteQuery(ctx context.Context, client DbClient, queryString string, args ...any) (*queryresult.ResultStreamer, error)

ExecuteQuery executes a single query. If shutdownAfterCompletion is true, shutdown the client after completion

func MaxDbConnections

func MaxDbConnections() int

func PgEscapeName

func PgEscapeName(name string) string

PgEscapeName escapes strings which will be usaed for Podsdtgres object identifiers (table names, column names, schema names)

func PgEscapeSearchPath

func PgEscapeSearchPath(searchPath []string) []string

PgEscapeSearchPath applies postgres escaping to search path and remove whitespace

func PgEscapeString

func PgEscapeString(str string) string

PgEscapeString escapes strings which are to be inserted use a custom escape tag to avoid chance of clash with the escaped text https://medium.com/@lnishada/postgres-dollar-quoting-6d23e4f186ec

Types

type DbClient

type DbClient struct {

	// TODO KAI new hook <TIMING>
	BeforeExecuteHook func(context.Context, *sql.Conn) error
	// contains filtered or unexported fields
}

DbClient wraps over `sql.DB` and gives an interface to the database

func NewDbClient

func NewDbClient(ctx context.Context, connectionString string) (_ *DbClient, err error)

func (*DbClient) Close

func (c *DbClient) Close(context.Context) error

Close closes the connection to the database and shuts down the backend

func (*DbClient) Execute

func (c *DbClient) Execute(ctx context.Context, query string, args ...any) (*localqueryresult.Result, error)

execute the query in the given Context NOTE: The returned Result MUST be fully read - otherwise the connection will block and will prevent further communication

func (*DbClient) ExecuteSync

func (c *DbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*localqueryresult.SyncQueryResult, error)

execute a query against this client and wait for the result

func (*DbClient) GetConnectionString

func (c *DbClient) GetConnectionString() string

func (*DbClient) StartQuery

func (c *DbClient) StartQuery(ctx context.Context, dbConn *sql.Conn, query string, args ...any) (rows *sql.Rows, err error)

StartQuery runs query in a goroutine, so we can check for cancellation in case the client becomes unresponsive and does not respect context cancellation

type PgxConnector

type PgxConnector struct {
	driver.Connector
	AfterConnectFunc func(context.Context, driver.Conn) error
}

func NewPgxConnector

func NewPgxConnector(dataSourceName string, afterConnectFunc func(context.Context, driver.Conn) error) (*PgxConnector, error)

func (*PgxConnector) Connect

func (c *PgxConnector) Connect(ctx context.Context) (driver.Conn, error)

Jump to

Keyboard shortcuts

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