sql

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorFieldNotFound = errors.New(msg.MSG_FIELD_NOT_FOUND)
	ErrorDataNotFound  = errors.New(msg.MSG_DATA_NOT_FOUND)
)

Functions

func MergeToKeyValue added in v1.0.20

func MergeToKeyValue(left []et.Json, key string, value any) []et.Json

* * MergeToKeyValue * @params left []et.Json, key string, value any * @return []et.Json *

func MergeToMap added in v1.0.20

func MergeToMap(left, right []et.Json) []et.Json

* * MergeToMap * @params left, right []et.Json * @return []et.Json *

func Prefixer added in v1.0.20

func Prefixer(item et.Json, as string) et.Json

* * Prefixer * @param from *Source * @return *Source *

func Validate

func Validate(item et.Json, conditions []*Condition) bool

* * Validate * @param item et.Json, conditions []*Condition * @return bool *

Types

type BetweenValue

type BetweenValue struct {
	Min any `json:"Min"`
	Max any `json:"Max"`
}

type Command

type Command string
const (
	INSERT Command = "insert"
	UPDATE Command = "update"
	DELETE Command = "delete"
	UPSERT Command = "upsert"
	FROM   Command = "from"
)

type Condition

type Condition struct {
	Field     string    `json:"field"`
	Operator  Operator  `json:"operator"`
	Value     any       `json:"value"`
	Connector Connector `json:"connector"`
}

func Between

func Between(field string, min, max any) *Condition

* * Between * @param field string, min any, max any * @return Condition *

func Eq

func Eq(field string, value interface{}) *Condition

* * Eq * @param field string, value interface{} * @return Condition *

func In

func In(field string, value []interface{}) *Condition

* * In * @param field string, value []interface{} * @return Condition *

func Is

func Is(field string, value interface{}) *Condition

* * Is * @param field string, value interface{} * @return Condition *

func IsNot

func IsNot(field string, value interface{}) *Condition

* * IsNot * @param field string, value interface{} * @return Condition *

func Less

func Less(field string, value interface{}) *Condition

* * Less * @param field string, value interface{} * @return Condition *

func LessEq

func LessEq(field string, value interface{}) *Condition

* * LessEq * @param field string, value interface{} * @return Condition *

func Like

func Like(field string, value interface{}) *Condition

* * Like * @param field string, value interface{} * @return Condition *

func More

func More(field string, value interface{}) *Condition

* * More * @param field string, value interface{} * @return Condition *

func MoreEq

func MoreEq(field string, value interface{}) *Condition

* * MoreEq * @param field string, value interface{} * @return Condition *

func Neg

func Neg(field string, value interface{}) *Condition

* * Neg * @param field string, value interface{} * @return Condition *

func NotBetween

func NotBetween(field string, min, max any) *Condition

* * NotBetween * @param field string, min any, max any * @return Condition *

func NotIn

func NotIn(field string, value []interface{}) *Condition

* * NotIn * @param field string, value []interface{} * @return Condition *

func NotNull

func NotNull(field string) *Condition

* * NotNull * @param field string * @return Condition *

func Null

func Null(field string) *Condition

* * Null * @param field string * @return Condition *

func ToCondition

func ToCondition(json et.Json) *Condition

* * ToCondition * @param json et.Json * @return *Condition *

func (*Condition) ApplyToIndex

func (s *Condition) ApplyToIndex(keys []string) []string

* * ApplyToIndex * @param keys []string * @return []string *

func (*Condition) ApplyToObject

func (s *Condition) ApplyToObject(obj et.Json) bool

* * ApplyToObject * @param obj et.Json * @return bool *

func (*Condition) ApplyToValue

func (s *Condition) ApplyToValue(val any) bool

* * ApplyToValue * @param val any * @return bool *

func (*Condition) ToJson

func (s *Condition) ToJson() et.Json

* * ToJson * @return et.Json *

type Connector

type Connector string
const (
	NaC Connector = ""
	And Connector = "and"
	Or  Connector = "or"
)

func (Connector) Str

func (s Connector) Str() string

type Iterator added in v1.0.20

type Iterator interface {
	Next() (et.Json, bool)
	As() string
	Add(item et.Json)
	Data(int) et.Json
}

func Joingy added in v1.0.20

func Joingy(left, right Iterator, keys map[string]string, joinType JoinType) Iterator

* * Joingy * @params left, right Iterator, keys map[string]string, joinType JoinType * @return Iterator *

type Join added in v1.0.20

type Join struct {
	To   Iterator          `json:"to"`
	Keys map[string]string `json:"keys"`
	Type JoinType          `json:"type"`
}

type JoinType added in v1.0.20

type JoinType int
const (
	InnerJoin JoinType = iota
	LeftJoin
	RightJoin
	FullJoin
)

func (JoinType) String added in v1.0.20

func (j JoinType) String() string

* * String * @return string *

type Model

type Model struct {
	Host     string   `json:"host"`
	Database string   `json:"database"`
	Schema   string   `json:"schema"`
	Name     string   `json:"name"`
	Hidden   []string `json:"hidden"`
	IdxField string   `json:"idx_field"`
	// contains filtered or unexported fields
}

func (*Model) GetIndex

func (s *Model) GetIndex(field, key string, dest map[string]bool) (bool, error)

func (*Model) GetObjet

func (s *Model) GetObjet(idx string, dest et.Json) (bool, error)

func (*Model) Key

func (s *Model) Key() string

* * Key * @return string *

func (*Model) Next

func (s *Model) Next(fn func(idx string, item et.Json) (bool, error), asc bool, offset, limit, workers int) error

func (*Model) OnGetIndex

func (s *Model) OnGetIndex(getIndexFn func(field, key string, dest map[string]bool) (bool, error))

func (*Model) OnGetObject

func (s *Model) OnGetObject(getObjectFn func(idx string, dest et.Json) (bool, error))

func (*Model) OnNext

func (s *Model) OnNext(nextFn func(fn func(idx string, item et.Json) (bool, error), asc bool, offset, limit, workers int) error)

type NextFn

type NextFn func(fn func(idx string, item et.Json) (bool, error), asc bool, offset, limit, workers int) error

type Operator

type Operator string
const (
	OpEq         Operator = "eq"
	OpNeg        Operator = "neg"
	OpLess       Operator = "less"
	OpLessEq     Operator = "less_eq"
	OpMore       Operator = "more"
	OpMoreEq     Operator = "more_eq"
	OpLike       Operator = "like"
	OpIn         Operator = "in"
	OpNotIn      Operator = "not_in"
	OpIs         Operator = "is"
	OpIsNot      Operator = "is_not"
	OpNull       Operator = "null"
	OpNotNull    Operator = "not_null"
	OpBetween    Operator = "between"
	OpNotBetween Operator = "not_between"
)

func ToOperator

func ToOperator(s string) Operator

func (Operator) Str

func (s Operator) Str() string

type Source added in v1.0.20

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

func (*Source) Add added in v1.0.20

func (s *Source) Add(item et.Json)

* * Add * @param item et.Json *

func (*Source) As added in v1.0.20

func (s *Source) As() string

* * As * @return string *

func (*Source) Data added in v1.0.20

func (s *Source) Data(index int) et.Json

* * Data * @param index int * @return et.Json *

func (*Source) Next added in v1.0.20

func (s *Source) Next() (et.Json, bool)

* * Next * @return (et.Json, bool) *

type Status

type Status string
const (
	Active       Status = "active"
	Archived     Status = "archived"
	Canceled     Status = "canceled"
	OfSystem     Status = "of_system"
	ForDelete    Status = "for_delete"
	Pending      Status = "pending"
	Approved     Status = "approved"
	Rejected     Status = "rejected"
	Failed       Status = "failed"
	Processed    Status = "processed"
	Connected    Status = "connected"
	Disconnected Status = "disconnected"
)

type Transaction

type Transaction struct {
	Model   *Model             `json:"from"`
	Command Command            `json:"command"`
	Data    map[string]et.Json `json:"data"`
	Status  Status             `json:"status"`
}

type Tx

type Tx struct {
	StartedAt    time.Time      `json:"startedAt"`
	LastUpdateAt time.Time      `json:"lastUpdateAt"`
	ID           string         `json:"id"`
	Transactions []*Transaction `json:"transactions"`
	// contains filtered or unexported fields
}

func GetTx

func GetTx(tx *Tx) (*Tx, bool)

* * GetTx: Returns the Transaction for the session * @param tx *Tx * @return (*Tx, bool) *

func (*Tx) AddTransaction

func (s *Tx) AddTransaction(from *Model, cmd Command, idx string, data et.Json) error

* * AddTransaction: Adds data to the Transaction * @param from *Model, cmd Command, idx string, data et.Json *

func (*Tx) GetCache

func (s *Tx) GetCache(from *Model) []et.Json

* * getCache: Returns the data for the from * @param from *Model * @return []et.Json *

func (*Tx) OnChange

func (s *Tx) OnChange(fn func(*Tx) error)

* * OnChange * @params fn func(*Tx) error *

func (*Tx) SetStatus

func (s *Tx) SetStatus(idx int, status Status) error

* * SetStatus: Sets the status of a transaction * @param idx int, status Status * @return error *

func (*Tx) ToJson

func (s *Tx) ToJson() (et.Json, error)

* * ToJson * @return et.Json, error *

type Where

type Where struct {
	From       Iterator        `json:"from"`
	Conditions []*Condition    `json:"conditions"`
	Selects    []string        `json:"selects"`
	Joins      []*Join         `json:"joins"`
	Hiddens    []string        `json:"hiddens"`
	OrderBy    map[string]bool `json:"order_by"`
	Offset     int             `json:"offset"`
	Limits     int             `json:"limits"`
	Workers    int             `json:"workers"`
	Result     []et.Json       `json:"result"`
	// contains filtered or unexported fields
}

* * Where *

func From

func From(itmes []et.Json, as string) *Where

func (*Where) Add

func (s *Where) Add(condition *Condition) *Where

* * Add * @param condition *Condition * @return *Where *

func (*Where) AdddResult

func (s *Where) AdddResult(item et.Json) (next bool)

* * AdddResult * @return next bool *

func (*Where) And

func (s *Where) And(condition *Condition) *Where

* * And * @param condition *Condition * @return *Where *

func (*Where) Asc

func (s *Where) Asc(field string) *Where

* * Asc * @param field string * @return *Where *

func (*Where) Desc

func (s *Where) Desc(field string) *Where

* * Desc * @param field string * @return *Where *

func (*Where) First

func (s *Where) First(tx *Tx) et.Json

* * First * @param tx *Tx * @return et.Json, error *

func (*Where) FullJoin added in v1.0.20

func (s *Where) FullJoin(to []et.Json, as string, keys map[string]string) *Where

* * FullJoin * @param to []et.Json, as string, keys map[string]string * @return *Where *

func (*Where) Hidden

func (s *Where) Hidden(fields ...string) *Where

* * Hidden * @param fields ...string * @return *Where *

func (*Where) IsDebug

func (s *Where) IsDebug() *Where

* * IsDebug: Returns the debug mode * @return *Where *

func (*Where) Join

func (s *Where) Join(to []et.Json, as string, keys map[string]string) *Where

* * Join * @param to []et.Json, as string, keys map[string]string * @return *Where *

func (*Where) Last

func (s *Where) Last(tx *Tx) et.Json

* * Last * @param tx *Tx * @return et.Json, error *

func (*Where) LeftJoin added in v1.0.20

func (s *Where) LeftJoin(to []et.Json, as string, keys map[string]string) *Where

* * LeftJoin * @param to []et.Json, as string, keys map[string]string * @return *Where *

func (*Where) Limit

func (s *Where) Limit(page int, rows int) *Where

* * Limit * @param page int, rows int * @return *Where *

func (*Where) One

func (s *Where) One(tx *Tx, idx int) et.Json

* * One * @param tx *Tx * @return et.Json, error *

func (*Where) Or

func (s *Where) Or(condition *Condition) *Where

* * Or * @param condition *Condition * @return *Where *

func (*Where) Order

func (s *Where) Order(field string, asc bool) *Where

* * Order * @param field string * @return *Where *

func (*Where) RightJoin added in v1.0.20

func (s *Where) RightJoin(to []et.Json, as string, keys map[string]string) *Where

* * RightJoin * @param to []et.Json, as string, keys map[string]string * @return *Where *

func (*Where) Run

func (s *Where) Run(tx *Tx) []et.Json

* * Run * @param tx *Tx * @return []et.Json, error *

func (*Where) Select

func (s *Where) Select(fields ...string) *Where

* * Select * @param fields ...string * @return *Where *

func (*Where) ToJson

func (s *Where) ToJson() (et.Json, error)

* * ToJson * @return et.Json *

func (*Where) Where

func (s *Where) Where(condition *Condition) *Where

* * Where * @param condition *Condition * @return *Where *

Jump to

Keyboard shortcuts

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