clsql-orm
2016-02-08
No Description
Upstream URL
License
Not determined
CLSQL-PG-INTROSPECT
-------------------
Use this package to help with introspective operations on Postgres
databases.
Some small examples of some basic operations follow.
(gen-view-class music)
Would take the music table and define a clsql class based upon it.
This currently includes designating primary keys, not-null
constraints, unique constraints, and joins on foreign tables.
(gen-view-class musicians :classname music-people)
Defines a class MUSIC-PEOPLE based on table musicians. This is best to
avoid if you can, as then autogenerated foreign relations won't work.
(gen-view-class music :generate-joins nil)
Defines class MUSIC, but without the joins.
By default, accessors are generated, named after the columns. To turn this
off, pass :generate-accessors nil to gen-view-class.
Accessors/slots for joins are named [home key]-[target table]
Besides this main utility, there are functions for:
- determining if a column has any of the following restrictions:
+ not-null (not-null-p)
+ unique (unique-p)
+ is a primary key (primary-key-p)
- listing all foreign constraints of a table (list-foreign-constraints)
- listing all user columns of a table and their type (user-columns)
- figuring out a clsql type given a PostgreSQL type (clsql-type-for-pg-type)
Most of the functionality is wrapped up in one simple macro:
(defmacro gen-view-classes-for-database ((connection-spec database-type &key (generate-joins t) (generate-accessors t)) &rest classes)
That'll do it for you.
Of course, database-type has to be :postgresql. The option is in for...forwards compatibility?
Bug reports and patches gladly accepted.
Thanks,
Alan Shields
Alan-Shields@omrf.ouhsc.edu
This work was made possible by the Centola Lab of the Oklahoma Medical
Research Foundation
License information is in the file LICENSE