Path to have :db-type working
"Eduardo Muñoz" <[email protected]> 18 Apr 2003 18:47:41 +0200
| Newsgroups | gmane.lisp.uncommon-sql |
|---|---|
| Organization | Not likely |
| Message-ID | <[email protected]> |
Maybe this functionality is not really needed (or wanted by
the uncommon-sql crew) but here it goes. I patched my
uncommon-sql installation (Debian) to allow the :db-type
slot to work as advertised in the documentation. This makes
the mapping betwen objects and database rows cleaner IMHO.
For example (postgresql specific):
(sql:def-view-class foo ()
((id :db-kind :key
:type integer
:db-type "SERIAL")
...
))
maps the id slot to a SERIAL column, :type integer takes
care of the type translation handling. If the :db-type is
nil the behaviour is the normal one.
I find this more convenient than to mess with the type
system of cmucl to convince it that serial is a subtype of
integer and to define type-translation methods for already
defined types.
BTW, both of usql-tutorial.lisp and usql-tutorial.txt have a
typo on the definition of company class:
(sql:def-view-class company ()
((companyid
:db-type :key
^^^^
Should be :db-kind
The examples work well though.
diffs follow:
$ diff -uw classes.lisp.old classes.lisp
--- classes.lisp.old Fri Apr 5 23:22:00 2002
+++ classes.lisp Fri Apr 18 16:03:22 2003
@@ -647,12 +647,17 @@
(defmethod output-sql ((stmt sql-create-table) &optional
(database *default-database*))
(flet ((output-column (column-spec)
- (destructuring-bind (name type &rest constraints)
+ (destructuring-bind (name lisp-type db-type &rest constraints)
column-spec
- (let ((type (listify type)))
+ (let ((lisp-type (listify lisp-type)))
(output-sql name database)
(write-char #\Space *sql-stream*)
- (write-string (database-get-type-specifier (car type) (cdr type) database) *sql-stream*)
+ (write-string (if (stringp db-type)
+ db-type
+ (database-get-type-specifier (car lisp-type)
+ (cdr lisp-type)
+ database))
+ *sql-stream*)
(let ((constraints (database-constraint-statement constraints database)))
(when constraints
(write-string " " *sql-stream*)
________________________
$ diff -uw objects.lisp.old objects.lisp
--- objects.lisp.old Fri Apr 5 23:22:00 2002
+++ objects.lisp Fri Apr 18 15:55:07 2003
@@ -237,6 +237,7 @@
(slot-definition-type slotdef))))
(when-bind (const (view-class-slot-db-constraints slotdef))
(setq cdef (append cdef (list const))))
+ (setf cdef (append cdef (list (view-class-slot-db-type slotdef))))
cdef)))
--
Eduardo Muñoz | (prog () 10 (print "Hello world!")
http://213.97.131.125/ | 20 (go 10))