Documentation
¶
Index ¶
- func WithNestedTransaction(db *gorm.DB, fn TransactionFunc) error
- func WithNestedTransactionContext(ctx context.Context, db *gorm.DB, fn TransactionFunc) error
- func WithTransaction(db *gorm.DB, fn TransactionFunc) error
- func WithTransactionContext(ctx context.Context, db *gorm.DB, fn TransactionFunc) error
- type BaseModel
- type DBManager
- type GormConfig
- type ID
- type JSONB
- type JSONBArray
- type NullableUUID
- type SoftDelete
- type Timestamp
- type TransactionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithNestedTransaction ¶
func WithNestedTransaction(db *gorm.DB, fn TransactionFunc) error
WithNestedTransaction handles nested transactions using savepoints
func WithNestedTransactionContext ¶
WithNestedTransactionContext handles nested transactions using savepoints with context
func WithTransaction ¶
func WithTransaction(db *gorm.DB, fn TransactionFunc) error
WithTransaction executes a function within a database transaction
func WithTransactionContext ¶
WithTransactionContext executes a function within a database transaction with context
Types ¶
type BaseModel ¶
type BaseModel struct {
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
CreatedAt time.Time `gorm:"index;not null" json:"createdAt"`
UpdatedAt time.Time `gorm:"index;not null" json:"updatedAt"`
DeletedAt *time.Time `gorm:"index" json:"deletedAt,omitempty"`
}
BaseModel provides common fields for all models
func (*BaseModel) BeforeCreate ¶
BeforeCreate hook to ensure ID is set
type DBManager ¶
DBManager wraps gorm.DB and provides additional functionality
func OpenGorm ¶
func OpenGorm(c GormConfig, automigrateModels ...interface{}) (*DBManager, error)
type GormConfig ¶
type GormConfig struct {
Host string
User string
Password string
Name string
Port string
SSLMode string
Timezone string
MaxIdleConns int
MaxOpenConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
TranslateErrors bool
LogLevel logger.LogLevel
SlowThreshold time.Duration
IgnoreRecordNotFoundError bool
}
type JSONB ¶
JSONB represents a PostgreSQL JSONB column
type JSONBArray ¶
type JSONBArray []any
JSONBArray represents a PostgreSQL JSONB array
func (*JSONBArray) Scan ¶
func (j *JSONBArray) Scan(value any) error
Scan implements the sql.Scanner interface
type NullableUUID ¶
NullableUUID provides a nullable UUID type
func (*NullableUUID) Scan ¶
func (nu *NullableUUID) Scan(value interface{}) error
Scan implements the Scanner interface
type SoftDelete ¶
SoftDelete provides soft delete functionality
func (SoftDelete) IsDeleted ¶
func (s SoftDelete) IsDeleted() bool
IsDeleted checks if the model is soft deleted
type Timestamp ¶
type Timestamp struct {
CreatedAt time.Time `gorm:"index;not null" json:"createdAt"`
UpdatedAt time.Time `gorm:"index;not null" json:"updatedAt"`
}
Timestamp provides creation and update timestamps
type TransactionFunc ¶
TransactionFunc defines the function signature for transaction operations