Used inside a deftable form. Define this table using the corresponding DAO class' slots.
!FOREIGN (TARGET FIELDS &REST TARGET-FIELDS/ON-DELETE/ON-UPDATE/DEFERRABLE/INITIALLY-DEFERRED)
Used inside a deftable form. Define a foreign key on this table. Pass a table the index refers to, a list of fields or single field in *this* table, and, if the fields have different names in the table referred to, another field or list of fields for the target table, or :primary-key to indicate that the other table's primary key should be referenced.
!INDEX (&REST FIELDS)
Used inside a deftable form. Define an index on the defined table.
!UNIQUE-INDEX (&REST FIELDS)
Used inside a deftable form. Define a unique index on the defined table.
Immediately abort an open transaction.
CALL-WITH-CONNECTION (SPEC THUNK)
Binds *database* to a new connection, as specified by the spec argument, which should be a list of arguments that can be passed to connect, and runs the function given as a second argument with that database.
Disconnect and remove all connections in the connection pool.
Immediately commit an open transaction.
CONNECT (DATABASE USER PASSWORD HOST &KEY (PORT 5432) POOLED-P (USE-SSL *DEFAULT-USE-SSL*) (SERVICE postgres))
Create and return a database connection.
CONNECT-TOPLEVEL (DATABASE USER PASSWORD HOST &KEY (PORT 5432) (USE-SSL *DEFAULT-USE-SSL*))
Set *database* to a new connection. Use this if you only need one connection, or if you want a connection for debugging from the REPL.
Test whether a database connection is still connected.
Create all defined tables.
Create all tables whose identifying symbol is interned in the given package.
Create a defined table.
Generate the appropriate CREATE TABLE query for this class.
Given a database-error for an integrity violation, will attempt to extract the constraint name.
LIST-SEQUENCES (&OPTIONAL STRINGS-P)
Return a list of the sequences in a database. Turn them into keywords if strings-p is not true.
LIST-TABLES (&OPTIONAL STRINGS-P)
Return a list of the tables in a database. Turn them into keywords if strings-p is not true.
LIST-VIEWS (&OPTIONAL STRINGS-P)
Return a list of the views in a database. Turn them into keywords if strings-p is not true.
Immediately release a savepoint, commiting its results.
Immediately roll back a savepoint, aborting it results.
Try to insert the content of a DAO. If this leads to a unique key violation, update it instead.
Check whether a sequence exists. Takes either a string or a symbol for the sequence name.
Shortcut for getting the next value from a sequence.
SQL-ESCAPE-STRING (STRING &OPTIONAL PREFIX)
Escape string data so it can be used in a query.
TABLE-DESCRIPTION (TABLE &OPTIONAL SCHEMA-NAME)
Return a list of (name type null-allowed) lists for the fields of a table. If SCHEMA-NAME is specified, only fields from that schema are returned.
Check whether a table exists. Takes either a string or a symbol for the table name.
Check whether a view exists. Takes either a string or a symbol for the view name.
!UNIQUE (TARGET-FIELDS &KEY DEFERRABLE INITIALLY-DEFERRED)
COALESCE (&REST ARGS)
SQL-ERROR (CONTROL &REST ARGS)
Synthesise a number of methods for a newly defined DAO class. (Done this way because some of them are not defined in every situation, and each of them needs to close over some pre-computed values.)
Enumerate the slots in a class that refer to table rows.
Defines a row-reader for objects of a given class.
Build a list of superclasses of a given class that are DAO classes.
ENSURE-PREPARED (CONNECTION ID QUERY)
Make sure a statement has been prepared for this connection.
GENERATE-PREPARED (FUNCTION-FORM QUERY FORMAT)
Helper macro for the following two functions.
Get a database connection from the specified pool, returns nil if no connection was available.
Provide unique statement names.
Used for supporting both plain string queries and S-SQL constructs. Looks at the argument at compile-time and wraps it in (sql ...) if it looks like an S-SQL query.
Used to allow both strings and symbols as identifier - converts symbols to string with the S-SQL rules.
ADD-TABLE-DEFINITION (SYMBOL FUNC)
COLUMN-ROW-READER (G91 FIELDS)
FLAT-TABLE-NAME (&OPTIONAL (TABLE *TABLE-NAME*))
QUERY-DAO% (TYPE QUERY &REST ARGS)
SYMBOL-ALIST-ROW-READER (G0 FIELDS)
SYMBOL-PLIST-ROW-READER (G44 FIELDS)
DEFPREPARED (NAME QUERY &OPTIONAL (FORMAT ROWS))
Like perpare, but gives the function a name instead of returning it.
DEFPREPARED-WITH-NAMES (NAME (&REST ARGS) (QUERY &REST QUERY-ARGS) &OPTIONAL (FORMAT ROWS))
Like defprepared, but with lambda list for statement arguments.
DEFTABLE (NAME &BODY DEFINITIONS)
Define a table. name can be either a symbol or a (symbol string) list. In the first case, the table name is derived from the symbol by S-SQL's rules, in the second case, the name is given explicitly. The body of definitions can contain anything that evaluates to a string, as well as S-SQL expressions. In this body, the variables *table-name* and *table-symbol* are bound to the relevant values.
DOQUERY (QUERY (&REST NAMES) &BODY BODY)
Iterate over the rows in the result of a query, binding the given names to the results and executing body for every row. Query can be a string, an s-sql query, or a list starting with one of those, followed by the arguments to parameterize the query with.
EXECUTE (QUERY &REST ARGS)
Execute a query, ignore the results.
PREPARE (QUERY &OPTIONAL (FORMAT ROWS))
Wraps a query into a function that will prepare it once for a connection, and then execute it with the given parameters. The query should contain a placeholder ($1, $2, etc) for every parameter.
QUERY (QUERY &REST ARGS/FORMAT)
Execute a query, optionally with arguments to put in the place of $X elements. If one of the arguments is a known result style or a class name, it specifies the format in which the results should be returned.
QUERY-DAO (TYPE QUERY &REST ARGS)
Execute a query and return the result as daos of the given type. The fields returned by the query must match the slots of the dao, both by type and by name.
REGISTER-SQL-OPERATORS (ARITY &REST NAMES)
Define simple operators. Arity is one of :unary (like 'not'), :unary-postfix (the operator comes after the operand), :n-ary (like '+': the operator falls away when there is only one operand), :2+-ary (like '=', which is meaningless for one operand), or :n-or-unary (like '-', where the operator is kept in the unary case). After the arity follow any number of operators, either just a keyword, in which case the downcased symbol name is used as the operator, or a two-element list containing a keyword and a name string.
SELECT-DAO (TYPE &OPTIONAL (TEST T) &REST ORDERING)
Select daos for the rows in its table for which the given test holds, order them by the given criteria.
Compile form to an sql expression as far as possible.
WITH-CONNECTION (SPEC &BODY BODY)
Locally establish a database connection, and bind *database* to it.
WITH-SAVEPOINT (NAME &BODY BODY)
Execute the body within a savepoint, releasing savepoint when the body exits normally, and rolling back otherwise. NAME is both the variable that can be used to release or rolled back before the body unwinds, and the SQL name of the savepoint.
WITH-TRANSACTION ((&OPTIONAL NAME) &BODY BODY)
Execute the body within a database transaction, committing when the body exits normally, and aborting otherwise. An optional name can be given to the transaction, which can be used to force a commit or abort before the body unwinds.
DEFINE-DAO-FINALIZATION (((DAO-NAME CLASS) &REST KEYWORD-ARGS) &BODY BODY)
WITH-COLUMN-WRITERS ((&REST DEFS) &BODY BODY)
MAKE-EXISTS-QUERY (RELKIND NAME)
Helper macro for the functions that check whether an object exists.
Helper macro for the functions that list tables, sequences, and views.
WITH-POOL-LOCK (&BODY BODY)
Aquire a lock for the pool when evaluating body (if thread support is present).
Return a boolean indicating whether the given dao exists in the database.
Delete the given dao from the database.
Close a database connection. Returns it to a pool if it is a pooled connection.
GET-DAO (TYPE &REST ARGS)
Get the object corresponding to the given primary key, or return nil if it does not exist.
Insert the given object into the database.
MAKE-DAO (TYPE &REST ARGS &ALLOW-OTHER-KEYS)
Make the instance of the given class and insert it into the database
Reconnect a database connection.
Get the representation of a Lisp value so that it can be used in a query.
Update the object's representation in the database with the values in the given instance.
Update or insert the given dao. If its primary key is already in the database and all slots are bound, an update will occur. Otherwise it tries to insert it.
SETFDATABASE-ERROR-MESSAGE (NEW-VALUE CONDITION)
Used to fetch the default values of an object on creation.
SETFCONNECTION-POOL-TYPE (NEW-VALUE OBJECT)
SETFSAVEPOINT-OPEN-P (NEW-VALUE OBJECT)
SETFTRANSACTION-OPEN-P (NEW-VALUE OBJECT)
Special holding the current database. Most functions and macros operating on a database assume this contains a connected database.
Setting this to T will make S-SQL add double quotes around identifiers in queries. Setting it :auto will turn on this behaviour only for reserved words.
The maximum amount of connection that will be kept in a single pool, or NIL for no maximum.
Maps pool specifiers to lists of pooled connections.
A hook for locally overriding/adding behaviour to DAO row readers. Should be an alist mapping strings (column names) to symbols or functions. Symbols are interpreted as slot names that values should be written to, functions are called with the new object and the value as arguments.
This is used to communicate the fact that a slot is a column to effective-slot-definition-class.
A lock to prevent multiple threads from messing with the connection pool at the same time.
Mapping from keywords identifying result styles to the row-reader that should be used and whether all values or only one value should be returned.
Unexported ordered list containing the known table definitions.
Metaclass for database-access-object classes.
Representatino of a database connection. Contains login information in order to be able to automatically re-establish a connection when it is somehow closed.
Type of slots that refer to database columns.
Type for database connections that are pooled. Stores the arguments used to create it, so different pools can be distinguished.
Simple box type for storing the state and the associated database connection of a savepoint.
Simple box type for storing the status and the associated database connection of a transaction. When open-p is nil, the transaction has been aborted or committed.
Conditions of this type are signalled when an error occurs that breaks the connection socket. They offer a :reconnect restart.
This is the condition type that will be used to signal virtually all database-related errors (though in some cases socket errors may be raised when a connection fails on the IP level).