dal

package
v0.14.2-alpha1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: Apache-2.0 Imports: 4 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

func GetColumnNames

func GetColumnNames(d Dal, dst schema.Tabler, filter func(columnMeta ColumnMeta) bool) (names []string, err errors.Error)

GetColumnNames returns table Column Names in database

func GetPrimarykeyColumnNames

func GetPrimarykeyColumnNames(d Dal, dst schema.Tabler) (names []string, err errors.Error)

GetPrimarykeyColumnNames get returns PrimaryKey Column Names in database

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

Having creates a new Having 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 ColumnMeta

type ColumnMeta interface {
	Name() string
	DatabaseTypeName() string                 // varchar
	ColumnType() (columnType string, ok bool) // varchar(64)
	PrimaryKey() (isPrimaryKey bool, ok bool)
	AutoIncrement() (isAutoIncrement bool, ok bool)
	Length() (length int64, ok bool)
	DecimalSize() (precision int64, scale int64, ok bool)
	Nullable() (nullable bool, ok bool)
	Unique() (unique bool, ok bool)
	ScanType() reflect.Type
	Comment() (value string, ok bool)
	DefaultValue() (value string, ok bool)
}

ColumnMeta column type interface

func GetPrimarykeyColumns

func GetPrimarykeyColumns(d Dal, dst schema.Tabler) ([]ColumnMeta, errors.Error)

GetPrimarykeyColumns get returns PrimaryKey table Meta in database

type Dal

type Dal interface {
	// AutoMigrate runs auto migration for given entity
	AutoMigrate(entity interface{}, clauses ...Clause) errors.Error
	// AddColumn add column for the table
	AddColumn(table, columnName, columnType string) errors.Error
	// DropColumn drop column from the table
	DropColumn(table, columnName string) errors.Error
	// Exec executes raw sql query
	Exec(query string, params ...interface{}) errors.Error
	// RawCursor executes raw sql query and returns a database cursor
	RawCursor(query string, params ...interface{}) (*sql.Rows, errors.Error)
	// Cursor returns a database cursor, cursor is especially useful when handling big amount of rows of data
	Cursor(clauses ...Clause) (*sql.Rows, errors.Error)
	// Fetch loads row data from `cursor` into `dst`
	Fetch(cursor *sql.Rows, dst interface{}) errors.Error
	// All loads matched rows from database to `dst`, USE IT WITH COUTIOUS!!
	All(dst interface{}, clauses ...Clause) errors.Error
	// First loads first matched row from database to `dst`, error will be returned if no records were found
	First(dst interface{}, clauses ...Clause) errors.Error
	// All loads matched rows from database to `dst`, USE IT WITH COUTIOUS!!
	Count(clauses ...Clause) (int64, errors.Error)
	// Pluck used to query single column
	Pluck(column string, dest interface{}, clauses ...Clause) errors.Error
	// Create insert record to database
	Create(entity interface{}, clauses ...Clause) errors.Error
	// Update updates record
	Update(entity interface{}, clauses ...Clause) errors.Error
	// UpdateColumns batch records in database
	UpdateColumns(entity interface{}, clauses ...Clause) errors.Error
	// CreateOrUpdate tries to create the record, or fallback to update all if failed
	CreateOrUpdate(entity interface{}, clauses ...Clause) errors.Error
	// CreateIfNotExist tries to create the record if not exist
	CreateIfNotExist(entity interface{}, clauses ...Clause) errors.Error
	// Delete records from database
	Delete(entity interface{}, clauses ...Clause) errors.Error
	// AllTables returns all tables in database
	AllTables() ([]string, errors.Error)
	// GetColumns returns table columns in database
	GetColumns(dst schema.Tabler, filter func(columnMeta ColumnMeta) bool) (cms []ColumnMeta, err errors.Error)
	// GetPrimarykeyFields get the PrimaryKey from `gorm` tag
	GetPrimaryKeyFields(t reflect.Type) []reflect.StructField
}

Dal aims to facilitate an isolation between DBS and our System by defining a set of operations should a DBS provide

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