Pg

package
v1.4812.1501 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ROWS_MAX_LIMIT = 2000
View Source
const SQL_FUNCTIONS = `` /* 3327-byte string literal not displayed */
View Source
const TTL = 3

Variables

View Source
var CACHE *cmap.CMap // cache real storage
View Source
var CACHE_BORN *cmap.CMap // cache born time
View Source
var CACHE_INV *cmap.CMap // table invalidate date
View Source
var CACHE_TTL *cmap.CMap // cache invalidate time
View Source
var DEBUG bool
View Source
var FORM_CACHE *cmap.CMap // cache form fields
View Source
var GRID_CACHE *cmap.CMap // cache grid fields
View Source
var OFFICE_MAIL_SUFFIX string
View Source
var SELECT_CACHE *cmap.CMap
View Source
var SELECT_NOJOIN_CACHE *cmap.CMap
View Source
var SESSION_DBACTOR_ID = int64(1)
View Source
var SESSION_EXPIRY_KEY = `expired_at`
View Source
var SESSION_VALUE_KEY = `value`
View Source
var TYPE_CACHE *cmap.CMap // cache key-type (M.SS)
View Source
var Z func(string) string
View Source
var ZI func(int64) string
View Source
var ZJ func(string) string
View Source
var ZJLIKE func(string) string
View Source
var ZLIKE func(string) string
View Source
var ZS func(string) string
View Source
var ZZ func(string) string

Functions

func Connect1

func Connect1(user, pass, host, dbName string, port, maxConn int) *pgxpool.Pool

func GenInsert

func GenInsert(table string, kvparams M.SX) (string, []any)

generate insert, requires table name and field-value params

func GenUpdateId

func GenUpdateId(table string, id int64, kvparams M.SX) (string, []any)

generate update, requires table name, id and field-value params

func GenUpdateWhere

func GenUpdateWhere(table, where string, kvparams M.SX) (string, []any)

generate update, requires table, id and

func InitFunctions

func InitFunctions(conn *RDBMS)

func InitOfficeMail

func InitOfficeMail(suffix string)

func RamDel_ByQuery

func RamDel_ByQuery(ram_key, query string)

func RamExpired_ByBucket_ByKey

func RamExpired_ByBucket_ByKey(bucket, ram_key string) bool

func RamGetAI

func RamGetAI(ram_key, query string) ([]int64, bool)

func RamGetAMSX

func RamGetAMSX(ram_key, query string) (A.MSX, bool)

func RamGetAS

func RamGetAS(ram_key, query string) ([]string, bool)

func RamGetBool

func RamGetBool(ram_key, query string) (bool, bool)

func RamGetFloat

func RamGetFloat(ram_key, query string) (float64, bool)

func RamGetInt

func RamGetInt(ram_key, query string) (int64, bool)

func RamGetMIS

func RamGetMIS(ram_key, query string) (M.IS, bool)

func RamGetMSS

func RamGetMSS(ram_key, query string) (M.SS, bool)

func RamGetMSX

func RamGetMSX(ram_key, query string) (M.SX, bool)

func RamGetStr

func RamGetStr(ram_key, query string) (string, bool)

func RamGet_ByRamKey_ByQuery

func RamGet_ByRamKey_ByQuery(ram_key, query string) any

returns false when cache expired

func RamGlobalEvict_ByAjax_ByBucket

func RamGlobalEvict_ByAjax_ByBucket(ajax W.Ajax, bucket string)

func RamGlobalEvict_ByBucket

func RamGlobalEvict_ByBucket(bucket string)

func RamSetAI

func RamSetAI(bucket, key, query string, val []int64, sec int64) []int64

[]STRING only set when not yet being set, preventing double write and double delete

func RamSetAMSX

func RamSetAMSX(bucket, key, query string, val A.MSX, sec int64) A.MSX

A.MSX only set when not yet being set, preventing double write and double delete

func RamSetAS

func RamSetAS(bucket, key, query string, val []string, sec int64) []string

[]STRING only set when not yet being set, preventing double write and double delete

func RamSetBool

func RamSetBool(bucket, key, query string, val bool, sec int64) bool

BOOL only set when not yet being set, preventing double write and double delete

func RamSetFloat

func RamSetFloat(bucket, key, query string, val float64, sec int64) float64

FLOAT64 only set when not yet being set, preventing double write and double delete

func RamSetInt

func RamSetInt(bucket, key, query string, val int64, sec int64) int64

INT64 only set when not yet being set, preventing double write and double delete

func RamSetMIS

func RamSetMIS(bucket, key, query string, val M.IS, sec int64) M.IS

MAP[INT64]STRING only set when not yet being set, preventing double write and double delete

func RamSetMSS

func RamSetMSS(bucket, key, query string, val M.SS, sec int64) M.SS

MAP[STRING]STRING only set when not yet being set, preventing double write and double delete

func RamSetMSX

func RamSetMSX(bucket, ram_key, query string, val M.SX, sec int64) M.SX

M.SX only set when not yet being set, preventing double write and double delete

func RamSetStr

func RamSetStr(bucket, key, query string, val string, sec int64) string

STRING only set when not yet being set, preventing double write and double delete

func RamSet_ByBucket_ByRamKey_ByQuery

func RamSet_ByBucket_ByRamKey_ByQuery(bucket, ram_key, query string, val any, sec int64)

Types

type Adapter

type Adapter struct {
	*pgxpool.Pool
	Reconnect func() *pgxpool.Pool
}

type Base

type Base struct {
	Id         int64 `db:"id"`
	Table      string
	Connection *RDBMS
	UniqueId   sql.NullString `db:"unique_id"`
	CreatedAt  pq.NullTime    `db:"created_at"`
	UpdatedAt  pq.NullTime    `db:"updated_at"`
	DeletedAt  pq.NullTime    `db:"deleted_at"`
	RestoredAt pq.NullTime    `db:"restored_at"`
	ModifiedAt pq.NullTime    `db:"modified_at"`
	CreatedBy  sql.NullInt64  `db:"created_by"`
	UpdatedBy  sql.NullInt64  `db:"updated_by"`
	DeletedBy  sql.NullInt64  `db:"deleted_by"`
	RestoredBy sql.NullInt64  `db:"restored_by"`
	IsDeleted  bool           `db:"is_deleted"`
	DataStr    string         `db:"data"` // json object
	XData      M.SX
}

base structure for all model, including schema

func (*Base) DataToMap

func (b *Base) DataToMap() M.SX

func (*Base) Delete

func (b *Base) Delete(actor int64) bool

2016-05-25 delete row, TODO: add DeletedAt

func (*Base) GetArr

func (b *Base) GetArr(key string) []any

get []any from Data

func (*Base) GetBool

func (b *Base) GetBool(key string) bool

get boolean from Data

func (*Base) GetFloat

func (b *Base) GetFloat(key string) float64

get float64 from Data

func (*Base) GetId

func (b *Base) GetId() int64

get id

func (*Base) GetInt

func (b *Base) GetInt(key string) int64

get int64 from Data

func (*Base) GetMSX

func (b *Base) GetMSX(key string) M.SX

get string from Data

func (*Base) GetStr

func (b *Base) GetStr(key string) string

get string from Data

func (*Base) GetUniqueId

func (b *Base) GetUniqueId() string

get unique id

func (*Base) MapToData

func (b *Base) MapToData() string

func (*Base) Restore

func (b *Base) Restore(actor int64) bool

2016-05-25 restore row, TODO: add RestoredAt

func (*Base) Save

func (b *Base) Save(actor int64) bool

2015-08-27 also update unique_id

func (*Base) SetVal

func (b *Base) SetVal(key string, val any)

type FieldModel

type FieldModel struct {
	Label       string // label in form, and grid
	HtmlLabel   string // label for both form and grid
	FormLabel   string // label in form
	GridLabel   string // label in grid
	GridFooter  string // footer in grid, sum
	FormTooltip string // placeholder in form
	Key         string // key in the table.data
	Type        string // for formatting sql, form, and grid: float2, integer, datetime
	SqlType     string // for overriding sql format: bigint, float
	FormType    string // for overriding form format
	GridType    string // for overriding grid format
	HtmlSubType string // for checkbox example: 'True':'False', for select: DS.DataSourceName
	Hide        bool   // for hiding in sql, form, and grid
	SqlHide     bool   // for overriding sql hide status
	HtmlHide    bool   // for hiding both form and grid
	FormHide    bool   // for overriding form hide status
	GridHide    bool   // for overriding grid hide status
	Required    bool
	CustomQuery string
	Default     string // default value
	Min         string // minimum value
	Max         string // maximum value
	SqlColPos   int    // position on SQL Select
	NotDataCol  bool   // is it data->>'col_name' (default) or .col_name (true), overriden by: id, is_deleted, unique_id, modified_*, created_*, deleted_*, restored_*, updated_* where * = at or by
}

func (*FieldModel) SqlColumn

func (field *FieldModel) SqlColumn() string

type PgDockerTest

type PgDockerTest struct {
	User     string
	Password string
	Database string
	Image    string

	Port string
	DSN  string
	// contains filtered or unexported fields
}

func (*PgDockerTest) ConnectCheck

func (in *PgDockerTest) ConnectCheck(res *dockertest.Resource) (conn *pgx.Conn, err error)

func (*PgDockerTest) Image96

func (in *PgDockerTest) Image96(pool *D.DockerTest) *dockertest.RunOptions

func (*PgDockerTest) ImageLatest

func (in *PgDockerTest) ImageLatest(pool *D.DockerTest) *dockertest.RunOptions

func (*PgDockerTest) ImageVersion

func (in *PgDockerTest) ImageVersion(pool *D.DockerTest, version string) *dockertest.RunOptions

https://hub.docker.com/_/postgres

func (*PgDockerTest) SetDefaults

func (in *PgDockerTest) SetDefaults(img string)

type PostgreSession

type PostgreSession struct {
	Pool  *RDBMS
	Table string
}

func NewSession

func NewSession(conn *RDBMS, table, users_table string) *PostgreSession

func (PostgreSession) Del

func (sess PostgreSession) Del(key string)

func (PostgreSession) Expiry

func (sess PostgreSession) Expiry(key string) int64

func (PostgreSession) FadeInt

func (sess PostgreSession) FadeInt(key string, val int64, sec int64)

func (PostgreSession) FadeMSX

func (sess PostgreSession) FadeMSX(key string, val M.SX, sec int64)

func (PostgreSession) FadeStr

func (sess PostgreSession) FadeStr(key, val string, sec int64)

func (PostgreSession) FadeVal

func (sess PostgreSession) FadeVal(key string, val any, sec int64)

func (PostgreSession) GetInt

func (sess PostgreSession) GetInt(key string) int64

func (PostgreSession) GetMSX

func (sess PostgreSession) GetMSX(key string) M.SX

func (PostgreSession) GetStr

func (sess PostgreSession) GetStr(key string) string

func (PostgreSession) Inc

func (sess PostgreSession) Inc(key string) (ival int64)

func (PostgreSession) Product

func (sess PostgreSession) Product() string

func (PostgreSession) SetInt

func (sess PostgreSession) SetInt(key string, val int64)

func (PostgreSession) SetMSX

func (sess PostgreSession) SetMSX(key string, val M.SX)

func (PostgreSession) SetStr

func (sess PostgreSession) SetStr(key, val string)

func (PostgreSession) SetVal

func (sess PostgreSession) SetVal(key string, val any)

type QueryParams

type QueryParams struct {
	Term      string
	Offset    int64
	Limit     int64
	Count     int64
	Order     []string
	Rows      A.MSX
	Filter    M.SX
	Model     *TableModel
	IsDefault bool

	WithAs  string
	Where   string
	Select  string
	RamKey  string
	From    string
	Join    string
	OrderBy string
}

2017-01-25 Prayogo

func NewQueryParams

func NewQueryParams(posts *W.Posts, model *TableModel) *QueryParams

func (*QueryParams) SearchQuery_ByConn

func (qp *QueryParams) SearchQuery_ByConn(conn *RDBMS)

func (*QueryParams) ToAjax

func (qp *QueryParams) ToAjax(ajax W.Ajax)

func (*QueryParams) ToMSX

func (qp *QueryParams) ToMSX(m M.SX)

type RDBMS

type RDBMS struct {
	Name    string
	Adapter *sqlx.DB
}

wrapper for GO's sql.DB

func NewConn

func NewConn(user, db string) *RDBMS

create new postgresql connection to localhost

func (*RDBMS) CQBool

func (db *RDBMS) CQBool(bucket, ram_key, query string) bool

query and cache bool for TTL seconds

func (*RDBMS) CQFirstMap

func (db *RDBMS) CQFirstMap(bucket, ram_key, query string) M.SX

query and cache M.SX for TTL seconds

func (*RDBMS) CQFloat

func (db *RDBMS) CQFloat(bucket, ram_key, query string) float64

Query and cache float64 for TTL seconds

func (*RDBMS) CQInt

func (db *RDBMS) CQInt(bucket, ram_key, query string) int64

query and cache int64 for TTL seconds

func (*RDBMS) CQIntArr

func (db *RDBMS) CQIntArr(bucket, ram_key, query string) []int64

query and cache []int64 for TTL seconds

func (*RDBMS) CQIntStrMap

func (db *RDBMS) CQIntStrMap(bucket, ram_key, query string) map[int64]string

query and cache map[int64]string for TTL seconds

func (*RDBMS) CQMapArray

func (db *RDBMS) CQMapArray(bucket, ram_key, query string) A.MSX

query and cache AMSX for TTL seconds

func (*RDBMS) CQStr

func (db *RDBMS) CQStr(bucket, ram_key, query string) string

query and cache string for TTL seconds

func (*RDBMS) CQStrArr

func (db *RDBMS) CQStrArr(bucket, ram_key, query string) []string

query and cache []string for TTL seconds

func (*RDBMS) CQStrMapMap

func (db *RDBMS) CQStrMapMap(bucket, ram_key, index, query string) M.SX

query and cache M.SX for TTL seconds

func (*RDBMS) CQStrStrMap

func (db *RDBMS) CQStrStrMap(bucket, ram_key, query string) map[string]string

query and cache map[string]string for TTL seconds

func (*RDBMS) CTQBool

func (db *RDBMS) CTQBool(ttl int64, bucket, ram_key, query string) bool

query and cache bool for TTL seconds

func (*RDBMS) CTQFirstMap

func (db *RDBMS) CTQFirstMap(ttl int64, bucket, ram_key, query string) M.SX

query and cache M.SX for TTL seconds

func (*RDBMS) CTQFloat

func (db *RDBMS) CTQFloat(ttl int64, bucket, ram_key, query string) float64

Query and cache float64 for TTL seconds

func (*RDBMS) CTQInt

func (db *RDBMS) CTQInt(ttl int64, bucket, ram_key, query string) int64

query and cache int64 for TTL seconds

func (*RDBMS) CTQIntArr

func (db *RDBMS) CTQIntArr(ttl int64, bucket, ram_key, query string) []int64

query and cache []int64 for TTL seconds

func (*RDBMS) CTQIntStrMap

func (db *RDBMS) CTQIntStrMap(ttl int64, bucket, ram_key, query string) map[int64]string

query and cache map[int64]string for TTL seconds

func (*RDBMS) CTQMapArray

func (db *RDBMS) CTQMapArray(ttl int64, bucket, ram_key, query string) A.MSX

query and cache AMSX for TTL seconds

func (*RDBMS) CTQStr

func (db *RDBMS) CTQStr(ttl int64, bucket, ram_key, query string) string

query and cache string for TTL seconds

func (*RDBMS) CTQStrArr

func (db *RDBMS) CTQStrArr(ttl int64, bucket, ram_key, query string) []string

query and cache []string for TTL seconds

func (*RDBMS) CTQStrMapMap

func (db *RDBMS) CTQStrMapMap(ttl int64, bucket, ram_key, index, query string) M.SX

query and cache M.SX for TTL seconds

func (*RDBMS) CTQStrStrMap

func (db *RDBMS) CTQStrStrMap(ttl int64, bucket, ram_key, query string) map[string]string

query and cache map[string]string for TTL seconds

func (*RDBMS) CreateBaseTable

func (db *RDBMS) CreateBaseTable(name, users_table string)

create a base table

func (*RDBMS) DoDelete

func (db *RDBMS) DoDelete(actor int64, table string, id int64) (ok bool)

delete base table

func (*RDBMS) DoDelete2

func (db *RDBMS) DoDelete2(actor int64, table string, id int64, lambda func(base D.Record) string, ajax W.Ajax) bool

execute delete (is_deleted = true)

func (*RDBMS) DoInsert

func (db *RDBMS) DoInsert(actor int64, table string, kvparams M.SX) (id int64)

generate insert command and execute it

func (*RDBMS) DoRestore

func (db *RDBMS) DoRestore(actor int64, table string, id int64) (ok bool)

restore base table

func (*RDBMS) DoRestore2

func (db *RDBMS) DoRestore2(actor int64, table string, id int64, lambda func(base D.Record) string, ajax W.Ajax) bool

execute delete (is_deleted = false)

func (*RDBMS) DoTransaction

func (db *RDBMS) DoTransaction(lambda func(tx *Tx) string)

begin, commit transaction and rollback automatically when there are error

func (*RDBMS) DoUpdate

func (db *RDBMS) DoUpdate(actor int64, table string, id int64, kvparams M.SX) (ra int64)

generate update command and execute it

func (*RDBMS) DoUpsert

func (db *RDBMS) DoUpsert(actor int64, table string, kvparams M.SX) (id int64)

generate insert or update command and execute it

func (*RDBMS) DoWipeUnwipe

func (db *RDBMS) DoWipeUnwipe(a string, actor int64, table string, id int64) bool

delete or restore

func (*RDBMS) FixSerialSequence

func (db *RDBMS) FixSerialSequence(table string)

reset sequence, to be called after TRUNCATE TABLE tablename

func (*RDBMS) InitTrigger

func (db *RDBMS) InitTrigger()

init trigger

func (*RDBMS) JsonRow

func (db *RDBMS) JsonRow(table string, id int64, lambda func(rec D.Record) string) W.Ajax

2015-12-04 Kiz: replacement for JsonLine lambda should return empty string if it's correct row

func (*RDBMS) QAll

func (db *RDBMS) QAll(query string, params ...any) (rows Records)

do query all, also calls DoPrepare, don't forget to close the rows

func (*RDBMS) QArray

func (db *RDBMS) QArray(query string, params ...any) A.X

query any number of columns, returns array of slice (to be exported directly to json, not for processing)

func (*RDBMS) QBase

func (db *RDBMS) QBase(table string, id int64) (base Base)

fetch a row to as Base struct

func (*RDBMS) QBaseUniq

func (db *RDBMS) QBaseUniq(table, uid string) (base Base)

fetch a row to Base struct by unique_id

func (*RDBMS) QBool

func (db *RDBMS) QBool(query string, params ...any) (dest bool)

execute a select single value query, convert to int64

func (*RDBMS) QCount

func (db *RDBMS) QCount(query string) (dest int64)

query count from a table

func (*RDBMS) QExists

func (db *RDBMS) QExists(table string, id int64) (ex bool)

check if id exists

func (*RDBMS) QFirstArray

func (db *RDBMS) QFirstArray(query string, params ...any) A.X

query any number of columns, returns first line of line

func (*RDBMS) QFirstMap

func (db *RDBMS) QFirstMap(query string, params ...any) M.SX

query any number of columns, returns first line of line

func (*RDBMS) QFloat

func (db *RDBMS) QFloat(query string, params ...any) (dest float64)

func (*RDBMS) QId

func (db *RDBMS) QId(table, key string) (id int64)

check if unique exists

func (*RDBMS) QInt

func (db *RDBMS) QInt(query string, params ...any) (dest int64)

execute a select single value query, convert to int64

func (*RDBMS) QIntArr

func (db *RDBMS) QIntArr(query string, params ...any) []int64

query 1 colums of integer

func (*RDBMS) QIntBoolMap

func (db *RDBMS) QIntBoolMap(query string, params ...any) M.IB

query single column int64, return with true value

func (*RDBMS) QIntCountMap

func (db *RDBMS) QIntCountMap(query string, params ...any) M.II

query 1 colums of integer as map

func (*RDBMS) QIntIntMap

func (db *RDBMS) QIntIntMap(query string, params ...any) M.II

query 2 colums of integer-integer as map SELECT id, COUNT(*)

func (*RDBMS) QIntStr

func (db *RDBMS) QIntStr(query string, params ...any) (i int64, s string)

execute a select pair query, convert to int64 and string

func (*RDBMS) QIntStrMap

func (db *RDBMS) QIntStrMap(query string, params ...any) M.IS

query 2 colums of integer-string as map SELECT id, unique_id

func (*RDBMS) QJsonIntArr

func (db *RDBMS) QJsonIntArr(query string, params ...any) []int64

query one cell [1,2,3,...] and return array of int64

func (*RDBMS) QMapArray

func (db *RDBMS) QMapArray(query string, params ...any) A.MSX

query any number of columns, returns array of slice (to be exported directly to json, not for processing)

func (*RDBMS) QStr

func (db *RDBMS) QStr(query string, params ...any) (dest string)

execute a select single value query, convert to string

func (*RDBMS) QStrArr

func (db *RDBMS) QStrArr(query string, params ...any) []string

query 1 colums of string

func (*RDBMS) QStrArrMap

func (db *RDBMS) QStrArrMap(query string, params ...any) M.SAX

query 1+N columns of string-[]any as map

func (*RDBMS) QStrBoolMap

func (db *RDBMS) QStrBoolMap(query string, params ...any) M.SB

query 1 colums of string as map SELECT unique_id

func (*RDBMS) QStrCountMap

func (db *RDBMS) QStrCountMap(query string, params ...any) M.SI

query 1 colums of string as map result equal to: SELECT name, COUNT(*) FROM tabel1 GROUP BY 1 map[string]int

func (*RDBMS) QStrIdxArrMap

func (db *RDBMS) QStrIdxArrMap(key_idx int64, query string, params ...any) M.SAX

query any number of columns, returns map of string, array (to be exported directly to json, not for processing) the key_idx will be converted to string and taken as key

func (*RDBMS) QStrInt

func (db *RDBMS) QStrInt(query string, params ...any) (s string, i int64)

execute a select pair query, convert to string and int64

func (*RDBMS) QStrIntMap

func (db *RDBMS) QStrIntMap(query string, params ...any) M.SI

query 2 colums of string-integer as map

func (*RDBMS) QStrMapMap

func (db *RDBMS) QStrMapMap(key_idx string, query string, params ...any) M.SX

query any number of columns, returns map of string, map (to be exported directly to json, not for processing) the key_idx will be converted to string and taken as key

func (*RDBMS) QStrShiftArrMap

func (db *RDBMS) QStrShiftArrMap(query string, params ...any) M.SAX

query any number of columns, returns map of string, array (to be exported directly to json, not for processing) the first index will be converted to string and taken as key

func (*RDBMS) QStrStr

func (db *RDBMS) QStrStr(query string, params ...any) (s string, ss string)

execute a select pair query, convert to string and string

func (*RDBMS) QStrStrMap

func (db *RDBMS) QStrStrMap(query string, params ...any) M.SS

query 2 colums of string-string as map

func (*RDBMS) QTsv

func (db *RDBMS) QTsv(header, query string, params ...any) bytes.Buffer

query to tsv file

func (*RDBMS) QUniq

func (db *RDBMS) QUniq(table string, key int64) (uniq string)

get unique_id from id

func (*RDBMS) RenameBaseTable

func (db *RDBMS) RenameBaseTable(oldname, newname string)

rename a base table

func (*RDBMS) TableExists

func (db *RDBMS) TableExists(tableName string) bool

func (*RDBMS) ViewExists

func (db *RDBMS) ViewExists(viewname string) bool

type Records

type Records struct {
	ResultSet   *sqlx.Rows
	Query       string
	QueryParams []any
}

func (*Records) Close

func (r *Records) Close()

func (*Records) Err

func (r *Records) Err() error

func (*Records) ErrorCheck

func (r *Records) ErrorCheck(err error, msg string)

func (*Records) Next

func (r *Records) Next() bool

func (*Records) Scan

func (r *Records) Scan(dest ...any) bool

func (*Records) ScanMap

func (r *Records) ScanMap() map[string]any

func (*Records) ScanSlice

func (r *Records) ScanSlice() []any

func (*Records) ScanStruct

func (r *Records) ScanStruct(dest any) bool

type Row

type Row struct {
	Row       M.SX
	NonData   M.SX
	Posts     *W.Posts
	Ajax      W.Ajax
	ReqModel  *W.RequestModel
	Table     string
	Id        int64
	Tx        *Tx
	DbActor   int64
	Log       string
	UniqueId  string // set when you want to update it
	IsDeleted bool
}

primary table model

func NewNonDataRow

func NewNonDataRow(tx *Tx, table string, rm *W.RequestModel) *Row

create empty model

func NewRow

func NewRow(tx *Tx, table string, rm *W.RequestModel) *Row

fetch model to be edited

func NewRowUniq

func NewRowUniq(tx *Tx, table string, unique_id string, rm *W.RequestModel) *Row

fetch model to be edited from unique

func (*Row) Check_UserPassword

func (mp *Row) Check_UserPassword(pass string) bool

check password

func (*Row) Delete

func (mp *Row) Delete()

delete

func (*Row) GetAX

func (mp *Row) GetAX(key string) []any

get []any from Row

func (*Row) GetBool

func (mp *Row) GetBool(key string) bool

get boolean from Row

func (*Row) GetFloat

func (mp *Row) GetFloat(key string) float64

get float64 from Row

func (*Row) GetInt

func (mp *Row) GetInt(key string) int64

get int64 from Row

func (*Row) GetStr

func (mp *Row) GetStr(key string) string

get string from Row

func (*Row) Get_Id

func (mp *Row) Get_Id() int64

get id

func (*Row) Get_UniqueId

func (mp *Row) Get_UniqueId() string

get unique id

func (*Row) IndateRow

func (mp *Row) IndateRow() int64

insert or update row, insert if not exists even when uinque_id exists (error)

func (*Row) InsertRow

func (mp *Row) InsertRow() int64

insert row

func (*Row) IsChanged

func (mp *Row) IsChanged() bool

func (*Row) LogIt

func (mp *Row) LogIt(key string, val any)

log the changes

func (*Row) LogNonData

func (mp *Row) LogNonData(key string, val any)

log the changes

func (*Row) NotLogIt

func (mp *Row) NotLogIt(key string, val any)

log the changes

func (*Row) PermanentErase

func (mp *Row) PermanentErase()

permanent delete (usage warning!)

func (*Row) Restore

func (mp *Row) Restore()

undelete

func (*Row) SetBool

func (mp *Row) SetBool(key string) bool

set bool from Posts to Row

func (*Row) SetFloat

func (mp *Row) SetFloat(key string) float64

set float64 from Posts to Row

func (*Row) SetInt

func (mp *Row) SetInt(key string) int64

set int64 from Posts to Row

func (*Row) SetIntlPhone

func (mp *Row) SetIntlPhone(key string) string

set international phone, format: +xx xxxxxx

func (*Row) SetJsonIntArr

func (mp *Row) SetJsonIntArr(key string) []int64

set Row from json int[]

func (*Row) SetJsonMap

func (mp *Row) SetJsonMap(key string) M.SX

set Row from json {object}

func (*Row) SetJsonObjArr

func (mp *Row) SetJsonObjArr(key string) []map[string]any

set Row from json object[]

func (*Row) SetJsonStrArr

func (mp *Row) SetJsonStrArr(key string) []string

set Row from json string[]

func (*Row) SetNonData

func (mp *Row) SetNonData(key string)

func (*Row) SetNonDataVal

func (mp *Row) SetNonDataVal(key string, val any)

set raw data

func (*Row) SetStr

func (mp *Row) SetStr(key string) string

set string

func (*Row) SetStrPhone

func (mp *Row) SetStrPhone(key string) string

set string strip prefix and suffix from and letters

func (*Row) SetType

func (mp *Row) SetType(val string) string

set Row type with check

func (*Row) SetUnsetClock

func (mp *Row) SetUnsetClock(key string) string

set time from Posts to Row unset when string is whitespace

func (*Row) SetUnsetIntVal

func (mp *Row) SetUnsetIntVal(key string, val int64) int64

set unset int, returns 0 when unsetted

func (*Row) SetUnsetValClock

func (mp *Row) SetUnsetValClock(key string, val string) string

set time hh:mm

func (*Row) SetVal

func (mp *Row) SetVal(key string, val any) any

set Row value

func (*Row) SetValEpoch

func (mp *Row) SetValEpoch(key string) float64

set Row by current date epoch as float

func (*Row) SetValEpochOnce

func (mp *Row) SetValEpochOnce(key string) float64

set Row by current date epoch as float

func (*Row) SetValIf

func (mp *Row) SetValIf(ok bool, key string, val any)

set Row value if ok

func (*Row) SetValNoXSS

func (mp *Row) SetValNoXSS(key string, val any) any

set val without XSS filtering

func (*Row) SetValOnce

func (mp *Row) SetValOnce(key string, val any) any

set Row value only if still empty, or never being saved

func (*Row) SetValStr

func (mp *Row) SetValStr(key, val string)

set Row value from string

func (*Row) Set_UniqueId

func (mp *Row) Set_UniqueId(val string)

set unique id

func (*Row) Set_UserEmails

func (mp *Row) Set_UserEmails(emails string) (ok bool)

set Row office_mail, gmail, yahoo and email

func (*Row) Set_UserEmails_ByTable

func (mp *Row) Set_UserEmails_ByTable(emails string, table string) (ok bool)

func (*Row) Set_UserPassword

func (mp *Row) Set_UserPassword(pass string)

set user password, skip logging

func (*Row) ToJson

func (mp *Row) ToJson() string

convert Row to JSON string

func (*Row) Unset

func (mp *Row) Unset(key string)

unset Row key

func (*Row) UpdateRow

func (mp *Row) UpdateRow() int64

update row

func (*Row) UpsertRow

func (mp *Row) UpsertRow() int64

insert or update row, if uniq ada

func (*Row) WipeUnwipe

func (mp *Row) WipeUnwipe(a string)

delete or restore

type TableModel

type TableModel struct {
	CacheName string
	Fields    []FieldModel
	Joins     string
	WithAs    string
}

func (*TableModel) FieldModel_ByKey

func (tm *TableModel) FieldModel_ByKey(name string) FieldModel

get type of a field by key

func (*TableModel) FormFields

func (tm *TableModel) FormFields() A.MSX

generate form fields json

func (*TableModel) GridFields

func (tm *TableModel) GridFields() A.MSX

generate grid fields json

func (*TableModel) JoinStr

func (tm *TableModel) JoinStr() string

func (*TableModel) Query

func (tm *TableModel) Query(table, ram_key string) string

func (*TableModel) Select

func (tm *TableModel) Select() string

generate select fields

func (*TableModel) SelectNoJoin

func (tm *TableModel) SelectNoJoin() string

generate select fields without join

type Tx

type Tx struct {
	Trans *sqlx.Tx
}

func (*Tx) DataJsonMapIdAndIsDeleted_ByUniq

func (tx *Tx) DataJsonMapIdAndIsDeleted_ByUniq(table, unique_id string) (res M.SX, id int64, is_deleted bool)

fecth json data as map by unique id

func (*Tx) DataJsonMapUniqAndIsDeleted_ById

func (tx *Tx) DataJsonMapUniqAndIsDeleted_ById(table string, id int64) (res M.SX, uniq string, is_deleted bool)

fetch json data as map

func (*Tx) DoDelete

func (tx *Tx) DoDelete(actor int64, table string, id int64) bool

execute delete (is_deleted = true)

func (*Tx) DoDelete2

func (tx *Tx) DoDelete2(actor int64, table string, id int64, lambda func(base *Base) string, ajax W.Ajax) bool

execute delete (is_deleted = true)

func (*Tx) DoExec

func (tx *Tx) DoExec(query string, params ...any) sql.Result

execute anything that doesn't need LastInsertId or RowsAffected

func (*Tx) DoForcedInsert

func (tx *Tx) DoForcedInsert(actor int64, table string, kvparams M.SX) (id int64)

do insert without checking

func (*Tx) DoInsert

func (tx *Tx) DoInsert(actor int64, table string, kvparams M.SX) (id int64)

generate insert command and execute it

func (*Tx) DoRestore

func (tx *Tx) DoRestore(actor int64, table string, id int64) bool

execute delete (is_deleted = false)

func (*Tx) DoRestore2

func (tx *Tx) DoRestore2(actor int64, table string, id int64, lambda func(base *Base) string, ajax W.Ajax) bool

execute delete (is_deleted = false)

func (*Tx) DoUpdate

func (tx *Tx) DoUpdate(actor int64, table string, id int64, kvparams M.SX) (ra int64)

generate update command and execute it, returns number of updated records

func (*Tx) DoUpsert

func (tx *Tx) DoUpsert(actor int64, table string, kvparams M.SX) (id int64)

generate insert or update command and execute it

func (*Tx) DoWipeUnwipe

func (tx *Tx) DoWipeUnwipe(a string, actor int64, table string, id int64) bool

delete or restore

func (*Tx) QAll

func (tx *Tx) QAll(query string, params ...any) (rows Records)

do query all, also calls DoPrepare, don't forget to close the rows

func (*Tx) QBase

func (tx *Tx) QBase(table string, id int64) (base Base)

fetch a row to as Base struct

func (*Tx) QBaseUniq

func (tx *Tx) QBaseUniq(table, uid string) (base Base)

fetch a row to Base struct by unique_id

func (*Tx) QExists

func (tx *Tx) QExists(table string, id int64) bool

check if id exists

func (*Tx) QFirstMap

func (tx *Tx) QFirstMap(query string, params ...any) M.SX

query any number of columns, returns first line of line

func (*Tx) QFloat

func (tx *Tx) QFloat(query string, params ...any) (dest float64)

func (*Tx) QId

func (tx *Tx) QId(table, uniq string) (id int64)

check non-zero if unique exists

func (*Tx) QInt

func (tx *Tx) QInt(query string, params ...any) (dest int64)

execute a select single value query, convert to int64

func (*Tx) QIntArr

func (tx *Tx) QIntArr(query string, params ...any) []int64

query 1 colums of integer

func (*Tx) QIntBoolMap

func (tx *Tx) QIntBoolMap(query string, params ...any) M.IB

query single column int64, return with true value

func (*Tx) QIntCountMap

func (tx *Tx) QIntCountMap(query string, params ...any) M.II

query 1 colums of integer

func (*Tx) QIntIntMap

func (tx *Tx) QIntIntMap(query string, params ...any) M.II

query 2 colums of integer-integer as map

func (*Tx) QIntStr

func (tx *Tx) QIntStr(query string, params ...any) (i int64, s string)

execute a select pair value query, convert to int64 and string

func (*Tx) QIntStrMap

func (tx *Tx) QIntStrMap(query string, params ...any) M.IS

query 2 colums of integer-string as map

func (*Tx) QJsonIntArr

func (tx *Tx) QJsonIntArr(query string, params ...any) []int64

query one cell [1,2,3,...] and return array of int64

func (*Tx) QStr

func (tx *Tx) QStr(query string, params ...any) (dest string)

execute a select single value query, convert to string

func (*Tx) QStrArr

func (tx *Tx) QStrArr(query string, params ...any) []string

query 1 colums of string

func (*Tx) QStrArrMap

func (tx *Tx) QStrArrMap(query string, params ...any) M.SAX

query 1+N colums of string-[]any as map

func (*Tx) QStrBoolMap

func (tx *Tx) QStrBoolMap(query string, params ...any) M.SB

query 1 colums of string as map SELECT unique_id

func (*Tx) QStrCountMap

func (tx *Tx) QStrCountMap(query string, params ...any) M.SI

query 1 colums of string

func (*Tx) QStrInt

func (tx *Tx) QStrInt(query string, params ...any) (s string, i int64)

execute a select pair value query, convert to string and int

func (*Tx) QStrIntMap

func (tx *Tx) QStrIntMap(query string, params ...any) M.SI

query 2 colums of string-integer as map

func (*Tx) QStrStr

func (tx *Tx) QStrStr(query string, params ...any) (s string, ss string)

execute a select pair value query, convert to string and string

func (*Tx) QStrStrMap

func (tx *Tx) QStrStrMap(query string, params ...any) M.SS

query 2 colums of string-string as map

func (*Tx) QUniq

func (tx *Tx) QUniq(table string, id int64) (uniq string)

return non-empty string if id exists

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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