Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
func NewPostgresqlConnection ¶
func NewPostgresqlConnection(readWriteConfiguration *ConnectionConfiguration, readOnlyConfiguration *ConnectionConfiguration) (Connection, error)
type ConnectionConfiguration ¶
type JSONB ¶
JSONB is a custom type for handling JSONB fields in PostgreSQL It implements sql.Scanner and driver.Valuer interfaces for automatic JSON marshaling/unmarshaling with GORM
func (JSONB) GormDataType ¶
GormDataType tells GORM what SQL data type to use for this field
func (JSONB) MarshalJSON ¶
MarshalJSON implements json.Marshaler for JSONB This ensures JSONB serializes as a nested JSON object rather than base64-encoded bytes
func (*JSONB) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for JSONB This allows JSONB to be deserialized from nested JSON objects
type JSONBG ¶
type JSONBG[T any] struct { V T }
JSONBG is a generic JSONB wrapper that unmarshals into the concrete type parameter T. It implements sql.Scanner and driver.Valuer, and also json.Marshaler/json.Unmarshaler so it can be used seamlessly with GORM and HTTP JSON payloads.
Example:
type MyCfg struct { Enabled bool `json:"enabled"` }
type Model struct { Cfg JSONBG[MyCfg] `gorm:"type:jsonb"` }
In the database this is stored as jsonb, and when scanning it will populate MyCfg. When marshaling to JSON (e.g. API responses), it serializes the inner value of type T.
Note: The zero value contains the zero value of T. If T is a pointer type, the zero value will be nil and NULL may be written to DB. If you want an empty object `{}` instead, use a non-pointer struct type for T.
This type avoids map[string]any when a strongly-typed struct is desired.
func (*JSONBG[T]) GormDataType ¶
GormDataType tells GORM what SQL data type to use for this field
func (*JSONBG[T]) MarshalJSON ¶
MarshalJSON delegates to the inner value.
func (*JSONBG[T]) Scan ¶
Scan implements sql.Scanner: it unmarshals the DB value into the inner value.
func (*JSONBG[T]) UnmarshalJSON ¶
UnmarshalJSON delegates to the inner value.
type PostgresqlConnection ¶
type PostgresqlConnection struct {
ReadWriteConfiguration *ConnectionConfiguration
ReadOnlyConfiguration *ConnectionConfiguration
// contains filtered or unexported fields
}
func (*PostgresqlConnection) Db ¶
func (p *PostgresqlConnection) Db() *gorm.DB
func (*PostgresqlConnection) DbRo ¶
func (p *PostgresqlConnection) DbRo() *gorm.DB
func (*PostgresqlConnection) Initialize ¶
func (p *PostgresqlConnection) Initialize() error
type Repository ¶
type Repository interface {
Initialize(connection Connection) error
}