sql

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 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 JoinToKeyValue

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

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

func JoinToMap

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

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

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 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 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       []et.Json       `json:"from"`
	Conditions []*Condition    `json:"conditions"`
	Selects    []string        `json:"selects"`
	Joins      []string        `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) *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) 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(fields ...string) *Where

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

func (*Where) Last

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

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

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) 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