Re: Fixes and questions

Martin Simmons <[email protected]> Fri, 7 Nov 2003 11:45:11 GMT
Newsgroups gmane.lisp.uncommon-sql
Message-ID <[email protected]>
>>>>> On Fri, 7 Nov 2003 12:11:54 +0100, [email protected] said:
 
  rm> On Fri, Nov 07, 2003 at 10:59:11AM +0000, Martin Simmons wrote:
  >> >>>>> On 05 Nov 2003 17:20:43 +0800, Robert Marlow <[email protected]> said:
  >> 
  Robert> Also, I like this idea of the object-relational mapping. However, is
  Robert> there any provided way to extract relational data from a database and
  Robert> place it into the object system? That'd be real handy...
  >> 
  >> Forgive my ignorance of UncommonSQL, but in CommonSQL the object-relational
  >> mapping does just that.  After using DEF-VIEW-CLASS to define a Lisp class for
  >> some table, calling SELECT will create an object for each row in table,
  >> containing the data.

  rm> Hmm, my initial understanding of the OP was that he was looking or
  rm> a way to create a mapping between objects<->reldata for an existing 
  rm> relation.

But that *is* what CommonSQL's DEF-VIEW-CLASS does!  E.g.

psql:
test=> \d sqltest
          Table "sqltest"
 Attribute |    Type     | Modifier 
-----------+-------------+----------
 s1        | varchar(10) | 
 s2        | varchar(9)  | not null

test=> 

CommonSQL:
CL-USER 4 > (pprint (query "select s1,s2 from sqltest"))  ; relational query

(("astring1" "zstring2")
 ("bstring1" "ystring2")
 ("cstring1" "xstring2")
 ("dstring1" "wstring2")
 ("estring1" "vstring2")
 ("fstring1" "ustring2")
 ("gstring1" "tstring2"))

CL-USER 5 > (def-view-class sqltest ()
	      ((s1 :type (string 10) :db-kind :key)
	       (s2 :type (string 9))))
#<db-class SQLTEST>

CL-USER 6 > (dolist (object (select 'sqltest :flatp t))  ; object query
	      (format t "~S ~S ~S~%"
		      object
		      (slot-value object 's1)
		      (slot-value object 's2)))
#<db-instance SQLTEST 544065892> "astring1" "zstring2"
#<db-instance SQLTEST 544067332> "bstring1" "ystring2"
#<db-instance SQLTEST 544067436> "cstring1" "xstring2"
#<db-instance SQLTEST 544067540> "dstring1" "wstring2"
#<db-instance SQLTEST 544067644> "estring1" "vstring2"
#<db-instance SQLTEST 544067748> "fstring1" "ustring2"
#<db-instance SQLTEST 544067852> "gstring1" "tstring2"
NIL

CL-USER 7 > 

-- 
Martin Simmons                            Email: [email protected]
Xanalys Ltd, Compass House, Vision Park   TEL:   +44 1223 257944
Histon, Cambridge CB4 9AD, England.       FAX:   +44 1223 257812