db_client

package
v0.1.0-alpha.202401101409 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MaxConnLifeTime = 10 * time.Minute
	MaxConnIdleTime = 1 * time.Minute
)

Variables

This section is empty.

Functions

func IsConnectionString

func IsConnectionString(connString string) bool

Types

type DbClient

type DbClient struct {

	// connection UserPool for user initiated queries
	UserPool *sql.DB

	// connection used to run system/plumbing queries (connection state, server settings)
	ManagementPool *sql.DB

	// TODO KAI new hook <TIMING>
	BeforeExecuteHook func(context.Context, *sql.Conn) error

	// if a custom search path or a prefix is used, store it here
	CustomSearchPath []string
	SearchPathPrefix []string
	// the default user search path
	UserSearchPath []string
	// 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) (*queryresult.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) (*queryresult.SyncQueryResult, error)

execute a query against this client and wait for the result

func (*DbClient) GetConnectionString

func (c *DbClient) GetConnectionString() string

func (*DbClient) GetCustomSearchPath

func (c *DbClient) GetCustomSearchPath() []string

func (*DbClient) GetRequiredSessionSearchPath

func (c *DbClient) GetRequiredSessionSearchPath() []string

GetRequiredSessionSearchPath implements Client

func (*DbClient) LoadUserSearchPath

func (c *DbClient) LoadUserSearchPath(ctx context.Context) error

func (*DbClient) LoadUserSearchPathForConnection

func (c *DbClient) LoadUserSearchPathForConnection(ctx context.Context, connection *sql.Conn) error

func (*DbClient) RegisterNotificationListener

func (c *DbClient) RegisterNotificationListener(func(notification *pgconn.Notification))

RegisterNotificationListener has an empty implementation NOTE: we do not (currently) support notifications from remote connections

func (*DbClient) ResetPools

func (c *DbClient) ResetPools(ctx context.Context)

TODO KAI STEAMPIPE ONLY <MISC> Unimplemented (sql.DB does not have a mechanism to reset pools) - refreshDbClient terminates the current connection and opens up a new connection to the service.

func (*DbClient) SetRequiredSessionSearchPath

func (c *DbClient) SetRequiredSessionSearchPath(ctx context.Context) error

SetRequiredSessionSearchPath checks if either a search-path or search-path-prefix is set in config, and if so, set the search path (otherwise fall back to user search path) this just sets the required search path for this client - when creating a database session, we will actually set the searchPath

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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