sql. Querying database

^table::sql{SQL-query}
^table::sql{SQL-query}[$.limit(n) $.offset(o)
 $.bind[variables hash]]

The constructor creates an object of class
table containing table based on the data retrieved from a database. To use this constructor you must have connection with data server established (see operator connect).

SQL-query-query sent to a database.

It is possible to use additional parameters with the constructor:
$.limit(n)-retrieve no more than n entries;
$.offset(o)-ignore first o retrieved entries;
$.bind[hash] - variables to bind, see «Queries with bound variables» [3.1.4].

Example

$sql_table[^table::sql{select * from news}]

The code will result in an object containing all data from table
news.

Important notice: you should always provide exact list of fields you need.
Using "*" in queries is strongly NOT recommended, since another developer (or you yourself-in a while) will have no idea which fields are to be retrieved from database. Moreover, by using such a construction one may retrieve unneeded fields (say, those which were added during project's development), which will demand additional resources for retrieving and storing superfluous data.



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 03.07.2008