lights FAQ Forum github.com/luapower/x-widgets
This package
x-3d-model-editor
x-grid
x-widgets
xapp
xrowset
xrowset_sql

Web Development
webb
x-widgets

xrowset_sql

SQL rowsets


--[[

	SQL rowsets.
	Written by Cosmin Apreutesei. Public Domain.

	What must be specified manually:
		- select          : select without where clause.
		- where_all       : where clause for all rows (without the word "where").
		- order_by        : order-by clause.
		- pk              : 'foo bar ...', required as it can't be inferred reliably.
		- db              : optional, connection alias to query on.

	More complex cases can specify:
		- select_all    : instead of select + where_all.
		- where_row     : where clause for single row: 'tbl.pk1 = :as_pk1 and ...'.
		- select_row    : instead of select + where_row.
		- select_none   : instead of select_row or (select + 'where 1 = 0').

	If all else fails, you can always implement the rowset's S/U/I/D methods
	yourself. Just make sure to wrap multiple update queries in atomic().

	Inferred field attributes:
		name             : column alias.
		type             : field type.
		min, max         : numeric range (integers).
		decimals         : number of decimals (integers and decimals).
		max_char_w       : max length in characters in the current result set.
	Additionally, for fields that can be traced back to their origin table:
		enum_values      : enum values.
		default          : default value.
		not_null         : not-null flag.
		maxlen           : max length in characters.
		min, max         : numeric range (decimals).
		ref_table        : reference table (foreign key).
		ref_col          : column name in reference table (single-column fk).

	Fields without an origin table (SQL expressions) are made readonly.
	Auto-increment fields are made readonly.

	How to use rowset param values in queries:
		- in where_all:
			- `:param:filter`
				- `tbl.pk in (:param:filter)`, if the rowset's pk is a single column.
				- `$filter(foo = :foo and bar = :bar, :param:filter)` for composite pks.
			- `:param:lang`         : current language.
			- `:param:default_lang` : default language.
		- in insert and update queries:
			- `:COL`      : the column's new or changed value.
		- in update and delete where clause:
			- `:COL:old`  : the column's old value.

	Field methods to implement:
		to_lua(v)        : convert value for select result sets.
		to_sql(v)        : convert value for update queries (SQL statements).
		to_bin(v)        : convert value for update queries (prepared statements).

]]

See the source code for more info.


Package:x-widgets
Pkg type:Lua+ffi
Version: 80110b8
Last commit:
License: Public Domain

Requires: errors  fs  glue  luajit  path  time  webb  base64  cjson  connpool  coro  heap  hmac  msgpack  mustache  mysql  pp  queue  schema  sha1  sha2  sock  sqlpp  tarantool  uri  xxhash 

Required by: none


Top