Documentation
¶
Index ¶
- Constants
- func GetConstraintName(err error) string
- func IsCheckViolation(err error) bool
- func IsForeignKeyViolation(err error) bool
- func IsUniqueViolation(err error) bool
- type ColumnInfo
- type Connection
- func (c *Connection) BeginTx(ctx context.Context) (pgx.Tx, error)
- func (c *Connection) Close()
- func (c *Connection) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
- func (c *Connection) Health(ctx context.Context) error
- func (c *Connection) Inspector() *SchemaInspector
- func (c *Connection) Migrate() error
- func (c *Connection) Pool() *pgxpool.Pool
- func (c *Connection) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (c *Connection) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- func (c *Connection) Stats() *pgxpool.Stat
- type ForeignKey
- type FunctionInfo
- type FunctionParam
- type IndexInfo
- type SchemaInspector
- func (si *SchemaInspector) BuildRESTPath(table TableInfo) string
- func (si *SchemaInspector) GetAllFunctions(ctx context.Context, schemas ...string) ([]FunctionInfo, error)
- func (si *SchemaInspector) GetAllTables(ctx context.Context, schemas ...string) ([]TableInfo, error)
- func (si *SchemaInspector) GetAllViews(ctx context.Context, schemas ...string) ([]TableInfo, error)
- func (si *SchemaInspector) GetSchemas(ctx context.Context) ([]string, error)
- func (si *SchemaInspector) GetTableInfo(ctx context.Context, schema, table string) (*TableInfo, error)
- type TableInfo
Constants ¶
const ( // ErrCodeUniqueViolation is the PostgreSQL error code for unique constraint violations ErrCodeUniqueViolation = "23505" // ErrCodeForeignKeyViolation is the PostgreSQL error code for foreign key violations ErrCodeForeignKeyViolation = "23503" // ErrCodeCheckViolation is the PostgreSQL error code for check constraint violations ErrCodeCheckViolation = "23514" )
PostgreSQL error codes
Variables ¶
This section is empty.
Functions ¶
func GetConstraintName ¶
GetConstraintName returns the constraint name from a PostgreSQL error
func IsCheckViolation ¶
IsCheckViolation checks if an error is a check constraint violation
func IsForeignKeyViolation ¶
IsForeignKeyViolation checks if an error is a foreign key violation
func IsUniqueViolation ¶
IsUniqueViolation checks if an error is a unique constraint violation
Types ¶
type ColumnInfo ¶
type ColumnInfo struct {
Name string `json:"name"`
DataType string `json:"data_type"`
IsNullable bool `json:"is_nullable"`
DefaultValue *string `json:"default_value"`
IsPrimaryKey bool `json:"is_primary_key"`
IsForeignKey bool `json:"is_foreign_key"`
IsUnique bool `json:"is_unique"`
MaxLength *int `json:"max_length"`
Position int `json:"position"`
}
ColumnInfo represents metadata about a table column
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a database connection pool
func NewConnection ¶
func NewConnection(cfg config.DatabaseConfig) (*Connection, error)
NewConnection creates a new database connection pool
func (*Connection) Exec ¶
func (c *Connection) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
Exec executes a query that doesn't return rows
func (*Connection) Health ¶
func (c *Connection) Health(ctx context.Context) error
Health checks the health of the database connection
func (*Connection) Inspector ¶
func (c *Connection) Inspector() *SchemaInspector
Inspector returns the schema inspector
func (*Connection) Migrate ¶
func (c *Connection) Migrate() error
Migrate runs database migrations from both system and user sources
func (*Connection) Pool ¶
func (c *Connection) Pool() *pgxpool.Pool
Pool returns the underlying connection pool
func (*Connection) Stats ¶
func (c *Connection) Stats() *pgxpool.Stat
Stats returns database connection pool statistics
type ForeignKey ¶
type ForeignKey struct {
Name string `json:"name"`
ColumnName string `json:"column_name"`
ReferencedTable string `json:"referenced_table"`
ReferencedColumn string `json:"referenced_column"`
OnDelete string `json:"on_delete"`
OnUpdate string `json:"on_update"`
}
ForeignKey represents a foreign key relationship
type FunctionInfo ¶
type FunctionInfo struct {
Schema string `json:"schema"`
Name string `json:"name"`
Description string `json:"description"`
Parameters []FunctionParam `json:"parameters"`
ReturnType string `json:"return_type"`
IsSetOf bool `json:"is_set_of"`
Volatility string `json:"volatility"` // VOLATILE, STABLE, IMMUTABLE
Language string `json:"language"`
}
FunctionInfo represents metadata about a database function
type FunctionParam ¶
type FunctionParam struct {
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"` // IN, OUT, INOUT
HasDefault bool `json:"has_default"`
Position int `json:"position"`
}
FunctionParam represents a function parameter
type IndexInfo ¶
type IndexInfo struct {
Name string `json:"name"`
Columns []string `json:"columns"`
IsUnique bool `json:"is_unique"`
IsPrimary bool `json:"is_primary"`
}
IndexInfo represents an index on a table
type SchemaInspector ¶
type SchemaInspector struct {
// contains filtered or unexported fields
}
SchemaInspector provides PostgreSQL schema introspection capabilities
func NewSchemaInspector ¶
func NewSchemaInspector(conn *Connection) *SchemaInspector
NewSchemaInspector creates a new schema inspector
func (*SchemaInspector) BuildRESTPath ¶
func (si *SchemaInspector) BuildRESTPath(table TableInfo) string
BuildRESTPath builds a REST API path for a table
func (*SchemaInspector) GetAllFunctions ¶
func (si *SchemaInspector) GetAllFunctions(ctx context.Context, schemas ...string) ([]FunctionInfo, error)
GetAllFunctions retrieves information about all functions in the specified schemas
func (*SchemaInspector) GetAllTables ¶
func (si *SchemaInspector) GetAllTables(ctx context.Context, schemas ...string) ([]TableInfo, error)
GetAllTables retrieves information about all tables in the specified schemas
func (*SchemaInspector) GetAllViews ¶
GetAllViews retrieves information about all views in the specified schemas
func (*SchemaInspector) GetSchemas ¶
func (si *SchemaInspector) GetSchemas(ctx context.Context) ([]string, error)
GetSchemas retrieves all available schemas
func (*SchemaInspector) GetTableInfo ¶
func (si *SchemaInspector) GetTableInfo(ctx context.Context, schema, table string) (*TableInfo, error)
GetTableInfo retrieves detailed information about a specific table
type TableInfo ¶
type TableInfo struct {
Schema string `json:"schema"`
Name string `json:"name"`
RESTPath string `json:"rest_path,omitempty"` // The REST API path for this table (e.g., "/auth/users")
Columns []ColumnInfo `json:"columns"`
PrimaryKey []string `json:"primary_key"`
ForeignKeys []ForeignKey `json:"foreign_keys"`
Indexes []IndexInfo `json:"indexes"`
RLSEnabled bool `json:"rls_enabled"`
}
TableInfo represents metadata about a database table