gt

package module
v1.30.36 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 28 Imported by: 0

README

gt

API rapid development frame, model generation, general addition, deletion, modification and query, support for multi-table connection crud

Are you developing crud code slowly?

It will help you...

demo

Documentation

Index

Constants

View Source
const (
	Reset       = "\033[0m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"
)

Colors

Variables

This section is empty.

Functions

func GetColParamSQL

func GetColParamSQL(p *Parses) (sql string)

GetColParamSQL get col ?

func GetColSQL

func GetColSQL(model interface{}) (sql string)

GetColSQL select * replace

func GetColSQLAlias

func GetColSQLAlias(model interface{}, alias string) (sql string)

GetColSQLAlias select * replace add alias

func GetMoreColSQL added in v1.30.31

func GetMoreColSQL(model interface{}, tables ...string) (sql string)

GetMoreColSQL select * replace select more tables : table name / table alias name first table must main table, like from a inner join b, first table is a

Types

type Config

type Config struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      logger2.LogLevel
}

type Crud

type Crud interface {
	// Init init crud
	Init(param *Params)
	// DB db
	DB() *DB
	// Params new/replace param
	// return param
	Params(param ...Param) Crud

	// GetBySearch get url params
	// like form data
	GetBySearch(params cmap.CMap) Crud     // search single table
	Get(params cmap.CMap) Crud             // get data no search
	GetMore(params cmap.CMap) Crud         // get data more table no search
	GetByID(id interface{}) Crud           // by id
	GetMoreBySearch(params cmap.CMap) Crud // more search, more tables inner/left join

	// Delete delete by id/ids/slice
	Delete(id interface{}) Crud // delete

	// Update crud and search id
	// json data
	Update() Crud     // update
	Create() Crud     // create, include res insert id
	CreateMore() Crud // create more, data must array type, single table

	Select(q interface{}, args ...interface{}) Crud // select sql
	From(query string) Crud                         // from sql, if use search, From must only once
	Group(query string) Crud                        // the last group by
	Search(params cmap.CMap) Crud                   // Select Search pager, params only support Pager and Mock
	Single() Crud                                   // no search
	Exec() Crud                                     // exec insert/update/delete sql
	Error() error                                   // crud error
	RowsAffected() int64                            // inflect rows
	Pager() result.Pager                            // search pager
	Begin() Crud                                    // start a transaction
	Commit() Crud                                   // commit a transaction
	Rollback() Crud                                 // rollback a transaction
	SavePoint(name string) Crud                     // save a point
	RollbackTo(name string) Crud                    // rollback to point
}

Crud interface

func NewCrud

func NewCrud(params ...Param) (crud Crud)

NewCrud new crud

func NewCusCrud added in v1.30.30

func NewCusCrud(db *gorm.DB, log bool, params ...Param) (crud Crud)

NewCusCrud new your custom db crud

type DB added in v1.10.0

type DB struct {
	// db driver
	*gorm.DB
	// contains filtered or unexported fields
}

DB tool

func (*DB) Create added in v1.30.30

func (db *DB) Create(table string, data interface{})

Create single/array

func (*DB) CreateMore added in v1.30.30

func (db *DB) CreateMore(table string, model interface{}, data interface{})

CreateMore data must array type more data create single table also can use Create array

func (*DB) Delete added in v1.30.30

func (db *DB) Delete(table string, id interface{})

func (*DB) ExecSQL added in v1.30.30

func (db *DB) ExecSQL(sql string, args ...interface{})

func (*DB) Get added in v1.30.30

func (db *DB) Get(gt *GT)

Get no search

func (*DB) GetByID added in v1.30.30

func (db *DB) GetByID(gt *GT, id interface{})

func (*DB) GetBySQLSearch added in v1.30.30

func (db *DB) GetBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, args []interface{}) (pager result.Pager)

GetBySQLSearch get sql search data clientPage: default 1 everyPage: default 10 if clientPage or everyPage < 0, return all

func (*DB) GetBySearch added in v1.30.30

func (db *DB) GetBySearch(gt *GT) (pager result.Pager)

GetBySearch single table return search info

func (*DB) GetDataBySelectSQLSearch added in v1.30.30

func (db *DB) GetDataBySelectSQLSearch(gt *GT) (pager result.Pager)

GetDataBySelectSQLSearch select sql search

func (*DB) GetMoreBySearch added in v1.30.30

func (db *DB) GetMoreBySearch(gt *GT) (pager result.Pager)

GetMoreBySearch more table params: innerTables is inner join tables params: leftTables is left join tables return search info table1 as main table, include other tables_id(foreign key)

func (*DB) GetMoreData added in v1.30.30

func (db *DB) GetMoreData(gt *GT)

GetMoreData no search

func (*DB) InitColumns added in v1.30.30

func (db *DB) InitColumns(param *Params)

InitColumns init db table columns map

func (*DB) NewDB added in v1.30.30

func (db *DB) NewDB()

NewDB new db driver

func (*DB) Update added in v1.30.30

func (db *DB) Update(gt *GT)

type GT

type GT struct {
	*Params
	// CMap
	CMaps cmap.CMap // params

	// select sql
	Select string // select sql
	From   string // only once
	Group  string // the last group
	Args   []interface{}
	// contains filtered or unexported fields
}

GT SQL struct

func (*GT) GetMoreSQL added in v1.20.6

func (gt *GT) GetMoreSQL()

GetMoreSQL more table params: innerTables is inner join tables, must even number params: leftTables is left join tables return: select sql table1 as main table, include other tables_id(foreign key)

func (*GT) GetSQL added in v1.20.6

func (gt *GT) GetSQL()

GetSQL get single sql

func (*GT) GetSearchSQL added in v1.20.6

func (gt *GT) GetSearchSQL()

GetSearchSQL search sql default order by id desc

func (*GT) GetSelectSearchSQL added in v1.20.6

func (gt *GT) GetSelectSearchSQL()

GetSelectSearchSQL select sql

type Mysql added in v1.10.0

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

Mysql implement Crud

func (*Mysql) Begin added in v1.10.0

func (c *Mysql) Begin() Crud

func (*Mysql) Commit added in v1.10.0

func (c *Mysql) Commit() Crud

func (*Mysql) Create added in v1.10.0

func (c *Mysql) Create() Crud

func (*Mysql) CreateMore added in v1.10.0

func (c *Mysql) CreateMore() Crud

CreateMore can use Create replace

func (*Mysql) DB added in v1.10.0

func (c *Mysql) DB() *DB

func (*Mysql) Delete added in v1.10.0

func (c *Mysql) Delete(id interface{}) Crud

func (*Mysql) Error added in v1.10.0

func (c *Mysql) Error() error

func (*Mysql) Exec added in v1.10.0

func (c *Mysql) Exec() Crud

func (*Mysql) From added in v1.10.0

func (c *Mysql) From(query string) Crud

func (*Mysql) Get added in v1.20.6

func (c *Mysql) Get(params cmap.CMap) Crud

func (*Mysql) GetByID added in v1.10.0

func (c *Mysql) GetByID(id interface{}) Crud

func (*Mysql) GetBySearch added in v1.10.0

func (c *Mysql) GetBySearch(params cmap.CMap) Crud

GetBySearch pager info

func (*Mysql) GetMore added in v1.20.6

func (c *Mysql) GetMore(params cmap.CMap) Crud

func (*Mysql) GetMoreBySearch added in v1.10.0

func (c *Mysql) GetMoreBySearch(params cmap.CMap) Crud

GetMoreBySearch the same as search more tables

func (*Mysql) Group added in v1.10.0

func (c *Mysql) Group(query string) Crud

func (*Mysql) Init added in v1.20.0

func (c *Mysql) Init(param *Params)

func (*Mysql) Pager added in v1.10.0

func (c *Mysql) Pager() result.Pager

func (*Mysql) Params added in v1.10.0

func (c *Mysql) Params(params ...Param) Crud

func (*Mysql) Rollback added in v1.10.0

func (c *Mysql) Rollback() Crud

func (*Mysql) RollbackTo added in v1.20.0

func (c *Mysql) RollbackTo(name string) Crud

func (*Mysql) RowsAffected added in v1.10.0

func (c *Mysql) RowsAffected() int64

func (*Mysql) SavePoint added in v1.20.0

func (c *Mysql) SavePoint(name string) Crud

func (*Mysql) Search added in v1.10.0

func (c *Mysql) Search(params cmap.CMap) Crud

func (*Mysql) Select added in v1.10.0

func (c *Mysql) Select(q interface{}, args ...interface{}) Crud

func (*Mysql) Single added in v1.10.0

func (c *Mysql) Single() Crud

func (*Mysql) Update added in v1.10.0

func (c *Mysql) Update() Crud

type Param

type Param func(*Params)

func Data

func Data(Data interface{}) Param

func Distinct added in v1.20.9

func Distinct(Distinct string) Param

Distinct inner/left support distinct

func Inner added in v1.8.1

func Inner(InnerTables ...string) Param

func KeyModel

func KeyModel(KeyModel interface{}) Param

func Left added in v1.8.1

func Left(LeftTable ...string) Param

func Model

func Model(Model interface{}) Param

func SubSQL

func SubSQL(SubSQL ...string) Param

func Table

func Table(Table string) Param

func Valid added in v1.30.31

func Valid(valid bool) Param

func WhereSQL added in v1.20.0

func WhereSQL(WhereSQL string, args ...interface{}) Param

WhereSQL where sql and args

func (Param) WhereSQL added in v1.20.0

func (p Param) WhereSQL(WhereSQL string, args ...interface{}) Param

type Params

type Params struct {
	// attributes
	InnerTable []string    // inner join tables
	LeftTable  []string    // left join tables
	Table      string      // table name
	Model      interface{} // table model, like User{}
	KeyModel   interface{} // key like model
	Data       interface{} // table model data, like var user User{}, it is 'user', it store real data

	// sub query
	SubSQL string // SubQuery SQL
	// where
	WhereSQL string // Where SQL
	// contains filtered or unexported fields
}

Params crud params

type Parses added in v1.30.31

type Parses struct {
	Table  string // main table
	Key    string
	Tags   []string
	Vs     []interface{}
	OTags  map[string]string
	TagTb  map[string]string // part: tag->tb
	TagTag map[string]string // part: tag->tag
}

func (*Parses) Marshal added in v1.30.31

func (r *Parses) Marshal(v string)

func (*Parses) String added in v1.30.31

func (r *Parses) String() string

Jump to

Keyboard shortcuts

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