database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGormDBFromPool

func NewGormDBFromPool(ctx context.Context, pool *pgxpool.Pool) (*gorm.DB, error)

NewGormDBFromPool creates a GORM handle from the existing pgx pool configuration.

func QualifiedTable

func QualifiedTable(schemaName, tableName string) (string, error)

QualifiedTable returns a schema-qualified table reference safe for interpolation.

func QuoteIdentifier

func QuoteIdentifier(identifier string) (string, error)

QuoteIdentifier safely quotes a validated SQL identifier.

func TenantTable

func TenantTable(db *gorm.DB, schemaName, tableName string) (*gorm.DB, error)

TenantTable returns a GORM handle bound to an explicit schema-qualified table.

func ValidateIdentifier

func ValidateIdentifier(identifier string) error

ValidateIdentifier ensures a schema/table identifier is safe to interpolate.

Types

type Decimal

type Decimal struct {
	decimal.Decimal
}

Decimal wraps shopspring/decimal for GORM compatibility It implements the necessary interfaces for database scanning and value conversion

func DecimalZero

func DecimalZero() Decimal

Zero returns a zero-value Decimal

func NewDecimal

func NewDecimal(d decimal.Decimal) Decimal

NewDecimal creates a new Decimal from a shopspring decimal

func NewDecimalFromFloat

func NewDecimalFromFloat(f float64) Decimal

NewDecimalFromFloat creates a new Decimal from a float64

func NewDecimalFromString

func NewDecimalFromString(s string) (Decimal, error)

NewDecimalFromString creates a new Decimal from a string

func (Decimal) GormDBDataType

func (Decimal) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns the database data type based on dialect

func (Decimal) GormDataType

func (Decimal) GormDataType() string

GormDataType returns the GORM data type for this field

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Decimal) Scan

func (d *Decimal) Scan(value interface{}) error

Scan implements sql.Scanner interface

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (Decimal) Value

func (d Decimal) Value() (driver.Value, error)

Value implements driver.Valuer interface

type GormDB

type GormDB struct {
	*gorm.DB
}

GormDB wraps gorm.DB and provides multi-tenant support

func NewGormDB

func NewGormDB(ctx context.Context, connString string) (*GormDB, error)

NewGormDB creates a new GORM database connection from a connection string

func (*GormDB) Close

func (g *GormDB) Close() error

Close closes the database connection

func (*GormDB) Transaction

func (g *GormDB) Transaction(ctx context.Context, fn func(tx *gorm.DB) error) error

Transaction executes a function within a database transaction

func (*GormDB) WithContext

func (g *GormDB) WithContext(ctx context.Context) *gorm.DB

WithContext returns a new DB with context

type JSONB

type JSONB map[string]interface{}

JSONB represents a PostgreSQL JSONB column

func (JSONB) GormDBDataType

func (JSONB) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns the database data type based on dialect

func (JSONB) GormDataType

func (JSONB) GormDataType() string

GormDataType returns the GORM data type for this field

func (*JSONB) Scan

func (j *JSONB) Scan(value interface{}) error

Scan implements sql.Scanner interface

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

Value implements driver.Valuer interface

type JSONBRaw

type JSONBRaw json.RawMessage

JSONBRaw represents a raw JSONB column that preserves the original JSON

func (JSONBRaw) GormDBDataType

func (JSONBRaw) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns the database data type based on dialect

func (JSONBRaw) GormDataType

func (JSONBRaw) GormDataType() string

GormDataType returns the GORM data type for this field

func (JSONBRaw) MarshalJSON

func (j JSONBRaw) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*JSONBRaw) Scan

func (j *JSONBRaw) Scan(value interface{}) error

Scan implements sql.Scanner interface

func (*JSONBRaw) UnmarshalJSON

func (j *JSONBRaw) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (JSONBRaw) Value

func (j JSONBRaw) Value() (driver.Value, error)

Value implements driver.Valuer interface

Jump to

Keyboard shortcuts

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