Documentation
¶
Index ¶
- Variables
- func Begin() (*sql.Tx, error)
- func ClearTx()
- func Close() error
- func Connection(name string) (drivers.Driver, error)
- func CreateMany[T any](records []T) error
- func DB() *sql.DB
- func Exec(query string, args ...any) (sql.Result, error)
- func Fresh() error
- func GetDatabaseName() string
- func GetDriver() string
- func GetTx() *sql.Tx
- func Hash(password string) string
- func Init(driverName string, config map[string]any) error
- func InitFromEnv() error
- func Migrate() error
- func Ping() error
- func Raw(query string, args ...any) *sql.Rows
- func RegisterDriver(name string, factory func() drivers.Driver)
- func Rollback(steps int) error
- func Save[T any](model *T) error
- func Seed(seeders ...string) error
- func SetConnMaxIdleTime(d time.Duration)
- func SetConnMaxLifetime(d time.Duration)
- func SetConnection(name string, driver drivers.Driver)
- func SetEventDispatcher(fn func(event interface{}) error)
- func SetMaxIdleConns(n int)
- func SetMaxOpenConns(n int)
- func SetTx(tx *sql.Tx)
- func Stats() sql.DBStats
- func Transaction(fn func() error) error
- type AfterCreateHook
- type AfterDeleteHook
- type AfterUpdateHook
- type BeforeCreateHook
- type BeforeDeleteHook
- type BeforeUpdateHook
- type Model
- func (Model[T]) All() ([]T, error)
- func (Model[T]) Count() (int, error)
- func (Model[T]) Create(data any) (*T, error)
- func (Model[T]) CreateMany(records []T) error
- func (m *Model[T]) Delete() error
- func (Model[T]) DeleteWhere(conditions map[string]any) (int64, error)
- func (Model[T]) Exists() bool
- func (Model[T]) Find(id any) (*T, error)
- func (Model[T]) FindBy(field string, value any) (*T, error)
- func (Model[T]) First() (*T, error)
- func (m *Model[T]) GetChanges() map[string]any
- func (m *Model[T]) HasChanged(field string) bool
- func (m *Model[T]) IsClean() bool
- func (m *Model[T]) IsDirty() bool
- func (Model[T]) Last() (*T, error)
- func (Model[T]) OrderBy(column, direction string) *Query[T]
- func (Model[T]) Pluck(column string) ([]any, error)
- func (Model[T]) Raw(sql string, args ...any) *RawQuery[T]
- func (m *Model[T]) Refresh() error
- func (m *Model[T]) Save() error
- func (Model[T]) Update(conditions map[string]any, updates map[string]any) (int64, error)
- func (Model[T]) Where(condition string, args ...any) *Query[T]
- func (Model[T]) WhereIn(field string, values []any) *Query[T]
- func (Model[T]) WhereNotNull(field string) *Query[T]
- func (Model[T]) WhereNull(field string) *Query[T]
- func (Model[T]) With(relations ...string) *Query[T]
- type Query
- func (q *Query[T]) Chunk(size int, callback func([]T) error) error
- func (q *Query[T]) Count() (int, error)
- func (q *Query[T]) Delete() (int64, error)
- func (q *Query[T]) Distinct() *Query[T]
- func (q *Query[T]) Exists() bool
- func (q *Query[T]) Find(id any, dest *T) error
- func (q *Query[T]) First(dest *T) error
- func (q *Query[T]) ForceDelete() (int64, error)
- func (q *Query[T]) Get() ([]T, error)
- func (q *Query[T]) GroupBy(columns ...string) *Query[T]
- func (q *Query[T]) Having(condition string, args ...any) *Query[T]
- func (q *Query[T]) InsertGetId(data map[string]any) (int64, error)
- func (q *Query[T]) Join(table, first, operator, second string) *Query[T]
- func (q *Query[T]) LeftJoin(table, first, operator, second string) *Query[T]
- func (q *Query[T]) Limit(n int) *Query[T]
- func (q *Query[T]) LockForUpdate() *Query[T]
- func (q *Query[T]) Offset(n int) *Query[T]
- func (q *Query[T]) OnlyTrashed() *Query[T]
- func (q *Query[T]) OrWhere(condition string, args ...any) *Query[T]
- func (q *Query[T]) OrderBy(column, direction string) *Query[T]
- func (q *Query[T]) OrderByDesc(column string) *Query[T]
- func (q *Query[T]) Pluck(column string) ([]any, error)
- func (q *Query[T]) RightJoin(table, first, operator, second string) *Query[T]
- func (q *Query[T]) Select(columns ...string) *Query[T]
- func (q *Query[T]) SkipLocked() *Query[T]
- func (q *Query[T]) ToSQL() (string, []any)
- func (q *Query[T]) Update(updates map[string]any) (int64, error)
- func (q *Query[T]) Where(condition string, args ...any) *Query[T]
- func (q *Query[T]) WhereBetween(field string, start, end any) *Query[T]
- func (q *Query[T]) WhereIn(field string, values []any) *Query[T]
- func (q *Query[T]) WhereNotIn(field string, values []any) *Query[T]
- func (q *Query[T]) WhereNotNull(field string) *Query[T]
- func (q *Query[T]) WhereNull(field string) *Query[T]
- func (q *Query[T]) With(relations ...string) *Query[T]
- func (q *Query[T]) WithContext(ctx context.Context) *Query[T]
- func (q *Query[T]) WithTrashed() *Query[T]
- type QueryExecuted
- type QueryExecutor
- type RawQuery
- type SoftDeleteModel
- func (SoftDeleteModel[T]) All() ([]T, error)
- func (SoftDeleteModel[T]) Count() (int, error)
- func (SoftDeleteModel[T]) Create(data any) (*T, error)
- func (SoftDeleteModel[T]) CreateMany(records []T) error
- func (m *SoftDeleteModel[T]) Delete() error
- func (SoftDeleteModel[T]) DeleteWhere(conditions map[string]any) (int64, error)
- func (SoftDeleteModel[T]) Exists() bool
- func (SoftDeleteModel[T]) Find(id any) (*T, error)
- func (SoftDeleteModel[T]) FindBy(field string, value any) (*T, error)
- func (SoftDeleteModel[T]) First() (*T, error)
- func (m *SoftDeleteModel[T]) ForceDelete() error
- func (SoftDeleteModel[T]) ForceDeleteWhere(conditions map[string]any) (int64, error)
- func (m *SoftDeleteModel[T]) GetChanges() map[string]any
- func (m *SoftDeleteModel[T]) HasChanged(field string) bool
- func (m *SoftDeleteModel[T]) IsClean() bool
- func (m *SoftDeleteModel[T]) IsDirty() bool
- func (SoftDeleteModel[T]) Last() (*T, error)
- func (SoftDeleteModel[T]) OnlyTrashed() *Query[T]
- func (SoftDeleteModel[T]) OrderBy(column, direction string) *Query[T]
- func (SoftDeleteModel[T]) Pluck(column string) ([]any, error)
- func (SoftDeleteModel[T]) Raw(sql string, args ...any) *RawQuery[T]
- func (m *SoftDeleteModel[T]) Refresh() error
- func (m *SoftDeleteModel[T]) Restore() error
- func (m *SoftDeleteModel[T]) Save() error
- func (SoftDeleteModel[T]) Update(conditions map[string]any, updates map[string]any) (int64, error)
- func (SoftDeleteModel[T]) Where(condition string, args ...any) *Query[T]
- func (SoftDeleteModel[T]) WhereIn(field string, values []any) *Query[T]
- func (SoftDeleteModel[T]) WhereNotNull(field string) *Query[T]
- func (SoftDeleteModel[T]) WhereNull(field string) *Query[T]
- func (SoftDeleteModel[T]) With(relations ...string) *Query[T]
- func (SoftDeleteModel[T]) WithTrashed() *Query[T]
- type SoftDeleteUUIDModel
- func (SoftDeleteUUIDModel[T]) All() ([]T, error)
- func (SoftDeleteUUIDModel[T]) Count() (int, error)
- func (SoftDeleteUUIDModel[T]) Create(data any) (*T, error)
- func (SoftDeleteUUIDModel[T]) CreateMany(records []T) error
- func (m *SoftDeleteUUIDModel[T]) Delete() error
- func (SoftDeleteUUIDModel[T]) DeleteWhere(conditions map[string]any) (int64, error)
- func (SoftDeleteUUIDModel[T]) Exists() bool
- func (SoftDeleteUUIDModel[T]) Find(id string) (*T, error)
- func (SoftDeleteUUIDModel[T]) FindBy(field string, value any) (*T, error)
- func (SoftDeleteUUIDModel[T]) First() (*T, error)
- func (m *SoftDeleteUUIDModel[T]) ForceDelete() error
- func (SoftDeleteUUIDModel[T]) ForceDeleteWhere(conditions map[string]any) (int64, error)
- func (m *SoftDeleteUUIDModel[T]) GetChanges() map[string]any
- func (m *SoftDeleteUUIDModel[T]) HasChanged(field string) bool
- func (m *SoftDeleteUUIDModel[T]) IsClean() bool
- func (m *SoftDeleteUUIDModel[T]) IsDirty() bool
- func (SoftDeleteUUIDModel[T]) Last() (*T, error)
- func (SoftDeleteUUIDModel[T]) OnlyTrashed() *Query[T]
- func (SoftDeleteUUIDModel[T]) OrderBy(column, direction string) *Query[T]
- func (SoftDeleteUUIDModel[T]) Pluck(column string) ([]any, error)
- func (SoftDeleteUUIDModel[T]) Raw(sql string, args ...any) *RawQuery[T]
- func (m *SoftDeleteUUIDModel[T]) Refresh() error
- func (m *SoftDeleteUUIDModel[T]) Restore() error
- func (m *SoftDeleteUUIDModel[T]) Save() error
- func (SoftDeleteUUIDModel[T]) Update(conditions map[string]any, updates map[string]any) (int64, error)
- func (SoftDeleteUUIDModel[T]) Where(condition string, args ...any) *Query[T]
- func (SoftDeleteUUIDModel[T]) WhereIn(field string, values []any) *Query[T]
- func (SoftDeleteUUIDModel[T]) WhereNotNull(field string) *Query[T]
- func (SoftDeleteUUIDModel[T]) WhereNull(field string) *Query[T]
- func (SoftDeleteUUIDModel[T]) With(relations ...string) *Query[T]
- func (SoftDeleteUUIDModel[T]) WithTrashed() *Query[T]
- type UUIDModel
- func (UUIDModel[T]) All() ([]T, error)
- func (UUIDModel[T]) Count() (int, error)
- func (UUIDModel[T]) Create(data any) (*T, error)
- func (UUIDModel[T]) CreateMany(records []T) error
- func (m *UUIDModel[T]) Delete() error
- func (UUIDModel[T]) DeleteWhere(conditions map[string]any) (int64, error)
- func (UUIDModel[T]) Exists() bool
- func (UUIDModel[T]) Find(id string) (*T, error)
- func (UUIDModel[T]) FindBy(field string, value any) (*T, error)
- func (UUIDModel[T]) First() (*T, error)
- func (m *UUIDModel[T]) GetChanges() map[string]any
- func (m *UUIDModel[T]) HasChanged(field string) bool
- func (m *UUIDModel[T]) IsClean() bool
- func (m *UUIDModel[T]) IsDirty() bool
- func (UUIDModel[T]) Last() (*T, error)
- func (UUIDModel[T]) OrderBy(column, direction string) *Query[T]
- func (UUIDModel[T]) Pluck(column string) ([]any, error)
- func (UUIDModel[T]) Raw(sql string, args ...any) *RawQuery[T]
- func (m *UUIDModel[T]) Refresh() error
- func (m *UUIDModel[T]) Save() error
- func (UUIDModel[T]) Update(conditions map[string]any, updates map[string]any) (int64, error)
- func (UUIDModel[T]) Where(condition string, args ...any) *Query[T]
- func (UUIDModel[T]) WhereIn(field string, values []any) *Query[T]
- func (UUIDModel[T]) WhereNotNull(field string) *Query[T]
- func (UUIDModel[T]) WhereNull(field string) *Query[T]
- func (UUIDModel[T]) With(relations ...string) *Query[T]
Constants ¶
This section is empty.
Variables ¶
var ( ErrRecordNotFound = sql.ErrNoRows ErrInvalidSQL = errors.New("invalid SQL query") ErrConnection = errors.New("database connection error") ErrTransaction = errors.New("transaction error") )
Common errors
Functions ¶
func Connection ¶
Connection returns a named database connection
func CreateMany ¶
func GetDatabaseName ¶
func GetDatabaseName() string
GetDatabaseName returns the name of the current database
func InitFromEnv ¶
func InitFromEnv() error
InitFromEnv manually initializes the ORM from environment variables
func Migrate ¶
func Migrate() error
Migrate runs database migrations This is a placeholder - actual implementation should use pkg/orm/migrate package Example: migrator := migrate.NewMigrator(orm.DB(), orm.GetDriver()); migrator.Up()
func RegisterDriver ¶
RegisterDriver registers a new database driver
func Rollback ¶
Rollback rolls back migrations This is a placeholder - actual implementation should use pkg/orm/migrate package Example: migrator := migrate.NewMigrator(orm.DB(), orm.GetDriver()); migrator.Down(steps)
func SetConnMaxIdleTime ¶
SetConnMaxIdleTime sets the maximum idle time of connections
func SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum lifetime of connections
func SetConnection ¶
SetConnection sets a named database connection
func SetEventDispatcher ¶ added in v0.4.0
func SetEventDispatcher(fn func(event interface{}) error)
SetEventDispatcher sets the function used to dispatch events. This is called by the events package to wire up event dispatching.
func SetMaxIdleConns ¶
func SetMaxIdleConns(n int)
SetMaxIdleConns sets the maximum number of idle connections
func SetMaxOpenConns ¶
func SetMaxOpenConns(n int)
SetMaxOpenConns sets the maximum number of open connections
func SetTx ¶ added in v0.7.0
SetTx sets a test transaction for RefreshDatabase pattern All queries will use this transaction until ClearTx is called
func Transaction ¶
Transaction executes a function within a database transaction
Types ¶
type AfterCreateHook ¶
type AfterCreateHook interface {
AfterCreate() error
}
type AfterDeleteHook ¶
type AfterDeleteHook interface {
AfterDelete() error
}
type AfterUpdateHook ¶
type AfterUpdateHook interface {
AfterUpdate() error
}
type BeforeCreateHook ¶
type BeforeCreateHook interface {
BeforeCreate() error
}
type BeforeDeleteHook ¶
type BeforeDeleteHook interface {
BeforeDelete() error
}
type BeforeUpdateHook ¶
type BeforeUpdateHook interface {
BeforeUpdate() error
}
type Model ¶
type Model[T any] struct { ID uint `orm:"primaryKey;autoIncrement" json:"id"` CreatedAt time.Time `orm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `orm:"autoUpdateTime" json:"updated_at"` // Internal fields (not persisted) IsExisting bool `orm:"-" json:"-"` Original map[string]any `orm:"-" json:"-"` Changed map[string]bool `orm:"-" json:"-"` }
Model is the generic base model that provides Laravel-style static methods. By default, models do NOT have soft deletes. Use SoftDeleteModel for soft delete support.
func (Model[T]) CreateMany ¶
CreateMany inserts multiple records
func (Model[T]) DeleteWhere ¶
DeleteWhere permanently deletes records matching conditions
func (*Model[T]) GetChanges ¶
GetChanges returns all changed fields
func (*Model[T]) HasChanged ¶
HasChanged checks if a field has changed
func (Model[T]) Raw ¶ added in v0.8.0
Raw creates a raw SQL query builder for executing custom queries Usage: Model{}.Raw("SELECT * FROM users WHERE id = ?", 1).First(&user)
func (Model[T]) WhereNotNull ¶ added in v0.8.0
WhereNotNull starts a query with a WHERE IS NOT NULL condition
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query represents a chainable query builder with generics
func (*Query[T]) Delete ¶
Delete soft deletes matching records (if model supports soft deletes) or hard deletes
func (*Query[T]) ForceDelete ¶
ForceDelete permanently deletes matching records
func (*Query[T]) InsertGetId ¶
InsertGetId inserts a record and returns the ID
func (*Query[T]) LockForUpdate ¶
LockForUpdate adds FOR UPDATE clause for pessimistic locking
func (*Query[T]) OnlyTrashed ¶
OnlyTrashed queries only soft deleted records
func (*Query[T]) OrderByDesc ¶
OrderByDesc adds an ORDER BY DESC clause
func (*Query[T]) SkipLocked ¶
SkipLocked adds SKIP LOCKED clause to skip locked rows
func (*Query[T]) WhereBetween ¶
WhereBetween adds a WHERE BETWEEN condition
func (*Query[T]) WhereNotIn ¶
WhereNotIn adds a WHERE NOT IN condition
func (*Query[T]) WhereNotNull ¶
WhereNotNull adds a WHERE IS NOT NULL condition
func (*Query[T]) WithContext ¶ added in v0.4.0
WithContext sets the context for the query (for event propagation)
func (*Query[T]) WithTrashed ¶
WithTrashed includes soft deleted records
type QueryExecuted ¶ added in v0.4.0
type QueryExecuted struct {
Context context.Context
SQL string
Bindings []any
Duration time.Duration
RowsAffected int64
Connection string // Database connection/driver name
File string // Caller file
Line int // Caller line
TraceID string // APM trace ID
SpanID string // APM span ID
ParentID string // Parent span ID for correlation
}
QueryExecuted is dispatched when a database query completes
func (*QueryExecuted) Name ¶ added in v0.4.0
func (e *QueryExecuted) Name() string
Name returns the event name
type QueryExecutor ¶ added in v0.7.0
type QueryExecutor interface {
Exec(query string, args ...any) (sql.Result, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryRow(query string, args ...any) *sql.Row
}
QueryExecutor interface for *sql.DB and *sql.Tx
func Executor ¶ added in v0.7.0
func Executor() QueryExecutor
Executor returns the current query executor (transaction if set, otherwise DB)
type RawQuery ¶ added in v0.8.0
type RawQuery[T any] struct { // contains filtered or unexported fields }
RawQuery represents a raw SQL query that can be executed with First() or Get()
func NewRawQuery ¶ added in v0.8.0
NewRawQuery creates a new raw query builder
func (*RawQuery[T]) Exec ¶ added in v0.8.0
Exec executes a raw SQL statement (INSERT, UPDATE, DELETE) and returns affected rows
func (*RawQuery[T]) First ¶ added in v0.8.0
First executes the raw query and scans the first result into dest
func (*RawQuery[T]) Get ¶ added in v0.8.0
Get executes the raw query and returns all matching results
type SoftDeleteModel ¶ added in v0.8.0
type SoftDeleteModel[T any] struct { ID uint `orm:"primaryKey;autoIncrement" json:"id"` CreatedAt time.Time `orm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `orm:"autoUpdateTime" json:"updated_at"` DeletedAt *time.Time `orm:"index" json:"deleted_at,omitempty"` // Internal fields (not persisted) IsExisting bool `orm:"-" json:"-"` Original map[string]any `orm:"-" json:"-"` Changed map[string]bool `orm:"-" json:"-"` }
SoftDeleteModel is a base model WITH soft delete support. Use this when you need to keep deleted records (e.g., users, orders, audit trails).
func (SoftDeleteModel[T]) All ¶ added in v0.8.0
func (SoftDeleteModel[T]) All() ([]T, error)
All retrieves all records
func (SoftDeleteModel[T]) Count ¶ added in v0.8.0
func (SoftDeleteModel[T]) Count() (int, error)
Count returns the number of records
func (SoftDeleteModel[T]) Create ¶ added in v0.8.0
func (SoftDeleteModel[T]) Create(data any) (*T, error)
Create inserts a new record
func (SoftDeleteModel[T]) CreateMany ¶ added in v0.8.0
func (SoftDeleteModel[T]) CreateMany(records []T) error
CreateMany inserts multiple records
func (*SoftDeleteModel[T]) Delete ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) Delete() error
Delete soft deletes the model
func (SoftDeleteModel[T]) DeleteWhere ¶ added in v0.8.0
func (SoftDeleteModel[T]) DeleteWhere(conditions map[string]any) (int64, error)
DeleteWhere soft deletes records matching conditions
func (SoftDeleteModel[T]) Exists ¶ added in v0.8.0
func (SoftDeleteModel[T]) Exists() bool
Exists checks if any records exist
func (SoftDeleteModel[T]) Find ¶ added in v0.8.0
func (SoftDeleteModel[T]) Find(id any) (*T, error)
Find retrieves a record by primary key
func (SoftDeleteModel[T]) FindBy ¶ added in v0.8.0
func (SoftDeleteModel[T]) FindBy(field string, value any) (*T, error)
FindBy retrieves a record by a specific field
func (SoftDeleteModel[T]) First ¶ added in v0.8.0
func (SoftDeleteModel[T]) First() (*T, error)
First retrieves the first record
func (*SoftDeleteModel[T]) ForceDelete ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) ForceDelete() error
ForceDelete permanently deletes the model
func (SoftDeleteModel[T]) ForceDeleteWhere ¶ added in v0.8.0
func (SoftDeleteModel[T]) ForceDeleteWhere(conditions map[string]any) (int64, error)
ForceDeleteWhere permanently deletes records matching conditions
func (*SoftDeleteModel[T]) GetChanges ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) GetChanges() map[string]any
GetChanges returns all changed fields
func (*SoftDeleteModel[T]) HasChanged ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) HasChanged(field string) bool
HasChanged checks if a field has changed
func (*SoftDeleteModel[T]) IsClean ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) IsClean() bool
IsClean checks if the model has no unsaved changes
func (*SoftDeleteModel[T]) IsDirty ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) IsDirty() bool
IsDirty checks if the model has any unsaved changes
func (SoftDeleteModel[T]) Last ¶ added in v0.8.0
func (SoftDeleteModel[T]) Last() (*T, error)
Last retrieves the last record
func (SoftDeleteModel[T]) OnlyTrashed ¶ added in v0.8.0
func (SoftDeleteModel[T]) OnlyTrashed() *Query[T]
OnlyTrashed retrieves only soft deleted records
func (SoftDeleteModel[T]) OrderBy ¶ added in v0.8.0
func (SoftDeleteModel[T]) OrderBy(column, direction string) *Query[T]
OrderBy starts a query with an ORDER BY clause
func (SoftDeleteModel[T]) Pluck ¶ added in v0.8.0
func (SoftDeleteModel[T]) Pluck(column string) ([]any, error)
Pluck retrieves a single column values
func (SoftDeleteModel[T]) Raw ¶ added in v0.8.0
func (SoftDeleteModel[T]) Raw(sql string, args ...any) *RawQuery[T]
Raw creates a raw SQL query builder for executing custom queries Usage: SoftDeleteModel{}.Raw("SELECT * FROM users WHERE id = ?", 1).First(&user)
func (*SoftDeleteModel[T]) Refresh ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) Refresh() error
Refresh reloads the model from database
func (*SoftDeleteModel[T]) Restore ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) Restore() error
Restore restores a soft deleted model
func (*SoftDeleteModel[T]) Save ¶ added in v0.8.0
func (m *SoftDeleteModel[T]) Save() error
Save inserts or updates the model
func (SoftDeleteModel[T]) Where ¶ added in v0.8.0
func (SoftDeleteModel[T]) Where(condition string, args ...any) *Query[T]
Where starts a query with a WHERE condition
func (SoftDeleteModel[T]) WhereIn ¶ added in v0.8.0
func (SoftDeleteModel[T]) WhereIn(field string, values []any) *Query[T]
WhereIn queries for records where field is in the given values
func (SoftDeleteModel[T]) WhereNotNull ¶ added in v0.8.0
func (SoftDeleteModel[T]) WhereNotNull(field string) *Query[T]
WhereNotNull starts a query with a WHERE IS NOT NULL condition
func (SoftDeleteModel[T]) WhereNull ¶ added in v0.8.0
func (SoftDeleteModel[T]) WhereNull(field string) *Query[T]
WhereNull starts a query with a WHERE IS NULL condition
func (SoftDeleteModel[T]) With ¶ added in v0.8.0
func (SoftDeleteModel[T]) With(relations ...string) *Query[T]
With eager loads relationships
func (SoftDeleteModel[T]) WithTrashed ¶ added in v0.8.0
func (SoftDeleteModel[T]) WithTrashed() *Query[T]
WithTrashed includes soft deleted records
type SoftDeleteUUIDModel ¶ added in v0.8.0
type SoftDeleteUUIDModel[T any] struct { ID string `orm:"primaryKey;type:uuid" json:"id"` CreatedAt time.Time `orm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `orm:"autoUpdateTime" json:"updated_at"` DeletedAt *time.Time `orm:"index" json:"deleted_at,omitempty"` // Internal fields (not persisted) IsExisting bool `orm:"-" json:"-"` Original map[string]any `orm:"-" json:"-"` Changed map[string]bool `orm:"-" json:"-"` }
SoftDeleteUUIDModel is a UUID primary key model WITH soft delete support.
func (SoftDeleteUUIDModel[T]) All ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) All() ([]T, error)
All retrieves all records
func (SoftDeleteUUIDModel[T]) Count ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Count() (int, error)
Count returns the number of records
func (SoftDeleteUUIDModel[T]) Create ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Create(data any) (*T, error)
Create inserts a new record
func (SoftDeleteUUIDModel[T]) CreateMany ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) CreateMany(records []T) error
CreateMany inserts multiple records
func (*SoftDeleteUUIDModel[T]) Delete ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) Delete() error
Delete soft deletes the model
func (SoftDeleteUUIDModel[T]) DeleteWhere ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) DeleteWhere(conditions map[string]any) (int64, error)
DeleteWhere soft deletes records matching conditions
func (SoftDeleteUUIDModel[T]) Exists ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Exists() bool
Exists checks if any records exist
func (SoftDeleteUUIDModel[T]) Find ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Find(id string) (*T, error)
Find retrieves a record by UUID primary key
func (SoftDeleteUUIDModel[T]) FindBy ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) FindBy(field string, value any) (*T, error)
FindBy retrieves a record by a specific field
func (SoftDeleteUUIDModel[T]) First ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) First() (*T, error)
First retrieves the first record
func (*SoftDeleteUUIDModel[T]) ForceDelete ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) ForceDelete() error
ForceDelete permanently deletes the model
func (SoftDeleteUUIDModel[T]) ForceDeleteWhere ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) ForceDeleteWhere(conditions map[string]any) (int64, error)
ForceDeleteWhere permanently deletes records matching conditions
func (*SoftDeleteUUIDModel[T]) GetChanges ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) GetChanges() map[string]any
GetChanges returns all changed fields
func (*SoftDeleteUUIDModel[T]) HasChanged ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) HasChanged(field string) bool
HasChanged checks if a field has changed
func (*SoftDeleteUUIDModel[T]) IsClean ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) IsClean() bool
IsClean checks if the model has no unsaved changes
func (*SoftDeleteUUIDModel[T]) IsDirty ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) IsDirty() bool
IsDirty checks if the model has any unsaved changes
func (SoftDeleteUUIDModel[T]) Last ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Last() (*T, error)
Last retrieves the last record (by created_at descending)
func (SoftDeleteUUIDModel[T]) OnlyTrashed ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) OnlyTrashed() *Query[T]
OnlyTrashed retrieves only soft deleted records
func (SoftDeleteUUIDModel[T]) OrderBy ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) OrderBy(column, direction string) *Query[T]
OrderBy starts a query with an ORDER BY clause
func (SoftDeleteUUIDModel[T]) Pluck ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Pluck(column string) ([]any, error)
Pluck retrieves a single column values
func (SoftDeleteUUIDModel[T]) Raw ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Raw(sql string, args ...any) *RawQuery[T]
Raw creates a raw SQL query builder for executing custom queries Usage: SoftDeleteUUIDModel{}.Raw("SELECT * FROM users WHERE id = ?", 1).First(&user)
func (*SoftDeleteUUIDModel[T]) Refresh ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) Refresh() error
Refresh reloads the model from database
func (*SoftDeleteUUIDModel[T]) Restore ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) Restore() error
Restore restores a soft deleted model
func (*SoftDeleteUUIDModel[T]) Save ¶ added in v0.8.0
func (m *SoftDeleteUUIDModel[T]) Save() error
Save inserts or updates the model
func (SoftDeleteUUIDModel[T]) Update ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Update(conditions map[string]any, updates map[string]any) (int64, error)
Update updates records matching conditions
func (SoftDeleteUUIDModel[T]) Where ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) Where(condition string, args ...any) *Query[T]
Where starts a query with a WHERE condition
func (SoftDeleteUUIDModel[T]) WhereIn ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) WhereIn(field string, values []any) *Query[T]
WhereIn queries for records where field is in the given values
func (SoftDeleteUUIDModel[T]) WhereNotNull ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) WhereNotNull(field string) *Query[T]
WhereNotNull starts a query with a WHERE IS NOT NULL condition
func (SoftDeleteUUIDModel[T]) WhereNull ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) WhereNull(field string) *Query[T]
WhereNull starts a query with a WHERE IS NULL condition
func (SoftDeleteUUIDModel[T]) With ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) With(relations ...string) *Query[T]
With eager loads relationships
func (SoftDeleteUUIDModel[T]) WithTrashed ¶ added in v0.8.0
func (SoftDeleteUUIDModel[T]) WithTrashed() *Query[T]
WithTrashed includes soft deleted records
type UUIDModel ¶ added in v0.8.0
type UUIDModel[T any] struct { ID string `orm:"primaryKey;type:uuid" json:"id"` CreatedAt time.Time `orm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `orm:"autoUpdateTime" json:"updated_at"` // Internal fields (not persisted) IsExisting bool `orm:"-" json:"-"` Original map[string]any `orm:"-" json:"-"` Changed map[string]bool `orm:"-" json:"-"` }
UUIDModel is a generic base model with UUID primary key for distributed systems and external-facing APIs where sequential IDs pose security risks. By default, models do NOT have soft deletes. Use SoftDeleteUUIDModel for soft delete support.
func (UUIDModel[T]) CreateMany ¶ added in v0.8.0
CreateMany inserts multiple records
func (UUIDModel[T]) DeleteWhere ¶ added in v0.8.0
DeleteWhere permanently deletes records matching conditions
func (*UUIDModel[T]) GetChanges ¶ added in v0.8.0
GetChanges returns all changed fields
func (*UUIDModel[T]) HasChanged ¶ added in v0.8.0
HasChanged checks if a field has changed
func (UUIDModel[T]) Last ¶ added in v0.8.0
Last retrieves the last record (by created_at descending)
func (UUIDModel[T]) Raw ¶ added in v0.8.0
Raw creates a raw SQL query builder for executing custom queries Usage: UUIDModel{}.Raw("SELECT * FROM users WHERE id = ?", 1).First(&user)
func (UUIDModel[T]) WhereIn ¶ added in v0.8.0
WhereIn queries for records where field is in the given values
func (UUIDModel[T]) WhereNotNull ¶ added in v0.8.0
WhereNotNull starts a query with a WHERE IS NOT NULL condition