Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/dao/column.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@
(truncate value)
(local-time:universal-to-timestamp sec :nsec (* (round (* nsec 1000000)) 1000))))
(string
(local-time:parse-timestring value :date-time-separator #\Space))
(unless (string= value "")
(local-time:parse-timestring value :date-time-separator #\Space)))
(null nil)))
(:method ((col-type (eql :date)) value)
(etypecase value
(integer
(local-time:universal-to-timestamp value))
(string
(ppcre:register-groups-bind ((#'parse-integer year month day))
("^(\\d{4})-(\\d{2})-(\\d{2})$" value)
(local-time:universal-to-timestamp
(encode-universal-time 0 0 0 day month year))))
(unless (string= value "")
(ppcre:register-groups-bind ((#'parse-integer year month day))
("^(\\d{4})-(\\d{2})-(\\d{2})$" value)
(local-time:universal-to-timestamp
(encode-universal-time 0 0 0 day month year)))))
(null nil)))
(:method ((col-type (eql :timestamp)) value)
(inflate-for-col-type :datetime value))
Expand Down
13 changes: 12 additions & 1 deletion t/class.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(:use #:cl
#:rove
#:mito.class
#:mito-test.util))
#:mito-test.util)
(:import-from #:mito.dao.column
#:inflate-for-col-type))
(in-package #:mito-test.class)

(deftest create-table
Expand Down Expand Up @@ -326,3 +328,12 @@
created_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ
)"))

(deftest inflate-for-col-type-null-string
(testing "empty string treated as nil for nullable timestamp/date columns"
(ok (null (inflate-for-col-type :datetime ""))
"empty string inflates to nil for :datetime")
(ok (null (inflate-for-col-type :timestamp ""))
"empty string inflates to nil for :timestamp")
(ok (null (inflate-for-col-type :date ""))
"empty string inflates to nil for :date")))
Loading