Documentation
¶
Index ¶
- func ApplySchema(ctx context.Context, db *bun.DB, schemaName string) error
- func GetTableName(schemaName, tableName string) string
- func SetupConnectionHook(schemaName string) bun.QueryHook
- func ValidateSchemaName(schema string) error
- func WrapConnection(ctx context.Context, db *bun.DB, schemaName string) (*bun.DB, error)
- type SchemaConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySchema ¶
ApplySchema sets up the database to use the specified schema This does two things: 1. Creates the schema if it doesn't exist 2. Sets the PostgreSQL search_path to prioritize the schema
func GetTableName ¶
GetTableName returns the fully qualified table name with schema prefix This is useful when you need to explicitly reference a table in a specific schema
func SetupConnectionHook ¶
SetupConnectionHook creates a Bun query hook that sets the search_path for each connection This ensures that all queries use the correct schema, even in connection pools
func ValidateSchemaName ¶
ValidateSchemaName validates that the schema name is a safe SQL identifier This prevents SQL injection in schema names
func WrapConnection ¶
WrapConnection wraps a bun.DB connection to automatically apply schema for all operations Returns a new DB connection with the search_path set Note: This only affects the current connection. For connection pools, you should call ApplySchema in a connection hook
Types ¶
type SchemaConfig ¶
type SchemaConfig struct {
// SchemaName is the PostgreSQL schema to use
// Empty string means use database default (typically "public")
SchemaName string
}
SchemaConfig holds schema configuration