dbschema

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySchema

func ApplySchema(ctx context.Context, db *bun.DB, schemaName string) error

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

func GetTableName(schemaName, tableName string) string

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

func SetupConnectionHook(schemaName string) bun.QueryHook

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

func ValidateSchemaName(schema string) error

ValidateSchemaName validates that the schema name is a safe SQL identifier This prevents SQL injection in schema names

func WrapConnection

func WrapConnection(ctx context.Context, db *bun.DB, schemaName string) (*bun.DB, error)

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

Jump to

Keyboard shortcuts

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