Commit c8fdfc9a authored by ryszard.szopa's avatar ryszard.szopa
Browse files

with-transaction added to create-table, export get-id.

darcs-hash:eabf7415a6af57c8fb59be3a75f71f96211da476
parent 8790c947
......@@ -32,19 +32,20 @@ names is used."))
(list :type (if (not-null-p slot)
(slot-definition-type slot)
`(or db-null ,(slot-definition-type slot)))))))
(postmodern:execute
(sql-compile
`(:create-table ,class-name
,(iter (for slot in (class-non-transient-slots class))
(collect
(cons (slot-definition-name slot) (type-and-reference slot))))
(:primary-key id)))) ;id is hardcoded as a primary key
(dolist (index (mapcar (lambda (x) (if (consp x) x (list x)))(db-class-indices class)))
(postmodern:execute (sql-compile `(:create-index (:raw ,(index-name index))
:on ,class-name
:fields ,@index))))
(postmodern:execute (:create-sequence (id-seq-name class)))))
(postmodern:with-transaction ()
(postmodern:execute
(sql-compile
`(:create-table ,class-name
,(iter (for slot in (class-non-transient-slots class))
(collect
(cons (slot-definition-name slot) (type-and-reference slot))))
(:primary-key id)))) ;id is hardcoded as a primary key
(dolist (index (mapcar (lambda (x) (if (consp x) x (list x)))(db-class-indices class)))
(postmodern:execute (sql-compile `(:create-index (:raw ,(index-name index))
:on ,class-name
:fields ,@index))))
(postmodern:execute (:create-sequence (id-seq-name class))))))
(database-error (err)
(if (string= (database-error-code err) "42P07") ;table already exists
(progn
......
......@@ -11,5 +11,5 @@
#:class-name-of #:class-non-transient-slots #:slot-value-or-id-if-foreign
#:with-connection #:with-object-connection #:with-class-connection
#:dao #:defdao #:save-dao #:dao-exists-p #:insert-dao #:update-dao #:select-dao #:get-dao))
#:dao #:defdao #:save-dao #:dao-exists-p #:insert-dao #:update-dao #:select-dao #:get-dao #:get-id))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment