dal

package
v0.11.0-testdockerpush Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const FromClause string = "From"
View Source
const GroupbyClause string = "GroupBy"
View Source
const HavingClause string = "Having"
View Source
const JoinClause string = "Join"
View Source
const LimitClause string = "Limit"
View Source
const OffsetClause string = "Offset"
View Source
const OrderbyClause string = "OrderBy"
View Source
const SelectClause string = "Select"
View Source
const WhereClause string = "Where"

Variables

This section is empty.

Functions

This section is empty.

Types

type Clause

type Clause struct {
	Type string
	Data interface{}
}

func From

func From(table interface{}) Clause

From creates a new TableClause

func Groupby

func Groupby(expr string) Clause

Groupby creates a new Groupby clause

func Having

func Having(clause string, params ...interface{}) Clause

Groupby creates a new Groupby clause

func Join

func Join(clause string, params ...interface{}) Clause

Join creates a new JoinClause

func Limit

func Limit(limit int) Clause

Limit creates a new LimitClause

func Offset

func Offset(offset int) Clause

Offset creates a new OffsetClause

func Orderby

func Orderby(expr string) Clause

Orderby creates a new Orderby clause

func Select

func Select(fields string) Clause

Select creates a new TableClause

func Where

func Where(clause string, params ...interface{}) Clause

Where creates a new WhereClause

type Dal

type Dal interface {
	// Raw executes raw sql query with sql.Rows and error return
	Raw(query string, params ...interface{}) (*sql.Rows, error)
	// Exec executes raw sql query
	Exec(query string, params ...interface{}) error
	// CreateTable creates a table with gorm definition from `entity`R
	AutoMigrate(entity interface{}, clauses ...Clause) error
	// Cursor returns a database cursor, cursor is especially useful when handling big amount of rows of data
	Cursor(clauses ...Clause) (*sql.Rows, error)
	// Fetch loads row data from `cursor` into `dst`
	Fetch(cursor *sql.Rows, dst interface{}) error
	// All loads matched rows from database to `dst`, USE IT WITH COUTIOUS!!
	All(dst interface{}, clauses ...Clause) error
	// First loads first matched row from database to `dst`, error will be returned if no records were found
	First(dst interface{}, clauses ...Clause) error
	// All loads matched rows from database to `dst`, USE IT WITH COUTIOUS!!
	Count(clauses ...Clause) (int64, error)
	// Pluck used to query single column
	Pluck(column string, dest interface{}, clauses ...Clause) error
	// Create insert record to database
	Create(entity interface{}, clauses ...Clause) error
	// Update updates record
	Update(entity interface{}, clauses ...Clause) error
	// CreateOrUpdate tries to create the record, or fallback to update all if failed
	CreateOrUpdate(entity interface{}, clauses ...Clause) error
	// CreateIfNotExist tries to create the record if not exist
	CreateIfNotExist(entity interface{}, clauses ...Clause) error
	// Delete records from database
	Delete(entity interface{}, clauses ...Clause) error
}

Dal aims to facilitate an isolation of Database Access Layer by defining a set of operations should a Database Access Layer provide This is inroduced by the fact that mocking *gorm.DB is hard, and `gomonkey` is not working on macOS

type DalClause

type DalClause struct {
	Expr   string
	Params []interface{}
}

Jump to

Keyboard shortcuts

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