Skip to content

Commit

Permalink
Apply 'deflate' function for each values in arguments of find-dao. (f…
Browse files Browse the repository at this point in the history
…ixes #52)
  • Loading branch information
fukamachi committed May 10, 2019
1 parent e5f66f8 commit be0ea57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/core/dao.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
(c2mop:slot-definition-name
(table-column-references-column child)))))))))
else
collect `(:= ,(unlispify field) ,value))))
collect `(:= ,(unlispify field)
,(dao-table-column-deflate slot value)))))
(when op
(sxql:where `(:and ,@op))))))

Expand Down
25 changes: 20 additions & 5 deletions t/dao.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#:prove
#:mito.dao
#:mito.connection
#:mito-test.util))
#:mito-test.util)
(:import-from #:alexandria
#:make-keyword
#:compose))
(in-package :mito-test.dao)

(plan nil)
Expand Down Expand Up @@ -265,22 +268,34 @@
:initarg :name)
(is-admin :col-type :boolean
:initform nil
:initarg :is-admin))
:initarg :is-admin)
(role :col-type (:varchar 12)
:initarg :role
:deflate #'string-downcase
:inflate (compose #'make-keyword #'string-upcase)))
(:metaclass dao-table-class))
(mito:execute-sql
(sxql:drop-table :user :if-exists t))
(mito:ensure-table-exists 'user)

(let ((mito:*mito-logger-stream* t))
(mito:create-dao 'user :name "Admin User A" :is-admin t)
(mito:create-dao 'user :name "User B" :is-admin nil)
(mito:create-dao 'user
:name "Admin User A"
:is-admin t
:role :manager)
(mito:create-dao 'user
:name "User B"
:is-admin nil
:role :end-user)

(let ((user (mito:find-dao 'user :id 1)))
(is (slot-value user 'is-admin) t)
(is-type (mito:object-created-at user) 'local-time:timestamp))
(let ((user (mito:find-dao 'user :id 2)))
(is (slot-value user 'is-admin) nil)
(is-type (mito:object-created-at user) 'local-time:timestamp)))
(is-type (mito:object-created-at user) 'local-time:timestamp))
(let ((user (mito:find-dao 'user :role :manager)))
(ok user)))
(disconnect-toplevel)))

(subtest "timestamp with milliseconds (PostgreSQL)"
Expand Down

0 comments on commit be0ea57

Please sign in to comment.