regorm

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 10 Imported by: 1

README

regorm

A wrapper for gorm that make it easier to use

Documentation

Index

Constants

View Source
const (
	ISOperator    = "IS"
	ISNOTOperator = "IS NOT"
	EQOperator    = "="
	GTOperator    = ">"
	GTEOperator   = ">="
	LTOperator    = "<"
	LTEOperator   = "<="
	INOperator    = "IN"
	LikeOperator  = " LIKE "
	BetWeen       = " BETWEEN "
	NOTOperator   = " NOT "
	OROperator    = " OR "
	ANDOperator   = " AND "
	ASCOperator   = " ASC"
	DESCOperator  = " DESC"
)

Variables

View Source
var (
	// ErrRecordNotFound record not found error.
	ErrRecordNotFound = gorm.ErrRecordNotFound
	// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`.
	ErrInvalidTransaction = gorm.ErrInvalidTransaction
	// ErrNotImplemented not implemented.
	ErrNotImplemented = gorm.ErrNotImplemented
	// ErrMissingWhereClause missing where clause.
	ErrMissingWhereClause = gorm.ErrMissingWhereClause
	// ErrUnsupportedRelation unsupported relations.
	ErrUnsupportedRelation = gorm.ErrUnsupportedRelation
	// ErrPrimaryKeyRequired primary keys required.
	ErrPrimaryKeyRequired = gorm.ErrPrimaryKeyRequired
	// ErrModelValueRequired model value required.
	ErrModelValueRequired = gorm.ErrModelValueRequired
	// ErrModelAccessibleFieldsRequired model accessible fields required.
	ErrModelAccessibleFieldsRequired = gorm.ErrModelAccessibleFieldsRequired
	// ErrSubQueryRequired sub query required.
	ErrSubQueryRequired = gorm.ErrSubQueryRequired
	// ErrInvalidData unsupported data.
	ErrInvalidData = gorm.ErrInvalidData
	// ErrUnsupportedDriver unsupported driver.
	ErrUnsupportedDriver = gorm.ErrUnsupportedDriver
	// ErrRegistered registered.
	ErrRegistered = gorm.ErrRegistered
	// ErrInvalidField invalid field.
	ErrInvalidField = gorm.ErrInvalidField
	// ErrEmptySlice empty slice found.
	ErrEmptySlice = gorm.ErrEmptySlice
	// ErrDryRunModeUnsupported dry run mode unsupported.
	ErrDryRunModeUnsupported = gorm.ErrDryRunModeUnsupported
	// ErrInvalidDB invalid db.
	ErrInvalidDB = gorm.ErrInvalidDB
	// ErrInvalidValue invalid value.
	ErrInvalidValue = gorm.ErrInvalidValue
	// ErrInvalidValueOfLength invalid values do not match length.
	ErrInvalidValueOfLength = gorm.ErrInvalidValueOfLength
	// ErrPreloadNotAllowed preload is not allowed when count is used.
	ErrPreloadNotAllowed = gorm.ErrPreloadNotAllowed
	// ErrDuplicatedKey occurs when there is a unique key constraint violation.
	ErrDuplicatedKey = gorm.ErrDuplicatedKey
)

Functions

func Connection

func Connection() (*sql.DB, error)

func Init

func Init(gormdb *gorm.DB)

Types

type Builer

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

type Clause

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

func Between

func Between(field string, value any) *Clause

func EQ

func EQ(field string, value any) *Clause

func GT

func GT(field string, value any) *Clause

func GTE

func GTE(field string, value any) *Clause

func IN

func IN(field string, values any) *Clause

NOTE: Because of golang limition in array of any([]any) IN function used any type for values parameter instead of []any, developers must call IN function with array of any.

func IsNotNull added in v0.6.0

func IsNotNull(field string) *Clause

func IsNull added in v0.6.0

func IsNull(field string) *Clause

func LT

func LT(field string, value any) *Clause

func LTE

func LTE(field string, value any) *Clause

func Like

func Like(field, value string) *Clause

func NOT

func NOT() *Clause
func Search(fields []string, value, operator string) *Clause

func (*Clause) AND

func (w *Clause) AND() *Clause

func (*Clause) Between

func (w *Clause) Between(field string, value any) *Clause

func (*Clause) EQ

func (w *Clause) EQ(field string, value any) *Clause

func (*Clause) GT

func (w *Clause) GT(field string, value any) *Clause

func (*Clause) GTE

func (w *Clause) GTE(field string, value any) *Clause

func (*Clause) IN

func (w *Clause) IN(field string, values any) *Clause

NOTE: Because of golang limition in array of any([]any) IN function used any type for values parameter instead of []any, developers must call IN function with array of any.

func (*Clause) IsNotNull added in v0.6.0

func (w *Clause) IsNotNull(field string) *Clause

func (*Clause) IsNull added in v0.6.0

func (w *Clause) IsNull(field string) *Clause

func (*Clause) LT

func (w *Clause) LT(field string, value any) *Clause

func (*Clause) LTE

func (w *Clause) LTE(field string, value any) *Clause

func (*Clause) Like

func (w *Clause) Like(field, value string) *Clause

func (*Clause) NOT

func (w *Clause) NOT() *Clause

func (*Clause) OR

func (w *Clause) OR() *Clause

func (*Clause) Search

func (w *Clause) Search(fields []string, value, operator string) *Clause

type ConflictResovler added in v0.2.0

type ConflictResovler[E entity] interface {
	OnConflict(clause clause.OnConflict) Repository[E]
}

type QueryConsumer

type QueryConsumer[E entity] interface {
	Find(ctx context.Context) ([]E, error)
	One(ctx context.Context) (E, error)
	Count(ctx context.Context) (int64, error)
	Exists(ctx context.Context) (bool, error)

	Insert(ctx context.Context, entity E) error
	Save(ctx context.Context, entity E) (rowsAffected int64, err error)
	InsertBatch(ctx context.Context, entities []E) (rowsAffected int64, err error)
	Update(ctx context.Context, entity E) (rowsAffected int64, err error)
	Delete(ctx context.Context) (rowsAffected int64, err error)

	InsertTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
	SaveTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
	InsertBatchTx(ctx context.Context, entities []E) (tx Transaction, rowsAffected int64, err error)
	UpdateTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
	// rowsAffected param can be nil
	DeleteTx(ctx context.Context) (tx Transaction, rowsAffected int64, err error)
}

type QueryMaker

type QueryMaker[E entity] interface {
	Where(whereClause *Clause) Repository[E]
	Having(whereClause *Clause) Repository[E]
	Select(cols ...string) Repository[E]
	Offset(value int) Repository[E]
	Limit(value int) Repository[E]
	OrderBy(name string, desc bool) Repository[E]
	GroupBy(name string) Repository[E]
	Args() []any
	IsMany() Repository[E]
	Join(ent entity) Repository[E]
}

type RawExecutor

type RawExecutor[E entity] interface {
	Query(sql string, values ...any) error
	QueryRows(sql string, values ...any) ([]E, error)
	Exec(sql string, values ...any) error
}

type Repository added in v0.11.0

type Repository[E entity] interface {
	QueryMaker[E]
	QueryConsumer[E]
	RawExecutor[E]
	ConflictResovler[E]

	SetTx(tx Transaction, commit bool) Repository[E]
}

func NewRepository added in v0.11.0

func NewRepository[E entity](ent E) Repository[E]

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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