ezg

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Q

type Q[t any] struct {
	// contains filtered or unexported fields
}

Q represents a generalized struct wrapper that is used for CRUD operations on any gorm.Model.

func W

func W[t any](obj *t) Q[t]

W is a short form for Wrap. It wraps the model with general purpose functions.

func (Q[t]) Count

func (q Q[t]) Count(db *gorm.DB) (uint64, error)

Count counts the number of rows in the database that match the model. If the model implements a custom Count method, it will be used instead.

func (Q[t]) CountSql

func (q Q[t]) CountSql(db *gorm.DB, sql string, sqlArgs ...interface{}) (uint64, error)

CountSql counts the number of rows in the database that match the custom SQL query and arguments. If the model implements a custom CountSql method, it will be used instead.

func (Q[t]) Delete

func (q Q[t]) Delete(db *gorm.DB) error

Delete deletes the underlying model object from the database using GORM. If the model implements a custom Delete method, it will be used instead. If the model does not use gorm.Model while not implementing custom model method, it will return an error.

func (Q[t]) Find

func (q Q[t]) Find(db *gorm.DB) ([]t, error)

Find retrieves all instances of the underlying model from the database using GORM. If the model implements a custom Find method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) FindOne

func (q Q[t]) FindOne(db *gorm.DB) (*t, error)

FindOne retrieves a single instance of the underlying model from the database using GORM. If the model implements a custom FindOne method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return nil model and nil error.

func (Q[t]) FindOneSql

func (q Q[t]) FindOneSql(db *gorm.DB, sql string, sqlArgs ...interface{}) (*t, error)

FindOneSql retrieves a single instance of the underlying model from the database using GORM, using a custom SQL query. If the model implements a custom FindOneSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return nil model and nil error.

func (Q[t]) FindPaginated

func (q Q[t]) FindPaginated(db *gorm.DB, offset *uint64, limit *uint64, reverseOrder bool) ([]t, error)

FindPaginated retrieves a slice of models from the database with pagination parameters (limit and offset). If the model implements a custom FindPaginated method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) FindPaginatedSql

func (q Q[t]) FindPaginatedSql(db *gorm.DB, offset *uint64, limit *uint64, reverseOrder bool, sql string, sqlArgs ...interface{}) ([]t, error)

FindPaginatedSql retrieves a slice of models from the database with pagination, optional reverse ordering, and with custom WHERE SQL. If the model implements a custom FindPaginatedSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) FindSql

func (q Q[t]) FindSql(db *gorm.DB, sql string, sqlArgs ...interface{}) ([]t, error)

FindSql retrieves all instances of the underlying model from the database using GORM, using a custom SQL query. If the model implements a custom FindSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) Insert

func (q Q[t]) Insert(db *gorm.DB) error

Insert inserts the underlying model object into the database using GORM. If the model implements a custom Insert method, it will be used instead.

func (Q[t]) Join

func (q Q[t]) Join(db *gorm.DB, table, condition string) (*t, error)

Join retrieves a single instance of the underlying model from the database using GORM, with a join on another table using a custom condition. Instead of using gorm.ErrRecordNotFound it will return nil model and nil error.

func (Q[t]) M

func (q Q[t]) M() *t

M is a short form for Model. It returns the underlying model.

func (Q[t]) ShallowFind

func (q Q[t]) ShallowFind(db *gorm.DB) ([]t, error)

ShallowFind retrieves all instances of the underlying model from the database using GORM, without preloading any associations. If the model implements a custom Find method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) ShallowFindOne

func (q Q[t]) ShallowFindOne(db *gorm.DB) (*t, error)

ShallowFindOne retrieves a single instance of the underlying model from the database using GORM, without preloading any associations. If the model implements a custom FindOne method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return nil model and nil error.

func (Q[t]) ShallowFindOneSql

func (q Q[t]) ShallowFindOneSql(db *gorm.DB, sql string, sqlArgs ...interface{}) (*t, error)

ShallowFindOneSql retrieves a single instance of the underlying model from the database using GORM, using a custom SQL query and without preloading any associations. If the model implements a custom FindOneSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return nil model and nil error.

func (Q[t]) ShallowFindPaginated

func (q Q[t]) ShallowFindPaginated(db *gorm.DB, offset *uint64, limit *uint64, reverseOrder bool) ([]t, error)

ShallowFindPaginated retrieves a slice of models from the database with pagination parameters (limit and offset), without preloading. If the model implements a custom FindPaginated method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) ShallowFindPaginatedSql

func (q Q[t]) ShallowFindPaginatedSql(db *gorm.DB, offset *uint64, limit *uint64, reverseOrder bool, sql string, sqlArgs ...interface{}) ([]t, error)

ShallowFindPaginatedSql retrieves a slice of models from the database with pagination, optional reverse ordering, without preloading and with custom WHERE SQL. If the model implements a custom FindPaginatedSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) ShallowFindSql

func (q Q[t]) ShallowFindSql(db *gorm.DB, sql string, sqlArgs ...interface{}) ([]t, error)

ShallowFindSql retrieves all instances of the underlying model from the database using GORM, using a custom SQL query and without preloading any associations. If the model implements a custom FindSql method, it will be used instead. Instead of using gorm.ErrRecordNotFound it will return empty slice and nil error.

func (Q[t]) Update

func (q Q[t]) Update(db *gorm.DB) error

Update updates the underlying model object in the database using GORM. If the model implements a custom Update method, it will be used instead.

Jump to

Keyboard shortcuts

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