Common Lisp Package: AUTOPROJECT.CRUD

Provides code to automatically generate an ORM. Operations supported: - create - read - update - delete - match All tables should have a primary integer key.

README:

FUNCTION

Public

SELECT-BUFFERED (CRUD SELECT &KEY RAW (BUFFER-SIZE *BUFFER-SIZE*))

Buffered iteration over selects. Returns a closure that will return elements from the database corresponding to SELECT. If RAW is non-nil, the crud will be queried using CRUD-SELECT-RAW, otherwise CRUD-SELECT

SELECT-MAPC (CRUD SELECT FN &KEY RAW (BUFFER-SIZE *BUFFER-SIZE*))

Buffered mapc over selects. If RAW is non-nil, the crud will be queried using CRUD-SELECT-RAW, otherwise CRUD-SELECT

SELECT-MAPCAR (CRUD SELECT FN &KEY RAW (BUFFER-SIZE *BUFFER-SIZE*))

Buffered mapcar over selects. If RAW is non-nil, the crud will be queried using CRUD-SELECT-RAW, otherwise CRUD-SELECT

SELECT-REMOVE-IF (CRUD SELECT PREDICATE &KEY RAW (BUFFER-SIZE *BUFFER-SIZE*))

Buffered remove-if over selects. If RAW is non-nil, the crud will be queried using CRUD-SELECT-RAW, otherwise CRUD-SELECT

Undocumented

APPLY-SELECT (SELECT)

GET-SELECT-PROPERTY (SELECT PROPERTY)

MAKE-SELECT (&KEY (ATTR *) TABLE WHERE GROUP-BY JOIN ORDER-BY HAVING AMOUNT OFFSET)

MERGE-SELECT (SELECT DEFAULTS)

SELECT-COUNT (SELECT)

SELECT-NEXT-PAGE (SELECT)

SELECT-PREVIOUS-PAGE (SELECT)

SET-SELECT-PROPERTY (SELECT PROPERTY VALUE)

SQL-AND (&REST ARGS)

SQL-OP (LEFT OP RIGHT)

SQL-OR (&REST ARGS)

SQL-QUOTE (VALUE)

Private

MAKE-BUFFER (PRODUCER-FN)

Returns a closure that will fill a buffer by calling PRODUCER-FN. Each invocation of the closure pops one element off the buffer. When the buffer is empty, it is filled by calling PRODUCER-FN again. For example, the call (make-buffer (constantly '(1 2 3))) will return a closure that returns 1, 2, 3 forever, in that order.

Undocumented

%COPY-BOUND-SLOTS (FROM TO)

DATABASE-FORMAT-VALUE (THING)

DETECT-MULTIPLE-TABLES (SELECT)

EXTRACT-MULTIPLE-TABLES (SELECT)

FORMAT-LIST (LIST &KEY (SEPARATOR , ) (START-WITH ) (END-WITH ))

FORMAT-MAYBE (FORMAT-STRING ARG &OPTIONAL (ELSE ))

INSTANCE-LIST (I FIELD-LIST)

INSTANCE-LIST-BOUND (I FIELD-LIST)

INSTANCE-VALUES (I)

KEYWORDIFY (NAME)

LISPIFY (NAME)

LISTIFY-HASH (HASH &KEY (KIND ALIST))

MERGE-PLIST (PLIST DEFAULTS)

REMOVE-NIL-PROPS (LIST)

REMOVE-PROPS (LIST PROP-VALUE &KEY (TEST #'EQ))

ROW-MULTIPLE-INSTANCES (CRUD TABLES ROW)

SELECT-PAGE (SELECT PAGE)

SPLIT-LIST (LIST OFFSETS)

SQL-SELECT (&KEY (ATTR *) TABLE WHERE JOIN GROUP-BY ORDER-BY HAVING AMOUNT OFFSET)

SQLIFY (NAME &OPTIONAL TABLE)

SYMBOLICATE (NAME)

UNZIP (LIST)

ZIP (LIST-1 LIST-2)

MACRO

Public

DEFINE-FOREIGN-KEY ((ITEM-CLASS &REST ITEM-SLOT-NAMES) (FOREIGN-CLASS &REST FOREIGN-SLOT-NAMES) &KEY ASSIGN-KEY)

Defines a RESOLVE-KEY method for ITEM-CLASS and FOREIGN-CLASS. If ASSIGN-KEY is non-nil, also define an ASSIGN-KEY method. Example: (define-foreign-key (order customer-id) (customer id) :assign-key t) This would mean that order.customer_id references customer.id and that assignment is allowed with ASSIGN-KEY. Assigning a customer instance to an order instance would mean setting the slot customer-id of the order instance to the value of the id slot of customer instance.

WITH-CRUD ((CRUD &KEY TRANSACTIONP) &BODY BODY)

Do stuff while the db of CRUD is active. If TRANSACTIONP is non-nil, evaluate BODY in a transaction.

Private

>> (&BODY FORMS)

Chains FORMS together, binding IT to the result of each form.

DEFINE-CRUD-ACCESSORS (SPECIAL-VAR-NAME &OPTIONAL (PREFIX I-CRUD))

Defines crud accessors for the lazy. SPECIAL-VAR-NAME should be bound to a crud instance.

Undocumented

WITH-TRANSACTION (CRUD &BODY BODY)

GENERIC-FUNCTION

Public

ASSIGN-KEY (CRUD ITEM FOREIGN-ITEM)

Links ITEM to FOREIGN-ITEM by setting slot values of ITEM in the way specified by DEFINE-FOREIGN-KEY.

CRUD-CREATE (CRUD TABLE VALUES)

Adds a new row to the database of CRUD. Example: (CRUD-CREATE *crud* "foo" '("id" 5 "name" "John"))

CRUD-CREATE-FROM-INSTANCE (CRUD INSTANCE)

Adds a new row to the database of CRUD based on the slots of INSTANCE.

CRUD-DELETE (CRUD TABLE ID)

Deletes the row with id ID in TABLE.

CRUD-DELETE-FROM-INSTANCE (CRUD INSTANCE)

Deletes the row corresponding to INSTANCE.

CRUD-MATCH (CRUD INSTANCE)

Returns a set of instances that match the bound slots of INSTANCE.

CRUD-READ (CRUD TABLE ID)

Returns an instance corresponding to the row in TABLE with id ID.

CRUD-READ-FROM-INSTANCE (CRUD INSTANCE)

Returns an fresh instance of INSTANCE from the database of CRUD.

CRUD-SELECT (CRUD SELECT)

Returns instances that match SELECT. SELECT must select all fields ("*"). See MAKE-SELECT.

CRUD-SELECT-RAW (CRUD SELECT-OR-STRING)

Returns the results of the query SELECT-OR-STRING directly. This is useful for queries that do not return results that could be mapped to instances. The format of the result is dependent on the db adapter of CRUD.

CRUD-UPDATE (CRUD TABLE ID VALUES)

Updates the row with id ID in TABLE with VALUES. Example: (CRUD-UPDATE *crud* "foo" 5 '("name" "John"))

CRUD-UPDATE-FROM-INSTANCE (CRUD INSTANCE)

Updates the row corresponding to INSTANCE with its slot values in the database of CRUD.

RESOLVE-KEY (CRUD ITEM FOREIGN)

Returns the instance(s) from table FOREIGN-ITEM-NAME that is referenced by ITEM. Example: (resolve-key *crud* my-order 'customer) This would return the customer referenced by my-order. See ASSIGN-KEY and DEFINE-FOREIGN-KEY.

Undocumented

GET-CRUD-SYMBOL (CRUD-OR-ITEM KEYWORD)

MAKE-CRUD (CRUD-CLASS DB-ADAPTER &REST REST)

WRITE-CRUD-FORMS (CRUD CRUD-SUBCLASS-NAME STREAM PACKAGE TABLES FIELDS)

WRITE-CRUD-FORMS-TO-FILE (CRUD FILE CLASS-NAME PACKAGE-NAME)

Private

CALL-WITH-DB (DB-ADAPTER FN)

Connects to the database of DB-ADAPTER and executes FN. DB-ADAPTER may keep connections alive and reuse them.

CALL-WITH-TRANSACTION (DB-ADAPTER FN)

Executes FN in a transaction.

CRUD-EXECUTE-RAW (CRUD SQL-STATEMENT)

Executes SQL-STATEMENT in the database of CRUD.

DB-EXECUTE (DB-ADAPTER STATEMENT)

Executes statement in the database of DB-ADAPTER. Needs to be wrapped with CALL-WITH-DB.

DB-QUERY (DB-ADAPTER QUERY)

Executes query in the database of DB-ADAPTER. Needs to be wrapped with CALL-WITH-DB.

GET-LAST-ID (DB-ADAPTER)

Returns the id of the last inserted row.

READ-DATABASE-TABLES (DB-ADAPTER)

Inspects the database of DB-ADAPTER and returns two values: a list of tables in the database, and a list of lists specifying the fields in each table. Example return values: ("foo" "bar") (("id" "name" "date") ("id" "foo_id" "blargh")) This would mean that the table "foo" has the fields ("id" "name" "date") while table "bar" has the fields ("id" "foo_id" "blargh")

Undocumented

%INIT-CRUD (CRUD TABLES FIELDS-LIST)

CHECK-TABLE (CRUD TABLE)

CHECK-TABLE-COLUMNS (CRUD TABLE VALUES)

CREATE-CRUD-FORM (CRUD TABLE-NAME FIELDS)

CREATE-CRUD-FORMS (CRUD CRUD-SUBCLASS-NAME)

CREATE-CRUD-SUBCLASS-FORM (CRUD NAME TABLES FIELDS)

CRUD-CREATE/QUERY (CRUD TABLE VALUES)

CRUD-DELETE/QUERY (CRUD TABLE ID)

CRUD-MATCH/QUERY (CRUD INSTANCE)

CRUD-READ/QUERY (CRUD TABLE ID)

CRUD-SELECT-MULTIPLE (CRUD SELECT)

CRUD-UPDATE/QUERY (CRUD TABLE ID VALUES)

DEFINE-TABLE-CLASS (CRUD TABLE-NAME FIELDS)

DEFINE-TABLE-CLASSES (CRUD)

GET-FIELDS (CRUD TABLE)

GET-ID (INSTANCE)

GET-ID-FIELD (CRUD TABLE)

GET-NUMBER-OF-SLOTS (I)

GET-SLOT-KEYWORDS (I)

GET-SLOT-NAMES (DB-RESPONSE &OPTIONAL RETURN-KIND)

GET-SLOT-STRINGS (I)

GET-SLOT-SYMBOLS (I)

GET-SLOT-VALUES (I)

GET-TABLE-CLASS (CRUD TABLE)

GET-TABLE-NAME (INSTANCE)

INIT-CRUD (CRUD)

INSTANCE-PLIST (INSTANCE)

INSTANCE-PLIST-BOUND (INSTANCE)

INSTANCE-STRING-LIST (INSTANCE)

INSTANCE-STRING-LIST-BOUND (INSTANCE)

ROW-INSTANCE (CLASS-NAME ROW)

ROWS-INSTANCES (CRUD TABLE ROWS)

ROWS-MULTIPLE-INSTANCES (CRUD TABLES ROWS)

SLOT-ACCESSOR

Private

Undocumented

%GET-ID-FIELDS (OBJECT)

SETF%GET-ID-FIELDS (NEW-VALUE OBJECT)

GET-DB-ADAPTER (OBJECT)

SETFGET-DB-ADAPTER (NEW-VALUE OBJECT)

GET-FIELD-NAMES (OBJECT)

SETFGET-FIELD-NAMES (NEW-VALUE OBJECT)

GET-FIELD-SYMBOLS (OBJECT)

SETFGET-FIELD-SYMBOLS (NEW-VALUE OBJECT)

GET-TABLE-CLASSES (OBJECT)

SETFGET-TABLE-CLASSES (NEW-VALUE OBJECT)

VARIABLE

Private

*RETURN-INSTANCE*

If non-nil, return a fresh instance on create and update. This will do nothing for create if the db adapter doesn't implement get-last-id

Undocumented

*BUFFER-SIZE*

*DEBUG*

*GLOBAL-KEYWORD-SYMBOL-MAP-NAME*

*SELECT-AMOUNT*

*TABLE-SUPER-CLASS-NAME*

CLASS

Public

Undocumented

CRUD

Private

Undocumented

DB-ADAPTER

DB-RESPONSE