X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=sidebyside;f=doc%2Fcsql.xml;h=4787898bb3996ec6157698b6604218fb9a0d8c5b;hb=4c5797c1926bdfb21ca1824408e4aa5bf0d30d19;hp=47491ffe4fa44857334530ddd3e68054cfd01bd3;hpb=9dd1aaa4e36d0d9a13e68cb501f1d17dbb10c209;p=clsql.git
diff --git a/doc/csql.xml b/doc/csql.xml
index 47491ff..4787898 100644
--- a/doc/csql.xml
+++ b/doc/csql.xml
@@ -36,19 +36,19 @@
- &clsql; is based on the CommonSQL package from Xanalys, so the
- documentation that Xanalys makes available online is useful for
+ &clsql; is based on the CommonSQL package from LispWorks Ltd, so the
+ documentation that LispWorks makes available online is useful for
&clsql; as well. It is suggested that developers new to &clsql; read
their documentation as well, as any differences between CommonSQL
- and &clsql; are minor. Xanalys makes the following documents
+ and &clsql; are minor. LispWorks makes the following documents
available:
-
- Xanalys &lw; User Guide - The &commonsql;
+
+ &lw; User Guide - The &commonsql;
Package
@@ -57,8 +57,8 @@
-
- Xanalys &lw; Reference Manual - The SQL
+
+ &lw; Reference Manual - The SQL
Package
@@ -66,7 +66,7 @@
-
+ &commonsql; Tutorial by Nick Levine
@@ -83,7 +83,7 @@
+ url="http://philip.greenspun.com/sql/data-modeling.html">
Philip Greenspun's "SQL For Web Nerds" - Data
Modeling
@@ -177,10 +177,12 @@ mapped into a database). They would be defined as follows:
:nulls-ok t
:initarg :email)
(companyid
- :type integer)
+ :type integer
+ :initarg :companyid)
(managerid
:type integer
- :nulls-ok t))
+ :nulls-ok t
+ :initarg :managerid))
(:base-table employee))
(clsql:def-view-class company ()
@@ -193,7 +195,8 @@ mapped into a database). They would be defined as follows:
:type (string 100)
:initarg :name)
(presidentid
- :type integer))
+ :type integer
+ :initarg :presidentid))
(:base-table company))
@@ -253,10 +256,8 @@ mapped into a database). They would be defined as follows:
- :nulls-ok - If &t;, all &sql; &null; values
- retrieved from the database become nil; if &nil;, all &null;
- values retrieved are converted by
- DATABASE-NULL-VALUE.
+ :void-value - The Lisp value to return if the
+ field is &null;. The default is &nil;.
@@ -291,6 +292,17 @@ mapped into a database). They would be defined as follows:
:base-table option specifies what the table name
for the view class will be when it is mapped into the database.
+
+
+ Another class option is :normalizedp, which signals
+ &clsql; to use a normalized schema for the mapping from slots to
+ &sql; columns. By default &clsql; includes all the slots of a parent
+ class that map to &sql; columns into the child class. This option
+ tells &clsql; to normalize the schema, so that a join is done on the
+ primary keys of the concerned tables to get a complete column set
+ for the classes. For more information, see
+ def-view-class.
+
@@ -299,7 +311,7 @@ mapped into a database). They would be defined as follows:
In an &sql; only application, the EMPLOYEE and
COMPANY tables can be queried to determine things
-like, "Who is Vladamir's manager?", "What company does Josef work
+like, "Who is Vladimir's manager?", "What company does Josef work
for?", and "What employees work for Widgets Inc.". This is done by
joining tables with an &sql; query.
@@ -315,12 +327,12 @@ SELECT first_name, last_name FROM employee, company
-Who is Vladamir's manager?
+Who is Vladimir's manager?
SELECT managerid FROM employee
- WHERE employee.first_name = "Vladamir"
+ WHERE employee.first_name = "Vladimir"
AND employee.last_name = "Lenin"
@@ -453,6 +465,24 @@ There are other :join-info options available in &clsql;, but we will
save those till we get to the many-to-many relation examples.
+
+ Object Oriented Class Relations
+
+
+&clsql; provides an Object Oriented Data Definition Language, which
+provides a mapping from &sql; tables to CLOS objects. By default class
+inheritance is handled by including all the columns from parent
+classes into the child class. This means your database schema becomes
+very much denormalized. The class option :normalizedp
+can be used to disable the default behaviour and have &clsql;
+normalize the database schemas of inherited classes.
+
+
+
+See def-view-class
+for more information.
+
+
@@ -465,7 +495,7 @@ first need to create our tables in the database:
-Note: the file doc/clsql-tutorial.lisp contains
+Note: the file examples/clsql-tutorial.lisp contains
view class definitions which you can load into your list at this point
in order to play along at home.
@@ -481,22 +511,25 @@ any other CLOS object:
-(defvar employee1 (make-instance 'employee
- :emplid 1
- :first-name "Vladamir"
- :last-name "Lenin"
- :email "lenin@soviet.org"))
-
(defvar company1 (make-instance 'company
:companyid 1
+ :presidentid 1
:name "Widgets Inc."))
+(defvar employee1 (make-instance 'employee
+ :emplid 1
+ :first-name "Vladimir"
+ :last-name "Lenin"
+ :email "lenin@soviet.org"
+ :companyid 1))
(defvar employee2 (make-instance 'employee
:emplid 2
:first-name "Josef"
:last-name "Stalin"
- :email "stalin@soviet.org"))
+ :email "stalin@soviet.org"
+ :companyid 1
+ :managerid 1))
@@ -510,26 +543,6 @@ In order to insert an objects into the database we use the
(clsql:update-records-from-instance company1)
-
-Now we can set up some of the relations between employees and
-companies, and their managers. The
-ADD-TO-RELATION method provides us with an easy
-way of doing that. It will update both the relation slot, as well as
-the home-key and foreign-key slots in both objects in the relation.
-
-
-
-;; Lenin manages Stalin (for now)
-(clsql:add-to-relation employee2 'manager employee1)
-
-;; Lenin and Stalin both work for Widgets Inc.
-(clsql:add-to-relation company1 'employees employee1)
-(clsql:add-to-relation company1 'employees employee2)
-
-;; Lenin is president of Widgets Inc.
-(clsql:add-to-relation company1 'president employee1)
-
-
After you make any changes to an object, you have to specifically
tell &clsql; to update the &sql; database. The