gorm

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 4 Imported by: 1

README

Metadiv GORM

Installation

go get -u github.com/METADIV-GO/gorm

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GORM_ENCRYPT_KEY = os.Getenv("GORM_ENCRYPT_KEY")
)

Functions

func Count

func Count[T any](tx *gorm.DB, cls *Clause) (int64, error)

Count counts the number of records from the database.

func Delete

func Delete[T any](tx *gorm.DB, record *T) error

Delete deletes a record from the database.

func DeleteAll

func DeleteAll[T any](tx *gorm.DB, records []T) error

DeleteAll deletes all records from the database.

func DeleteBy

func DeleteBy[T any](tx *gorm.DB, cls *Clause) error

DeleteBy deletes records from the database by a clause.

func FindAll

func FindAll[T any](tx *gorm.DB, cls *Clause) ([]T, error)

FindAll finds all records from the database.

func FindOne

func FindOne[T any](tx *gorm.DB, cls *Clause) (*T, error)

FindOne finds one record from the database.

func Save

func Save[T any](tx *gorm.DB, record *T) (*T, error)

Save saves a record to the database.

func SaveAll

func SaveAll[T any](tx *gorm.DB, records []T) ([]T, error)

SaveAll saves all records to the database.

Types

type Clause

type Clause struct {
	Field     string    `json:"field"`
	Operator  string    `json:"operator"`
	Value     any       `json:"value"`
	Encrypted bool      `json:"encrypted"`
	Children  []*Clause `json:"children"`
}

func And

func And(children ...*Clause) *Clause

And creates a new clause with operator `AND`.

func Between

func Between(field string, from, to any, includeEdgeTo ...bool) *Clause

Between creates a new clause that checks if a field is between two values.

func DecryptEq

func DecryptEq(field string, value any) *Clause

DecryptEq creates a new clause with operator `=` and the value decrypted.

func DecryptIn

func DecryptIn(field string, value ...any) *Clause

DecryptIn creates a new clause with operator `IN` and the values decrypted. Please only use on string values.

func DecryptLike

func DecryptLike(field string, value any) *Clause

DecryptLike creates a new clause with operator `LIKE` and the value decrypted.

func DecryptNeq

func DecryptNeq(field string, value any) *Clause

DecryptNeq creates a new clause with operator `<>` and the value decrypted.

func DecryptNotIn

func DecryptNotIn(field string, value ...any) *Clause

DecryptNotIn creates a new clause with operator `NOT IN` and the values decrypted. Please only use on string values.

func DecryptNotLike

func DecryptNotLike(field string, value any) *Clause

DecryptNotLike creates a new clause with operator `NOT LIKE` and the value decrypted.

func DecryptNotSimilar

func DecryptNotSimilar(field string, value any) *Clause

DecryptNotSimilar creates a new clause with operator "NOT LIKE" and the value "%value%" decrypted.

func DecryptSimilar

func DecryptSimilar(field string, value any) *Clause

DecryptSimilar creates a new clause with operator "LIKE" and the value "%value%" decrypted.

func Eq

func Eq(field string, value any) *Clause

Eq creates a new clause with operator `=`.

func Gt

func Gt(field string, value any) *Clause

Gt creates a new clause with operator `>`.

func Gte

func Gte(field string, value any) *Clause

Gte creates a new clause with operator `>=`.

func In

func In(field string, value ...any) *Clause

In creates a new clause with operator `IN`.

func IsNotNull

func IsNotNull(field string) *Clause

IsNotNull creates a new clause with operator `IS NOT NULL`.

func IsNull

func IsNull(field string) *Clause

IsNull creates a new clause with operator `IS NULL`.

func Like

func Like(field string, value any) *Clause

Like creates a new clause with operator `LIKE`.

func Lt

func Lt(field string, value any) *Clause

Lt creates a new clause with operator `<`.

func Lte

func Lte(field string, value any) *Clause

Lte creates a new clause with operator `<=`.

func Neq

func Neq(field string, value any) *Clause

Neq creates a new clause with operator `<>`.

func NotBetween

func NotBetween(field string, from, to any, includeEdgeTo ...bool) *Clause

NotBetween creates a new clause that checks if a field is not between two values.

func NotIn

func NotIn(field string, value ...any) *Clause

NotIn creates a new clause with operator `NOT IN`.

func NotLike

func NotLike(field string, value any) *Clause

NotLike creates a new clause with operator `NOT LIKE`.

func NotSimilar

func NotSimilar(field string, value any) *Clause

NotSimilar creates a new clause with operator "NOT LIKE" and the value "%value%".

func Or

func Or(children ...*Clause) *Clause

Or creates a new clause with operator `OR`.

func Similar

func Similar(field string, value any) *Clause

Similar creates a new clause with operator "LIKE" and the value "%value%".

type Pagination

type Pagination struct {
	Page  int   `json:"page" form:"page"`
	Size  int   `json:"size" form:"size"`
	Total int64 `json:"total" form:"-"`
}

func FindAllComplex

func FindAllComplex[T any](tx *gorm.DB, cls *Clause, p *Pagination, s *Sorting) ([]T, *Pagination, error)

FindAllComplex finds all records from the database with pagination and sorting.

func Paginate

func Paginate(page, size int) *Pagination

Paginate creates a new *Pagination.

type Sorting

type Sorting struct {
	By  string `form:"by" json:"by"`
	Asc bool   `json:"asc" form:"asc"`
}

func Sort

func Sort(by string, asc bool) *Sorting

Sort creates a new *Sorting.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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