Documentation
¶
Index ¶
- func GetDatabaseConfigForResource(resource modconfig.ModTreeItem, workspaceMod *modconfig.Mod, ...) (connection.ConnectionStringProvider, backend.SearchPathConfig, error)
- func GetDefaultDatabaseConfig(mod *modconfig.Mod) (connection.ConnectionStringProvider, backend.SearchPathConfig, error)
- func GetPipesWorkspaceConnectionString(workspace string) (connection.ConnectionStringProvider, 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
- type PgxConnector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDatabaseConfigForResource ¶
func GetDatabaseConfigForResource(resource modconfig.ModTreeItem, workspaceMod *modconfig.Mod, defaultDatabase connection.ConnectionStringProvider, defaultSearchPathConfig backend.SearchPathConfig) (connection.ConnectionStringProvider, backend.SearchPathConfig, error)
GetDatabaseConfigForResource returns the ConnectionStringProvider and searchPathConfig for a resource if no database is set, use the default database, likewise for search path
func GetDefaultDatabaseConfig ¶
func GetDefaultDatabaseConfig(mod *modconfig.Mod) (connection.ConnectionStringProvider, backend.SearchPathConfig, error)
GetDefaultDatabaseConfig returns the default ConnectionStringProvider and searchPathConfig NOTE: if the dashboardUI has overridden the search path, opts wil be passed in to set the overridden value
func GetPipesWorkspaceConnectionString ¶ added in v1.2.0
func GetPipesWorkspaceConnectionString(workspace string) (connection.ConnectionStringProvider, error)
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
}
ClientMap provides thread-safe storage and management of database client connections. It caches clients to avoid creating new connections for each query, using composite cache keys generated from connection string, search path config, and database filters.
func NewClientMap ¶
func NewClientMap() *ClientMap
NewClientMap creates a new ClientMap instance with an empty clients map for storing database connections.
func (*ClientMap) Add ¶
func (e *ClientMap) Add(client *DbClient, searchPathConfig backend.SearchPathConfig) *ClientMap
Add stores a database client in the map using the provided configuration. Generates a composite cache key from connection string, search path, and filters. The filter parameter may be nil. Returns the ClientMap for method chaining.
func (*ClientMap) Close ¶
Close closes all database clients and removes them from the map for cleanup.
func (*ClientMap) Get ¶
func (e *ClientMap) Get(connectionString string, searchPathConfig backend.SearchPathConfig) *DbClient
Get retrieves an existing database client from the map based on configuration. Generates a composite cache key to lookup the client. The filter parameter may be nil. Returns nil if no matching client is found.
func (*ClientMap) GetOrCreate ¶
func (e *ClientMap) GetOrCreate(ctx context.Context, connectionString string, searchPathConfig backend.SearchPathConfig) (*DbClient, error)
GetOrCreate retrieves an existing client or creates a new one if it doesn't exist. Generates a composite cache key for lookup and uses double-checked locking to prevent race conditions during concurrent access. The filter parameter may be nil.
type ClientMapOption ¶
type ClientMapOption func(*ClientMap)
ClientMapOption defines a function type for configuring ClientMap options
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