linq

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSG_DRIVER_NOT_FOUND   = "Driver not found"
	MSG_DRIVER_REQUIRED    = "Driver is required"
	MSG_UPDATE_ONLY_ALLOW  = "Update only allow %d items"
	MSG_DELETE_ONLY_ALLOW  = "Delete only allow %d items"
	MSG_NOT_FOUND_IDT      = "Not found idt in the current values"
	MSG_CONNECTED_REQUIRED = "Connected is required"
	MSG_COMMAND_REQUIRED   = "Command is required"
	MSG_SQL_REQUIRED       = "Sql is required"
	MSG_QUERY_NOT_COMMAND  = "The query is not a command"
)
View Source
const (
	TpShowOriginal = iota
	TpUniqueValue
	TpCountAll
	TpCountValue
	TpCountUnique
	TpCountEmpty
	TpCountNotEmpty
	TpPercentEmpty
	TpPercentNotEmpty
	TpCount
	TpSum
	TpAvg
	TpMax
	TpMin
)

Variables

View Source
var (
	MaxUpdate = 1000
	MaxDelete = 1000
	MaxRows   = 1000
)

Global variables

Functions

func DataToItem

func DataToItem(rows *sql.Rows, source string) et.Item

* * DataItem return a item from a sql rows and source field * @param rows *sql.Rows * @param source string * @return et.Item *

func DataToItems

func DataToItems(rows *sql.Rows, source string) et.Items

* * DataItems return a items from a sql rows and source field * @param rows *sql.Rows * @param source string * @return et.Items *

func IndexColumn

func IndexColumn(model *Model, name string) int

IndexColumn return index of column in model

func Register

func Register(name string, driver func() Driver)

* * Register register a driver * @return *Linq *

func RowsToItem

func RowsToItem(rows *sql.Rows) et.Item

* * RowsToItem return a item from a sql rows * @param rows *sql.Rows * @return et.Item *

func RowsToItems

func RowsToItems(rows *sql.Rows) et.Items

* * RowsToItems return a items from a sql rows * @param rows *sql.Rows * @return et.Items *

func SQLDDL

func SQLDDL(sql string, args ...any) string

* * SQLDDL return a sql string with the args * @param sql string * @param args ...any * @return string *

func SQLParse

func SQLParse(sql string, args ...any) string

* * SQLParse return a sql string with the args * @param sql string * @param args ...any * @return string *

func SQLQuote

func SQLQuote(sql string) string

* * SQLQuote return a sql cuote string * @param sql string * @return string *

Types

type COl

type COl struct {
	Name        string
	Description string
	TypeData    TypeData
	Default     interface{}
}

type ColDetail

type ColDetail struct {
	Name        string
	Description string
	Default     interface{}
	FuncDetail  FuncDetail
}

type ColFkey

type ColFkey struct {
	ForeignKey  []string
	ParentModel *Model
	ParentKey   []string
}

type ColFormula

type ColFormula struct {
	Name    string
	Formula string
}

type ColRequired

type ColRequired struct {
	Name    string
	Message string
}

type ColRol

type ColRol struct {
	Name       string
	ForeignKey []string
	Parent     *Model
	ParentKey  []string
	Select     []string
	Calculate  TpCaculate
}

type Column

type Column struct {
	Model       *Model
	Name        string
	Tag         string
	Description string
	TypeColumn  TypeColumn
	TypeData    TypeData
	Definition  et.Json
	Default     interface{}
	RelationTo  *Relation
	FuncDetail  FuncDetail
	Formula     string
	PrimaryKey  bool
	ForeignKey  bool
	Indexed     bool
	Unique      bool
	Hidden      bool
	IsDataField bool
	Required    *Required
	Concats     []*Lselect
}

Column is a struct for columns in a model

func Col

func Col(model *Model, name string) *Column

Col return a column in the model

func (*Column) As

func (c *Column) As(l *Linq) string

AsModel return as name of model

func (*Column) AsModel

func (c *Column) AsModel(l *Linq) string

AsModel return as name of model

func (*Column) Between

func (c *Column) Between(vals ...interface{}) *Lwhere

* * Between method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) Concat

func (c *Column) Concat() string

* * Concat method to use in linq * @return string *

func (*Column) Describe

func (c *Column) Describe() et.Json

Describe carapteristics of column

func (*Column) Eq

func (c *Column) Eq(val interface{}) *Lwhere

* * Eq method to use in column * @param interface{} * @return *Lwhere *

func (*Column) In

func (c *Column) In(vals ...interface{}) *Lwhere

* * In method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) Less

func (c *Column) Less(val interface{}) *Lwhere

* * Less method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) LessEq

func (c *Column) LessEq(val interface{}) *Lwhere

* * LessEq method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) Like

func (c *Column) Like(val interface{}) *Lwhere

* * Like method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) Low

func (c *Column) Low() string

Resutn name of column in lowercase

func (*Column) More

func (c *Column) More(val interface{}) *Lwhere

* * More method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) MoreEq

func (c *Column) MoreEq(val interface{}) *Lwhere

* * MoreEq method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) Neg

func (c *Column) Neg(val interface{}) *Lwhere

* * Neg method to use in column * @param interface{} * @return *Lwhere *

func (*Column) NotBetween

func (c *Column) NotBetween(vals ...interface{}) *Lwhere

* * NotBetween method to use in column * @param ...interface{} * @return *Lwhere *

func (*Column) SetHidden

func (c *Column) SetHidden(val bool)

Hidden set hidden column

func (*Column) SetIndexed

func (c *Column) SetIndexed(asc bool)

SetIndexed add a index to column

func (*Column) SetRelationTo

func (c *Column) SetRelationTo(parent *Model, parentKey []string, _select []string, calculate TpCaculate, limit int)

SetRequiredTo set required column to model

func (*Column) SetRequired

func (c *Column) SetRequired(val bool, msg string)

SetRequired set required column

func (*Column) SetUnique

func (c *Column) SetUnique(val bool)

func (*Column) Table

func (c *Column) Table() string

Table return table name of column

func (*Column) Up

func (c *Column) Up() string

Resutn name of column in uppercase

type Connection

type Connection struct {
	Name     string
	Drive    TypeDriver
	User     string
	Password string
	Host     string
	Port     int
	Database string
	App      string
	Mode     ModeDatabase
}

type Constraint

type Constraint struct {
	ForeignKey []string
	Parent     *Model
	ParentKey  []string
}

* * Constraint is a struct for constraint *

func (*Constraint) Describe

func (c *Constraint) Describe() et.Json

* * Describe return a json with the definition of the constraint * @return et.Json *

func (*Constraint) Fkey

func (c *Constraint) Fkey() string

* * Fkey return a valid name of constraint * @return string *

func (*Constraint) Pkey

func (c *Constraint) Pkey() string

* * Pkey return a valid parent key name of constraint * @return string *

func (*Constraint) Table

func (c *Constraint) Table() string

* * Table return a valid parent table name of constraint * @return string *

type DB

type DB struct {
	Index       int
	Name        string
	Description string
	DB          *sql.DB
	WS          *ws.Hub
	Driver      *Driver
	Schemes     []*Schema
	Models      []*Model
	// contains filtered or unexported fields
}

* * DB struct to define a database *

func Core

func Core() (*DB, error)

* * Core a database * @return *linq.DB * @return error *

func Load

func Load(params *Connection) (*DB, error)

* * Load a database * @return *DB * @return error *

func Master

func Master() (*DB, error)

* * Master a database * @return *linq.DB * @return error *

func Mocks added in v0.0.4

func Mocks() (*DB, error)

* * Mocks a database * @return *linq.DB * @return error *

func NewDB

func NewDB(name string, db *sql.DB, driver Driver) (*DB, error)

* * NewDB create a new database * @param name string * @param description string * @param drive Driver * @return *DB *

func None added in v0.0.4

func None() (*DB, error)

* * None a database * @return *linq.DB * @return error *

func Read added in v0.0.4

func Read() (*DB, error)

* * Read a database * @return *linq.DB * @return error *

func (*DB) Close

func (d *DB) Close()

* * Close the database *

func (*DB) Command

func (d *DB) Command(sql string, args ...any) (et.Item, error)

* * Command execute a query in the database and return one item * @parms db * @parms sql * @parms args * @return et.Item * @return error *

func (*DB) CurrentSerie

func (d *DB) CurrentSerie(tag string) (int, error)

* * CurrentSerie return the current serie * @param tag string * @return int * @return error *

func (*DB) Data

func (d *DB) Data(source, sql string, args ...any) (et.Items, error)

* * Data execute a query * @param sql string * @param args ...any * @return et.Items * @return error *

func (*DB) DataOne

func (d *DB) DataOne(source, sql string, args ...any) (et.Item, error)

* * DataOne execute a query and return one item * @param sql string * @param args ...any * @return et.Item * @return error *

func (*DB) DeleteSerie

func (d *DB) DeleteSerie(tag string) error

* * DeleteSerie delete the serie * @param tag string * @return error *

func (*DB) Describe

func (d *DB) Describe() et.Json

* * Describe return the definition of the database * @return et.Json *

func (*DB) Disconnected

func (d *DB) Disconnected() error

* * Disconnected to database * @return error *

func (*DB) Exec

func (d *DB) Exec(sql string, args ...any) error

* * Exec execute a query * @param sql string * @param args ...any * @return error *

func (*DB) GetMigrateId

func (d *DB) GetMigrateId(old_id, tag string) (string, error)

* * GetMigrateId get a migrate id * @param old_id string * @param tag string * @return string * @return error *

func (*DB) GetModel

func (d *DB) GetModel(model *Model) *Model

* * GetModel get model by model * @param model *Model * @return *Model *

func (*DB) GetSchema

func (d *DB) GetSchema(schema *Schema) *Schema

* * GetSchema get a schema * @param schema *Schema * @return *Schema *

func (*DB) InitModel

func (d *DB) InitModel(model *Model) error

* * InitSchema init a schema * @param schema *Schema * @return error *

func (*DB) Master

func (d *DB) Master(params *Connection) error

* * Master set the database as master * @param params *Connection * @return error *

func (*DB) Model

func (d *DB) Model(name string) *Model

* * Model get model by name * @param name string * @return *Model *

func (*DB) NextCode

func (d *DB) NextCode(tag, format string) (string, error)

* * NextCode return the next code * @param tag string * @param format string * @return string * @return error *

func (*DB) NextSerie

func (d *DB) NextSerie(tag string) (int, error)

* * NextSerie return the next serie * @param tag string * @return int * @return error *

func (*DB) Query

func (d *DB) Query(sql string, args ...any) (et.Items, error)

* * Query execute a query in the database * @parms db * @parms sql * @parms args * @return et.Items * @return error *

func (*DB) QueryOne

func (d *DB) QueryOne(sql string, args ...any) (et.Item, error)

* * QueryOne execute a query in the database and return one item * @parms db * @parms sql * @parms args * @return et.Item * @return error *

func (*DB) Read added in v0.0.4

func (d *DB) Read(params *Connection) error

* * Read set the database as master * @param params *Connection * @return error *

func (*DB) SetSerie

func (d *DB) SetSerie(tag string, val int) error

* * SetSerie set the serie * @param tag string * @param val int * @return error *

func (*DB) Table

func (d *DB) Table(schema, name string) *Model

* * Table get model by tablename * @param schema string * @param name string * @return *Model *

func (*DB) UpSertMigrateId

func (d *DB) UpSertMigrateId(old_id, _id, tag string) error

* * UpSertMigrateId upsert a migrate id * @param old_id string * @param _id string * @param tag string * @return error *

type DDL added in v0.0.4

type DDL struct {
	Table       string
	Indexes     string
	ForeignKeys string
	Objects     string
	Recycling   string
}

type Definition

type Definition struct {
	Schema      string
	Name        string
	Description string
	Version     int
	Columns     []COl
	Atribs      []COl
	Indexes     []string
	Uniques     []string
	Hidden      []string
	Required    []ColRequired
	PrimaryKey  []string
	ForeignKey  []ColFkey
	Rollup      []ColRol
	Details     []ColDetail
	Formulas    []ColFormula
	Trigger     []TRigger
}

type Driver

type Driver interface {
	Type() string
	Mode() ModeDatabase
	LoadMode() error
	Connect(params *Connection) (*DB, error)
	Master(params *Connection) (*DB, error)
	// Listen
	SetListen(channels []string, handler HandlerListend)
	SetCommand(query string) error
	SetMutex(id, query string, index int64) error
	GetCommand(id string) (et.Item, error)
	SyncCommand() error
	// DDL (Data Definition Language)
	DefineSql(model *Model) string
	MutationSql(model *Model) string
	// Crud
	SelectSql(linq *Linq) string
	CurrentSql(linq *Linq) string
	InsertSql(linq *Linq) string
	UpdateSql(linq *Linq) string
	DeleteSql(linq *Linq) string
	// DCL (Data Control Language)
	DCL(command string, params et.Json) (et.Item, error)
	// Series
	NextSerie(tag string) (int, error)
	NextCode(tag, format string) (string, error)
	SetSerie(tag string, val int) error
	CurrentSerie(tag string) (int, error)
	DeleteSerie(tag string) error
	// Migration IDs
	UpSertMigrateId(old_id, _id, tag string) error
	GetMigrateId(old_id, tag string) (string, error)
	// Models
	ModelExist(schema, name string) (bool, error)
}

type FuncDetail

type FuncDetail func(col *Column, data *et.Json)

Details is a function for details

type HandlerListend

type HandlerListend func(res et.Json)

type Index

type Index struct {
	Column *Column
	Asc    bool
}

* * Index is a struct for index *

func (*Index) Describe

func (i *Index) Describe() et.Json

* * Describe return a json with the definition of the index * @return et.Json *

type Lcolumns

type Lcolumns struct {
	Used     bool
	Columns  []*Lselect
	Distinct bool
}

Define type columns in linq

func NewColumns

func NewColumns() *Lcolumns

* * NewColumns return a new columns * @return *Lcolumns *

func (*Lcolumns) Describe

func (l *Lcolumns) Describe() et.Json

* * Describe return a json with the definition of the columns * @return et.Json *

func (*Lcolumns) SetAs

func (l *Lcolumns) SetAs(name string) *Lselect

* * SetAs set the name of the column * @param name string * @return *Lselect *

type Lfrom

type Lfrom struct {
	Linq  *Linq
	Model *Model
	AS    string
}

From struct to use in linq

func (*Lfrom) As

func (l *Lfrom) As(name string) *Lfrom

As method to use set as name to from in linq

func (*Lfrom) AsColumn

func (l *Lfrom) AsColumn(col *Column) string

Return as column name in linq

func (*Lfrom) C

func (l *Lfrom) C(name string) *Column

Shortcut to column in module to linq

func (*Lfrom) Col

func (l *Lfrom) Col(name string) *Column

Shortcut to column in module to linq

func (*Lfrom) Column

func (l *Lfrom) Column(name string) *Column

Find column in module to linq

func (*Lfrom) Describe

func (l *Lfrom) Describe() et.Json

Describe method to use in linq

func (*Lfrom) Table

func (l *Lfrom) Table() string

Return table name in linq

type Lgroup

type Lgroup struct {
	Linq   *Linq
	Column *Lselect
	AS     string
}

GroupBy struct to use in linq

func (*Lgroup) As

func (l *Lgroup) As() string

As method to use set as name to column in linq

func (*Lgroup) Describe

func (l *Lgroup) Describe() et.Json

Describe method to use in linq

func (*Lgroup) SetAs

func (l *Lgroup) SetAs(name string) *Lgroup

As method to use set as name to column in linq

type Linq

type Linq struct {
	DB      *DB
	Froms   []*Lfrom
	Columns []*Lselect
	Atribs  []*Lselect
	Selects *Lcolumns
	Datas   *Lcolumns
	Returns *Lcolumns
	Details *Lcolumns
	Wheres  []*Lwhere
	Groups  []*Lgroup
	Havings []*Lwhere

	Orders    []*Lorder
	Joins     []*Ljoin
	Union     []*Linq
	Limit     int
	Offset    int
	Values    *Values
	TypeQuery TypeQuery
	Sql       string
	Args      []any
	Result    *et.Item
	// contains filtered or unexported fields
}

Linq struct

func From

func From(model *Model, as ...string) *Linq

From method new linq

func NewLinQ

func NewLinQ() *Linq

func (*Linq) All

func (l *Linq) All() (et.Items, error)

* * All is a function to select all data * @return et.Items * @return error *

func (*Linq) And

func (l *Linq) And(where *Lwhere) *Linq

* * And connector to use in where * @param *Lwhere * @return *Linq *

func (*Linq) Avg

func (l *Linq) Avg(col *Column, as string) *Linq

Avg function to use in linq

func (*Linq) Clear

func (l *Linq) Clear() string

* * Clear clear sql * @return string *

func (*Linq) Column

func (l *Linq) Column(col interface{}) *Column

* * Column find column in module to linq * @param name string * @return *Column *

func (*Linq) Concat

func (l *Linq) Concat(cols ...interface{}) *Lwhere

* * Concat method to use in linq * @param []interfase{} * @return *Lwhere *

func (*Linq) Count

func (l *Linq) Count(col *Column, as string) *Linq

Count function to use in linq

func (*Linq) Data

func (l *Linq) Data(sel ...interface{}) *Linq

Select SourceField a linq with data

func (*Linq) Debug

func (l *Linq) Debug() *Linq

* * Debug show sql in debug mode * @return *Linq *

func (*Linq) Describe

func (l *Linq) Describe() *et.Json

* * Describe return a json with the definition of the linq * @return et.Json *

func (*Linq) Distinct

func (l *Linq) Distinct() *Linq

Select distinct columns a query

func (*Linq) Exec

func (l *Linq) Exec() (et.Item, error)

* * Exec execute a command in the database * @return et.Items * @return error *

func (*Linq) F

func (l *Linq) F(as string) *Lfrom

func (*Linq) Find

func (l *Linq) Find() (et.Items, error)

* * Find is a function to select all data * @return et.Items * @return error *

func (*Linq) First

func (l *Linq) First() (et.Item, error)

* * First is a function to select first data * @return et.Item * @return error *

func (*Linq) From

func (l *Linq) From(model *Model, as ...string) *Lfrom

From method to use in linq

func (*Linq) GetAtrib

func (l *Linq) GetAtrib(column *Column) *Lselect

func (*Linq) GetColumn

func (l *Linq) GetColumn(column *Column) *Lselect

Add column to columns

func (*Linq) GetData

func (l *Linq) GetData(model *Model, name string) *Lselect

Add column to data by name

func (*Linq) GetDetail

func (l *Linq) GetDetail(column *Column) *Lselect

Add column to details

func (*Linq) GetRetun

func (l *Linq) GetRetun(model *Model, name string) *Lselect

func (*Linq) GetSelect

func (l *Linq) GetSelect(model *Model, name string) *Lselect

Add column to select by name

func (*Linq) Go

func (l *Linq) Go() (et.Item, error)

* * Go is a Exec function and return items * @return et.Items * @return error *

func (*Linq) GroupBy

func (l *Linq) GroupBy(columns ...*Column) *Linq

GroupBy method to use in linq

func (*Linq) Having

func (l *Linq) Having(where *Lwhere) *Linq

Where method to use in linq

func (*Linq) History

func (l *Linq) History(val bool) *Linq

* * History method to use in linq * @return *Linq *

func (*Linq) Join

func (l *Linq) Join(t1, t2 *Model, where *Lwhere) *Linq

Inner Join method to use in linq

func (*Linq) Last

func (l *Linq) Last() (et.Item, error)

* * Last is a function to select last data * @return et.Item * @return error *

func (*Linq) LeftJoin

func (l *Linq) LeftJoin(t1, t2 *Model, where *Lwhere) *Linq

Left Join method to use in linq

func (*Linq) List

func (l *Linq) List(page, rows int) (et.List, error)

* * List is a function to select page data and return list * @return et.List * @return error *

func (*Linq) Max

func (l *Linq) Max(col *Column, as string) *Linq

Max function to use in linq

func (*Linq) Min

func (l *Linq) Min(col *Column, as string) *Linq

Min function to use in linq

func (*Linq) One

func (l *Linq) One() (et.Item, error)

* * QueryOne is a function to execute a query and return one item * @return et.Item * @return error *

func (*Linq) Or

func (l *Linq) Or(where *Lwhere) *Linq

* * Or connector to use in where * @param *Lwhere * @return *Linq *

func (*Linq) OrderBy

func (l *Linq) OrderBy(asc bool, columns ...*Column) *Linq

* * OrderBy * @param asc * @param columns *

func (*Linq) OrderByDesc

func (l *Linq) OrderByDesc(columns ...*Column) *Linq

* * OrderBy * @param columns *

func (*Linq) Page

func (l *Linq) Page(page, rows int) (et.Items, error)

* * Page is a function to select page data * @return et.Items * @return error *

func (*Linq) Query

func (l *Linq) Query() (et.Items, error)

* * Query is a function to execute a query * @return et.Items * @return error *

func (*Linq) Returning

func (l *Linq) Returning(sel ...any) *Linq

func (*Linq) RightJoin

func (l *Linq) RightJoin(t1, t2 *Model, where *Lwhere) *Linq

Right Join method to use in linq

func (*Linq) SQL

func (l *Linq) SQL() string

* * SQL return sql * @return string *

func (*Linq) Select

func (l *Linq) Select(sel ...interface{}) *Linq

Select columns a query

func (*Linq) Set

func (l *Linq) Set(values et.Json) *Linq

func (*Linq) ShowModel

func (l *Linq) ShowModel() *Linq

* * ShowModel show model id debug model * @return *Linq *

func (*Linq) Skip

func (l *Linq) Skip(n int) (et.Items, error)

* * Skip is a function to skip n element data * @return et.Items * @return error *

func (*Linq) Sum

func (l *Linq) Sum(col *Column, as string) *Linq

Sum function to use in linq

func (*Linq) Take

func (l *Linq) Take(n int) (et.Items, error)

* * Take is a function to select n element data * @return et.Items * @return error *

func (*Linq) Where

func (l *Linq) Where(where *Lwhere) *Linq

* * Where method to use in linq * @param *Lselect * @param string * @param interface{} * @return *Lwhere *

type Listener

type Listener func(data et.Json)

* * Listener is a function for listener * @param data et.Json *

type Ljoin

type Ljoin struct {
	Linq     *Linq
	T1       *Lfrom
	T2       *Lfrom
	On       *Lwhere
	TypeJoin TypeJoin
}

Join struct to use in linq

func (*Ljoin) Describe

func (l *Ljoin) Describe() et.Json

Describe method to use in linq

type Lorder

type Lorder struct {
	Linq   *Linq
	Column *Lselect
	Asc    bool
}

OrderBy struct to use in linq

func (*Lorder) As

func (l *Lorder) As() string

* * As * @return string *

func (*Lorder) Describe

func (l *Lorder) Describe() et.Json

* * Describe * @return Json *

func (*Lorder) Sorted

func (l *Lorder) Sorted() string

* * Sorted * @return string *

type Lselect

type Lselect struct {
	Linq       *Linq
	From       *Lfrom
	Column     *Column
	AS         string
	TpCaculate TpCaculate
}

Select struct to use in linq

func (*Lselect) As

func (l *Lselect) As() string

As method to use set as name to column in linq

func (*Lselect) Describe

func (l *Lselect) Describe() et.Json

Describe method to use in linq

func (*Lselect) FuncDetail

func (l *Lselect) FuncDetail(data *et.Json)

Details method to use in linq

func (*Lselect) SetAs

func (l *Lselect) SetAs(name string) *Lselect

As method to use set as name to column in linq

type Lwhere

type Lwhere struct {
	Linq     *Linq
	Columns  []*Lselect
	Operator string
	Value    interface{}
	Connetor string
}

* * Lwhere struct to use in linq *

func Concat

func Concat(cols ...interface{}) *Lwhere

* * Concat struct to use in linq * @param []interfase{} * @return *Lwhere *

func Where

func Where(column *Column, operator string, value interface{}) *Lwhere

* * Where method to use in linq * @param *Column * @param string * @param interface{} * @return *Lwhere *

func (*Lwhere) As

func (w *Lwhere) As() string

* * As method to use in linq * @return string *

func (*Lwhere) Between

func (w *Lwhere) Between(vals ...interface{}) *Lwhere

* * Between method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) Describe

func (w *Lwhere) Describe() et.Json

* * Describe method to use in linq * @return et.Json *

func (*Lwhere) Eq

func (w *Lwhere) Eq(val interface{}) *Lwhere

* * Eq method to use in linq * @param interface{} * @return *Lwhere *

func (*Lwhere) In

func (w *Lwhere) In(vals ...interface{}) *Lwhere

* * In method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) Less

func (w *Lwhere) Less(val interface{}) *Lwhere

* * Less method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) LessEq

func (w *Lwhere) LessEq(val interface{}) *Lwhere

* * LessEq method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) Like

func (w *Lwhere) Like(val interface{}) *Lwhere

* * Like method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) More

func (w *Lwhere) More(val interface{}) *Lwhere

* * More method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) MoreEq

func (w *Lwhere) MoreEq(val interface{}) *Lwhere

* * MoreEq method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) Neg

func (w *Lwhere) Neg(val interface{}) *Lwhere

* * Neg method to use in linq * @param interface{} * @return *Lwhere *

func (*Lwhere) NotBetween

func (w *Lwhere) NotBetween(vals ...interface{}) *Lwhere

* * NotBetween method to use in linq * @param ...interface{} * @return *Lwhere *

func (*Lwhere) Quote

func (w *Lwhere) Quote() string

* * Quote method to use in linq * @return string *

func (*Lwhere) Unquote

func (w *Lwhere) Unquote() string

* * Unquote method to use in linq * @return string *

func (*Lwhere) Where

func (w *Lwhere) Where() string

* * Where method to use in linq * @return string *

type ModeDatabase

type ModeDatabase int

Mode Database

const (
	ModeNone ModeDatabase = iota
	ModeCore
	ModeMaster
	ModeRead
	ModeMocks
)

func ToModeDatabase

func ToModeDatabase(val int) ModeDatabase

* * ToModeDatabase convert int to ModeDatabase * @param val int * @return ModeDatabase *

func (ModeDatabase) IsNone

func (m ModeDatabase) IsNone() bool

* * IsNone return if the mode is none * @return bool *

func (ModeDatabase) String

func (m ModeDatabase) String() string

* * String return string of mode database * @return string *

type Model

type Model struct {
	Schema               *Schema
	DB                   *DB
	Name                 string
	Tag                  string
	Table                string
	Description          string
	Columns              []*Column
	PrimaryKeys          []*Column
	ForeignKey           []*Constraint
	Index                []*Index
	Unique               []*Index
	RelationTo           []*Column
	Details              []*Column
	Hidden               []*Column
	Required             []*Column
	ColumnStatus         *Column
	ColumnSource         *Column
	ColumnCreatedTime    *Column
	ColumnUpdatedTime    *Column
	ColumnCreatedBy      *Column
	ColumnLastEditedTime *Column
	ColumnLastEditedBy   *Column
	ColumnProject        *Column
	ColumnSerie          *Column
	ColumnUUIndex        *Column
	BeforeInsert         []Trigger
	AfterInsert          []Trigger
	BeforeUpdate         []Trigger
	AfterUpdate          []Trigger
	BeforeDelete         []Trigger
	AfterDelete          []Trigger
	OnListener           Listener
	Integrity            bool
	DDL                  *DDL
	Version              int
}

* * Model is a struct for model *

func MOdel

func MOdel(def *Definition) *Model

func NewModel

func NewModel(schema *Schema, name, description string, version int) *Model

* * NewModel create a new model * @param schema *Schema * @param name string * @param description string * @param version int * @return *Model *

func (*Model) AddColumn

func (m *Model) AddColumn(col *Column)

* * AddColumn add a column to the model * @param col *Column *

func (*Model) AddForeignKey

func (m *Model) AddForeignKey(foreignKey []string, parentModel *Model, parentKey []string) *Constraint

* * AddForeignKey add foreign key column by name to the model * @param foreignKey []string * @param parentModel *Model * @param parentKey []string * @return *Constraint *

func (*Model) AddIndex

func (m *Model) AddIndex(name string, asc bool) *Column

* * AddIndex add index column by name to the model * @param name string * @param asc bool * @return *Column *

func (*Model) AddPrimaryKey

func (m *Model) AddPrimaryKey(name string) *Column

* * AddPrimaryKey add primary key column by name to the model * @param name string * @return *Column *

func (*Model) AddRelationTo

func (m *Model) AddRelationTo(col *Column)

* * AddRelationTo add relation to column to the model * @param col *Column *

func (*Model) AddUnique

func (m *Model) AddUnique(name string, asc bool) *Column

* * AddUnique add unique column by name to the model * @param name string * @param asc bool * @return *Column *

func (*Model) Avg

func (m *Model) Avg(col *Column, as string) *Linq

func (*Model) C

func (m *Model) C(name string) *Column

* * C short to find a column in the model * @param name string * @return *Column *

func (*Model) Col

func (m *Model) Col(name string) *Column

* * Col short to find a column in the model * @param name string * @return *Column *

func (*Model) Column

func (m *Model) Column(name string) *Column

* * Column add a column to the model * @param name string * @return *Column *

func (*Model) Count

func (m *Model) Count(col *Column, as string) *Linq

func (*Model) Data

func (m *Model) Data(sel ...interface{}) *Linq

Select SourceField a linq with data

func (*Model) DefineAtrib

func (m *Model) DefineAtrib(name, description string, typeData TypeData, _default interface{}) *Column

*

  • Define atrib define a atrib in the model
  • @param name string
  • @param description string
  • @param typeData TypeData
  • @param _default interface{}
  • @return *Column

*

func (*Model) DefineColumn

func (m *Model) DefineColumn(name, description string, typeData TypeData, _default interface{}) *Column

*

  • Define column define a column in the model
  • @param name string
  • @param description string
  • @param typeData TypeData
  • @param _default interface{}
  • @return *Column

*

func (*Model) DefineDetail

func (m *Model) DefineDetail(name, description string, _default interface{}, funcDetail FuncDetail) *Column

*

  • Define detail define a detail in the model
  • @param name string
  • @param description string
  • @param _default interface{}
  • @return *Column

*

func (*Model) DefineForeignKey

func (m *Model) DefineForeignKey(foreignKey []string, parentModel *Model, parentKey []string) *Model

*

  • Define foreign key in the model
  • @param foreignKey []string
  • @param parentModel *Model
  • @param parentKey []string
  • @return *Model

*

func (*Model) DefineFormula

func (m *Model) DefineFormula(name, formula string) *Column

*

  • Define formula in the model
  • @param name string
  • @param formula string
  • @return *Column

*

func (*Model) DefineHidden

func (m *Model) DefineHidden(cols []string) *Model

*

  • Define hidden columns in the model
  • @param cols []string
  • @return *Model

*

func (*Model) DefineIndex

func (m *Model) DefineIndex(name []string, asc bool) *Model

*

  • Define index in the model
  • @param name []string
  • @param asc bool
  • @return *Model

*

func (*Model) DefineIntegrity

func (m *Model) DefineIntegrity(integrity bool)

*

  • Define integrity in the model
  • @param integrity bool

*

func (*Model) DefinePrimaryKey

func (m *Model) DefinePrimaryKey(cols []string) *Model

*

  • Define primary key in the model
  • @param cols []string
  • @return *Model

*

func (*Model) DefineRequired

func (m *Model) DefineRequired(cols []ColRequired) *Model

*

  • Define required columns in the model
  • @param col string
  • @param msg string
  • @return *Model

*

func (*Model) DefineRollup

func (m *Model) DefineRollup(name string, foreignKey []string, parentModel *Model, parentKey []string, _select []string) *Column

*

  • Define rollup in the model
  • @param name string
  • @param foreignKey []string
  • @param parentModel *Model
  • @param parentKey []string
  • @param _select string
  • @return *Column

*

func (*Model) DefineTrigger

func (m *Model) DefineTrigger(event TypeTrigger, trigger Trigger)

*

  • Define trigger in the model
  • @param event TypeTrigger
  • @param trigger Trigger

*

func (*Model) DefineUnique

func (m *Model) DefineUnique(name string, asc bool) *Model

*

  • Define unique in the model
  • @param name string
  • @param asc bool
  • @return *Model

*

func (*Model) Delete

func (m *Model) Delete() *Linq

* * Delete method to use in linq * @return error *

func (*Model) Describe

func (m *Model) Describe() et.Json

* * Describe return a json with the definition of the model * @return et.Json *

func (*Model) Distinct

func (m *Model) Distinct() *Linq

func (*Model) GetMigrateId

func (m *Model) GetMigrateId(old_id string) (string, error)

* * GetMigrateId get migrate id * @param old_id string * @return string * @return error *

func (*Model) Init

func (m *Model) Init(db *DB) error

* * Init a model * @param db *DB * @return error *

func (*Model) Insert

func (m *Model) Insert(data et.Json) *Linq

* * Insert method to use in linq * @return error *

func (*Model) Kind

func (m *Model) Kind() string

* * Kind * @return string *

func (*Model) Max

func (m *Model) Max(col *Column, as string) *Linq

func (*Model) Min

func (m *Model) Min(col *Column, as string) *Linq

func (*Model) Select

func (m *Model) Select(sel ...interface{}) *Linq

Select columns to use in linq

func (*Model) Sum

func (m *Model) Sum(col *Column, as string) *Linq

func (*Model) UpSertMigrateId

func (m *Model) UpSertMigrateId(old_id, _id string) error

* * UpSertMigrateId upsert migrate id * @param old_id string * @param _id string * @return error *

func (*Model) Update

func (m *Model) Update(data et.Json) *Linq

* * Update method to use in linq * @return error *

type Relation

type Relation struct {
	ForeignKey []string
	Parent     *Model
	ParentKey  []string
	Select     []string
	Calculate  TpCaculate
	Limit      int
}

Relation is a struct for relation between models

func (*Relation) Describe

func (r *Relation) Describe() et.Json

Describe return a json with the definition of the relation

func (*Relation) Fkey

func (r *Relation) Fkey() string

Name return a valid key name of relation

func (*Relation) Pkey

func (r *Relation) Pkey() string

Pkey return a valid primary key name of relation

func (*Relation) SelectsAs

func (r *Relation) SelectsAs(l *Linq) string

SelectsAs return a string with the select columns

func (*Relation) Table

func (r *Relation) Table() string

Name return a valid name of relation

func (*Relation) WhereAs

func (r *Relation) WhereAs(l *Linq) string

WhereAs return a string with the where columns

type RelationTo

type RelationTo struct {
	PrimaryKey *Column
	ForeignKey *Column
}

* * RelationTo is a struct for relation to *

func (*RelationTo) Describe

func (r *RelationTo) Describe() et.Json

* * Describe return a json with the definition of the relation to * @return et.Json *

type Required

type Required struct {
	Required bool
	Message  string
}

func (*Required) Describe

func (r *Required) Describe() et.Json

Describe return a json with the definition of the required

type Schema

type Schema struct {
	Name        string
	Description string
	Models      []*Model
}

Schema struct used to define a schema in a database

func NewSchema

func NewSchema(name, description string) *Schema

NewSchema create a new schema

func (*Schema) AddModel

func (s *Schema) AddModel(model *Model)

* * AddModel add a model to the schema * @param model *Model *

func (*Schema) Describe

func (s *Schema) Describe() et.Json

* * Describe return a json with the schema description * @return et.Json *

func (*Schema) Kind

func (s *Schema) Kind() string

* * Kind * @return string *

func (*Schema) Low

func (s *Schema) Low() string

* * Low return the name of the schema in lowercase * @return string *

func (*Schema) Up

func (s *Schema) Up() string

* * Up return the name of the schema in uppercase * @return string *

type TRigger

type TRigger struct {
	TypeTrigger TypeTrigger
	Trigger     Trigger
}

type TpCaculate

type TpCaculate int

TpCaculate type for calculate

func (TpCaculate) Limit

func (t TpCaculate) Limit() int

Limit return limit of calculate

func (TpCaculate) String

func (t TpCaculate) String() string

String return string of type calculate

type Trigger

type Trigger func(model *Model, value *Values) error

* * Trigger is a function for trigger * @param model *Model * @param old et.Json * @param new et.Json * @param data et.Json * @return error *

type TypeColumn

type TypeColumn int

Type columns

const (
	TpColumn TypeColumn = iota
	TpAtrib
	TpDetail
	TpConcat
	TpOther
)

func (TypeColumn) String

func (t TypeColumn) String() string

String return string of type column

type TypeCommand

type TypeCommand int

TypeCommand struct to use in linq

const (
	Tpnone TypeCommand = iota
	TpInsert
	TpUpdate
	TpDelete
)

Values for TypeCommand

func (TypeCommand) String

func (d TypeCommand) String() string

String method to use in linq

type TypeData

type TypeData int
const (
	TpKey TypeData = iota
	TpText
	TpMemo
	TpInteger
	TpNumber
	TpSelect
	TpMultiSelect
	TpStatus
	TpDate // Date & Time
	TpPerson
	TpFile // files & media
	TpCheckbox
	TpURL   // URL
	TpEmail // Email
	TpPhone
	TpFormula  // Formula
	TpFunction // Function
	TpRollup   // Rollup (Enrollar) with other model
	TpCreatedTime
	TpCreatedBy
	TpLastEditedTime
	TpLastEditedBy
	TpProject
	TpSource
	TpJson
	TpArray
	TpSerie
	TpCode
	TpShape
	TpUUIndex
)

func (TypeData) Default

func (t TypeData) Default() interface{}

func (TypeData) Describe

func (t TypeData) Describe() *et.Json

func (TypeData) Indexed

func (t TypeData) Indexed() bool

func (TypeData) Mutate

func (t TypeData) Mutate(val interface{})

func (TypeData) String

func (t TypeData) String() string

type TypeDriver

type TypeDriver int
const (
	Postgres TypeDriver = iota
	Mysql
	Sqlite
	Oracle
	SQLServer
)

func StrToDriver

func StrToDriver(s string) TypeDriver

func (TypeDriver) String

func (d TypeDriver) String() string

* * String return the string of the driver * @return string *

type TypeJoin

type TypeJoin int
const (
	Inner TypeJoin = iota
	Left
	Right
)

func (TypeJoin) String

func (d TypeJoin) String() string

type TypeQuery

type TypeQuery int

* * TypeQuery, type of query *

const (
	TpQuery TypeQuery = iota
	TpCommand
	TpAll
	TpLast
	TpSkip
	TpPage
)

* * TypeQuery, type of query *

func (TypeQuery) String

func (d TypeQuery) String() string

* * TypeQuery, return string type of query *

type TypeShape

type TypeShape int
const (
	ShapePoint TypeShape = iota
	ShapeLine
	ShapePolygon
	ShapeMultiPart
)

func (TypeShape) String

func (t TypeShape) String() string

type TypeTrigger

type TypeTrigger int

* * TypeTrigger is a enum for trigger type *

const (
	BeforeInsert TypeTrigger = iota
	AfterInsert
	BeforeUpdate
	AfterUpdate
	BeforeDelete
	AfterDelete
)

func (TypeTrigger) String

func (t TypeTrigger) String() string

* * String return string of type trigger * @return string *

type TypeVar

type TypeVar int
const (
	IdTField TypeVar = iota
	SourceField
	IndexField
	StateField
)

Var field system name

func (TypeVar) Low

func (t TypeVar) Low() string

* * Low return lowcase to field system * @return string *

func (TypeVar) Up

func (t TypeVar) Up() string

* * Up return upcase to field system * @return string *

type Validation

type Validation func(col *Column, value interface{}) bool

Validation tipe function

type Value

type Value struct {
	Column *Column
	Old    interface{}
	New    interface{}
	Change bool
}

type Values

type Values struct {
	Linq        *Linq
	Model       *Model
	TypeCommand TypeCommand
	Data        et.Json
	Values      []*Value
	Change      bool
	History     bool
	IdT         string
	User        interface{}
	Project     interface{}
}

Command struct to use in linq

func (*Values) Default

func (l *Values) Default(col *Column) interface{}

* * Default return the default value of the column in command * @param col *Column * @return interface{} *

func (*Values) Delete

func (c *Values) Delete() error

* * Delete method to use in linq * @return error *

func (*Values) DeleteCascade

func (c *Values) DeleteCascade() error

* * DeleteCascade method to use in linq * @return error *

func (*Values) Describe

func (l *Values) Describe() et.Json

* * Describe returns a json with the definition of the command * @return et.Json *

func (*Values) Insert

func (c *Values) Insert() error

* * Insert method to use in linq * @return error *

func (*Values) IsDifferent

func (l *Values) IsDifferent(name string) bool

func (*Values) New

func (l *Values) New(def interface{}, name string) interface{}

* * New return the new value of the column in command * @param def interface{} * @param name string * @return interface{} *

func (*Values) News

func (v *Values) News() et.Json

* * New returns a json with the new values of the command * @return et.Json *

func (*Values) Old

func (l *Values) Old(def interface{}, name string) interface{}

* * Old return the old value of the column in command * @param def interface{} * @param name string * @return interface{} *

func (*Values) Olds

func (v *Values) Olds() et.Json

* * Old returns a json with the old values of the command * @return et.Json *

func (*Values) Set

func (l *Values) Set(col interface{}, value interface{})

* * Set values to command * @param col interface{} * @param value interface{} *

func (*Values) Update

func (c *Values) Update() error

* * Update method to use in linq * @return error *

func (*Values) UpdateCascade

func (c *Values) UpdateCascade() error

* * UpdateCascade method to use in linq * @return error *

Jump to

Keyboard shortcuts

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