Documentation ¶
Index ¶
- Constants
- func ExecuteQuery(ctx context.Context, client DbClient, queryString string, args ...any) (*queryresult.ResultStreamer, error)
- func GetCloudWorkspaceConnectionString(workspace string) (string, error)
- func GetDatabaseConfigForResource(resource modconfig.ModTreeItem, workspaceMod *modconfig.Mod, ...) (string, backend.SearchPathConfig, error)
- func GetDefaultDatabaseConfig(opts ...backend.ConnectOption) (string, backend.SearchPathConfig, error)
- func MaxDbConnections() int
- func PgEscapeName(name string) string
- func PgEscapeSearchPath(searchPath []string) []string
- func PgEscapeString(str string) string
- type ClientMap
- func (e *ClientMap) Add(client *DbClient, searchPathConfig backend.SearchPathConfig) *ClientMap
- func (e *ClientMap) Close(ctx context.Context) error
- func (e *ClientMap) Get(connectionString string, searchPathConfig backend.SearchPathConfig) *DbClient
- func (e *ClientMap) GetOrCreate(ctx context.Context, connectionString string, ...) (*DbClient, error)
- type ClientMapOption
- type DbClient
- func (c *DbClient) Close(context.Context) error
- func (c *DbClient) Execute(ctx context.Context, query string, args ...any) (*localqueryresult.Result, error)
- func (c *DbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*queryresult.SyncQueryResult, error)
- func (c *DbClient) GetConnectionString() string
- func (c *DbClient) StartQuery(ctx context.Context, dbConn *sql.Conn, query string, args ...any) (rows *sql.Rows, err error)
- type PgxConnector
Constants ¶
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 GetCloudWorkspaceConnectionString ¶ added in v1.0.0
func GetDatabaseConfigForResource ¶
func GetDatabaseConfigForResource(resource modconfig.ModTreeItem, workspaceMod *modconfig.Mod, defaultDatabase string, defaultSearchPathConfig backend.SearchPathConfig) (string, backend.SearchPathConfig, error)
func GetDefaultDatabaseConfig ¶
func GetDefaultDatabaseConfig(opts ...backend.ConnectOption) (string, backend.SearchPathConfig, error)
GetDefaultDatabaseConfig builds the default database and searchPathConfig NOTE: if the dashboardUI has overridden the search path, opts wil be passed in to set the overridden value
func MaxDbConnections ¶
func MaxDbConnections() int
func PgEscapeName ¶
PgEscapeName escapes strings which will be usaed for Podsdtgres object identifiers (table names, column names, schema names)
func PgEscapeSearchPath ¶
PgEscapeSearchPath applies postgres escaping to search path and remove whitespace
func PgEscapeString ¶
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 ClientMap ¶
type ClientMap struct {
// contains filtered or unexported fields
}
func NewClientMap ¶
func NewClientMap() *ClientMap
func (*ClientMap) Add ¶
func (e *ClientMap) Add(client *DbClient, searchPathConfig backend.SearchPathConfig) *ClientMap
func (*ClientMap) Get ¶
func (e *ClientMap) Get(connectionString string, searchPathConfig backend.SearchPathConfig) *DbClient
Get returns an existing db client for the given connection string if no client is stored for the string, it returns null
func (*ClientMap) GetOrCreate ¶
func (e *ClientMap) GetOrCreate(ctx context.Context, connectionString string, searchPathConfig backend.SearchPathConfig) (*DbClient, error)
GetOrCreate returns a db client for the given connection string if clients map already contains a client for this connection string, use that otherwise create a new client and add to the map
type ClientMapOption ¶
type ClientMapOption func(*ClientMap)
type DbClient ¶
type DbClient struct { // the Backend Backend backend.Backend // contains filtered or unexported fields }
DbClient wraps over `sql.DB` and gives an interface to the database
func NewDbClient ¶
func (*DbClient) Execute ¶
func (c *DbClient) Execute(ctx context.Context, query string, args ...any) (*localqueryresult.Result, error)
Execute executes 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)
ExecuteSync executes a query against this client and wait for the result
func (*DbClient) GetConnectionString ¶
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