-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate down migration files. (PostgreSQL and MySQL).
- Loading branch information
Showing
12 changed files
with
366 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(defpackage mito.conversion | ||
(:use :cl) | ||
(:import-from :local-time) | ||
(:export :convert-for-driver-type)) | ||
(in-package :mito.conversion) | ||
|
||
(defvar *db-datetime-format* | ||
'((:year 4) #\- (:month 2) #\- (:day 2) #\Space (:hour 2) #\: (:min 2) #\: (:sec 2) #\. (:usec 6) :gmt-offset-or-z)) | ||
|
||
(defvar *db-datetime-format-without-timezone* | ||
'((:year 4) #\- (:month 2) #\- (:day 2) #\Space (:hour 2) #\: (:min 2) #\: (:sec 2) #\. (:usec 6))) | ||
|
||
(defvar *db-date-format* | ||
'((:year 4) #\- (:month 2) #\- (:day 2))) | ||
|
||
(defgeneric convert-for-driver-type (driver-type col-type value) | ||
(:method (driver-type col-type value) | ||
(declare (ignore driver-type col-type)) | ||
value) | ||
(:method (driver-type col-type (value string)) | ||
(declare (ignore driver-type col-type)) | ||
value) | ||
(:method ((driver-type (eql :mysql)) (col-type (eql :boolean)) value) | ||
(ecase value | ||
(t 1) | ||
('nil 0))) | ||
(:method ((driver-type (eql :mysql)) (col-type (eql :datetime)) (value local-time:timestamp)) | ||
(local-time:format-timestring nil value | ||
:format *db-datetime-format-without-timezone*)) | ||
(:method (driver-type (col-type (eql :datetime)) (value local-time:timestamp)) | ||
(local-time:format-timestring nil value | ||
:format *db-datetime-format* | ||
:timezone local-time:+gmt-zone+)) | ||
(:method (driver-type (col-type (eql :date)) (value local-time:timestamp)) | ||
(local-time:format-timestring nil value | ||
:format *db-date-format*)) | ||
(:method (driver-type (col-type (eql :timestamp)) value) | ||
(convert-for-driver-type driver-type :datetime value)) | ||
(:method (driver-type (col-type (eql :timestamptz)) value) | ||
(convert-for-driver-type driver-type :datetime value)) | ||
(:method ((driver-type (eql :sqlite3)) (col-type (eql :boolean)) value) | ||
(ecase value | ||
(t 1) | ||
('nil 0))) | ||
(:method ((driver-type (eql :postgres)) (col-type (eql :boolean)) value) | ||
(ecase value | ||
(t '(:raw "true")) | ||
('nil '(:raw "false"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.