model

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delete

type Delete[T any] struct {
	// contains filtered or unexported fields
}

func (*Delete[T]) Delete added in v0.2.1

func (d *Delete[T]) Delete() error

func (*Delete[T]) Where

func (d *Delete[T]) Where(query interface{}, args ...interface{}) *Delete[T]

type EntryModel

type EntryModel[T IEntry] struct {
	// contains filtered or unexported fields
}

func NewEntryModel

func NewEntryModel[T IEntry](db *db.DB, tableName string) *EntryModel[T]

func (*EntryModel[T]) CreateTable

func (a *EntryModel[T]) CreateTable() error

func (*EntryModel[T]) CreateWithPk added in v0.1.4

func (a *EntryModel[T]) CreateWithPk(entry T, keyName string, kind reflect.Kind) (any, error)

CreateWithPk creates a record and returns the generated primary key

func (*EntryModel[T]) Delete

func (a *EntryModel[T]) Delete() *Delete[T]

func (*EntryModel[T]) DeleteById added in v0.1.3

func (a *EntryModel[T]) DeleteById(id uint) error

func (*EntryModel[T]) DeleteTable

func (a *EntryModel[T]) DeleteTable() error

func (*EntryModel[T]) FindAll

func (a *EntryModel[T]) FindAll() ([]T, error)

func (*EntryModel[T]) FindAllByIds

func (a *EntryModel[T]) FindAllByIds(id ...uint) ([]T, error)

func (*EntryModel[T]) FindAllByIdsWithPreload added in v0.5.1

func (a *EntryModel[T]) FindAllByIdsWithPreload(ids []uint, preloads ...string) ([]T, error)

FindAllByIdsWithPreload finds all records by IDs with preloaded associations Usage: model.FindAllByIdsWithPreload([]uint{1, 2, 3}, "Profile", "Role")

func (*EntryModel[T]) FindAllWithPreload added in v0.5.1

func (a *EntryModel[T]) FindAllWithPreload(preloads ...string) ([]T, error)

FindAllWithPreload finds all records with preloaded associations Usage: model.FindAllWithPreload("Profile", "Role")

func (*EntryModel[T]) FindById

func (a *EntryModel[T]) FindById(id uint) (T, error)

func (*EntryModel[T]) FindByIdWithPreload added in v0.5.1

func (a *EntryModel[T]) FindByIdWithPreload(id uint, preloads ...string) (T, error)

FindByIdWithPreload finds a record by ID with preloaded associations Usage: model.FindByIdWithPreload(id, "Profile", "Role")

func (*EntryModel[T]) FindOne

func (a *EntryModel[T]) FindOne(query interface{}, args ...interface{}) (T, error)

func (*EntryModel[T]) FindOneWithPreload added in v0.5.1

func (a *EntryModel[T]) FindOneWithPreload(query interface{}, args []interface{}, preloads ...string) (T, error)

FindOneWithPreload finds one record with preloaded associations Usage: model.FindOneWithPreload("status = ?", 1, "Profile", "Role")

func (*EntryModel[T]) GetTableName

func (a *EntryModel[T]) GetTableName() string

func (*EntryModel[T]) IsExist

func (a *EntryModel[T]) IsExist() (bool, error)

func (*EntryModel[T]) NewEntryModel

func (a *EntryModel[T]) NewEntryModel(db *db.DB) *EntryModel[T]

func (*EntryModel[T]) Page

func (a *EntryModel[T]) Page(page *web.Page) ([]T, int, error)

func (*EntryModel[T]) PageForWeb added in v0.1.3

func (a *EntryModel[T]) PageForWeb(page *web.Page) (*web.PageAble[T], error)

func (*EntryModel[T]) Query

func (a *EntryModel[T]) Query() *Query[T]

func (*EntryModel[T]) QueryPage

func (a *EntryModel[T]) QueryPage(page *web.Page, query interface{}, args ...interface{}) ([]T, int, error)

func (*EntryModel[T]) Save

func (a *EntryModel[T]) Save(t T) error

func (*EntryModel[T]) SaveForMap added in v0.1.4

func (a *EntryModel[T]) SaveForMap(mapValue map[string]interface{}) error

func (*EntryModel[T]) SaveForMapWithPk added in v0.1.4

func (a *EntryModel[T]) SaveForMapWithPk(mapValue map[string]interface{}, keyName string) (any, error)

SaveForMapWithPk saves a record from a map and returns the generated primary key

func (*EntryModel[T]) SaveForMapWithUintPk added in v0.1.4

func (a *EntryModel[T]) SaveForMapWithUintPk(mapValue map[string]interface{}, keyName string) (uint, error)

func (*EntryModel[T]) Saves

func (a *EntryModel[T]) Saves(ts []T) error

func (*EntryModel[T]) SavesForMap added in v0.1.4

func (a *EntryModel[T]) SavesForMap(mapValues []map[string]interface{}) error

func (*EntryModel[T]) Update

func (a *EntryModel[T]) Update() *Update[T]

func (*EntryModel[T]) UpdateById

func (a *EntryModel[T]) UpdateById(t T) error

func (*EntryModel[T]) UpdateColumn

func (a *EntryModel[T]) UpdateColumn(id uint, column string, value interface{}) error

func (*EntryModel[T]) UpdateForMap

func (a *EntryModel[T]) UpdateForMap(id uint, data map[string]interface{}) error

type IEntry

type IEntry interface {
	SetCreateTime(createTime time.Time)
	SetUpdateTime(updateTIme time.Time)
	GetId() uint
	SetId(id uint)
}

type Model

type Model[T any] struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel[T any](db *db.DB, tableName string) *Model[T]

func (*Model[T]) CreateTable

func (a *Model[T]) CreateTable() error

func (*Model[T]) CreateWithPk added in v0.1.4

func (a *Model[T]) CreateWithPk(entry T, keyName string, kind reflect.Kind) (any, error)

CreateWithPk creates a record and returns the generated primary key

func (*Model[T]) Delete

func (a *Model[T]) Delete() *Delete[T]

func (*Model[T]) DeleteTable

func (a *Model[T]) DeleteTable() error

func (*Model[T]) GetTableName

func (a *Model[T]) GetTableName() string

func (*Model[T]) IsExist

func (a *Model[T]) IsExist() (bool, error)

func (*Model[T]) Query

func (a *Model[T]) Query() *Query[T]

func (*Model[T]) Save

func (a *Model[T]) Save(entry T) error

func (*Model[T]) SaveForMap added in v0.1.4

func (a *Model[T]) SaveForMap(mapValue map[string]any) error

func (*Model[T]) SaveForMapWithPk added in v0.1.4

func (a *Model[T]) SaveForMapWithPk(mapValue map[string]any, keyName string) (any, error)

SaveForMapWithPk saves a record from a map and returns the generated primary key

func (*Model[T]) SaveForMapWithUintPk added in v0.1.4

func (a *Model[T]) SaveForMapWithUintPk(mapValue map[string]any, keyName string) (uint, error)

func (*Model[T]) Saves

func (a *Model[T]) Saves(entry []T) error

func (*Model[T]) SavesForMap added in v0.1.4

func (a *Model[T]) SavesForMap(mapValues []map[string]any) error

func (*Model[T]) Update

func (a *Model[T]) Update() *Update[T]

type Page

type Page[T any] struct {
	Total int `json:"total"`
	List  []T `json:"list"`
}

func ToPage

func ToPage[T IEntry](total int, list []T) *Page[T]

type Query

type Query[T any] struct {
	// contains filtered or unexported fields
}

func (*Query[T]) All

func (q *Query[T]) All() ([]T, error)

func (*Query[T]) Count added in v0.1.3

func (q *Query[T]) Count() (int, error)

func (*Query[T]) Exec added in v0.5.1

func (q *Query[T]) Exec(sql string, args ...interface{}) ([]T, error)

func (*Query[T]) ExecPage added in v0.5.1

func (q *Query[T]) ExecPage(page *web.Page, sql string, args ...interface{}) ([]T, int, error)

func (*Query[T]) Joins added in v0.5.1

func (q *Query[T]) Joins(query string) *Query[T]

Joins adds a join clause for association loading (GORM join support) Usage: query.Joins("Profile").All()

func (*Query[T]) List

func (q *Query[T]) List(size int) ([]T, error)

func (*Query[T]) ListPage

func (q *Query[T]) ListPage(page *web.Page) ([]T, error)

func (*Query[T]) One

func (q *Query[T]) One() (T, error)

func (*Query[T]) Order

func (q *Query[T]) Order(query interface{}) *Query[T]

func (*Query[T]) Page

func (q *Query[T]) Page(page *web.Page) ([]T, int, error)

func (*Query[T]) PageForWeb added in v0.1.3

func (q *Query[T]) PageForWeb(page *web.Page) (*web.PageAble[T], error)

func (*Query[T]) Preload added in v0.5.1

func (q *Query[T]) Preload(query string) *Query[T]

Preload adds a preload clause for eager loading associations (GORM foreign key support) Usage: query.Preload("Profile").Preload("Role").All() Supports nested preloading: query.Preload("Profile.Addresses")

func (*Query[T]) Size

func (q *Query[T]) Size(size int) ([]T, int, error)

func (*Query[T]) Where

func (q *Query[T]) Where(query interface{}, args ...interface{}) *Query[T]

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(db *db.DB) *Transaction

func (*Transaction) Exec

func (t *Transaction) Exec(fc func(tx *db.DB) error) error

type Update

type Update[T any] struct {
	// contains filtered or unexported fields
}

func (*Update[T]) Set added in v0.2.1

func (u *Update[T]) Set(s string, value any) *UpdateSet

func (*Update[T]) Update added in v0.2.1

func (u *Update[T]) Update(t T) error

func (*Update[T]) UpdateColumn added in v0.2.1

func (u *Update[T]) UpdateColumn(column string, value any) error

func (*Update[T]) UpdateForMap added in v0.2.1

func (u *Update[T]) UpdateForMap(mapValue map[string]any) error

func (*Update[T]) Where

func (u *Update[T]) Where(query interface{}, args ...interface{}) *Update[T]

type UpdateSet added in v0.1.3

type UpdateSet struct {
	// contains filtered or unexported fields
}

func (*UpdateSet) Exec added in v0.1.3

func (w *UpdateSet) Exec() error

func (*UpdateSet) Set added in v0.1.3

func (w *UpdateSet) Set(s string, value any) *UpdateSet

Jump to

Keyboard shortcuts

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