sql

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 4 Imported by: 1

README

Wrapper of gorm

Installation

go get -u github.com/Metadiv-Technology-Limited/sql

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(children ...models.IClause) models.IClause

And creates a new clause with operator `AND`.

func Between

func Between(field string, from, to any, includeEdgeTo ...bool) models.IClause

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

func Count

func Count[T any](tx *gorm.DB, cls models.IClause) (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 models.IClause) error

DeleteBy deletes records from the database by a clause.

func Eq

func Eq(field string, value any) models.IClause

Eq creates a new clause with operator `=`.

func FindAll

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

FindAll finds all records from the database.

func FindAllComplex

func FindAllComplex[T any](tx *gorm.DB, cls models.IClause, p models.IPagination, s models.ISorting) ([]T, models.IPagination, error)

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

func FindOne

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

FindOne finds one record from the database.

func Gt

func Gt(field string, value any) models.IClause

Gt creates a new clause with operator `>`.

func Gte

func Gte(field string, value any) models.IClause

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

func In

func In(field string, value ...any) models.IClause

In creates a new clause with operator `IN`.

func IsNotNull

func IsNotNull(field string) models.IClause

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

func IsNull

func IsNull(field string) models.IClause

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

func Like

func Like(field string, value any) models.IClause

Like creates a new clause with operator `LIKE`.

func Lt

func Lt(field string, value any) models.IClause

Lt creates a new clause with operator `<`.

func Lte

func Lte(field string, value any) models.IClause

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

func Neq

func Neq(field string, value any) models.IClause

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

func NotBetween

func NotBetween(field string, from, to any, includeEdgeTo ...bool) models.IClause

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

func NotIn

func NotIn(field string, value ...any) models.IClause

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

func NotLike

func NotLike(field string, value any) models.IClause

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

func NotSimilar

func NotSimilar(field string, value any) models.IClause

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

func Or

func Or(children ...models.IClause) models.IClause

Or creates a new clause with operator `OR`.

func Paginate

func Paginate(page, size int) models.IPagination

Paginate creates a new models.IPagination.

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.

func Similar

func Similar(field string, value any) models.IClause

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

func Sort

func Sort(by string, asc bool) models.ISorting

Sort creates a new models.ISorting.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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