diff --git a/src/package.lisp b/src/package.lisp index a57400d..f9ac82a 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -14,6 +14,8 @@ (:export #:precision #:scale #:intern-symbol + #:parse-column-typemod + #:typemod-expr-matches-p #:typemod-expr-to-function)) (defpackage #:pgloader.logs @@ -439,6 +441,8 @@ #:precision #:scale #:intern-symbol + #:parse-column-typemod + #:typemod-expr-matches-p #:typemod-expr-to-function) (:import-from #:pgloader.parse-date #:parse-date-string diff --git a/src/sources/common/casting-rules.lisp b/src/sources/common/casting-rules.lisp index 702a3ba..3856c9c 100644 --- a/src/sources/common/casting-rules.lisp +++ b/src/sources/common/casting-rules.lisp @@ -10,29 +10,6 @@ (defvar *default-cast-rules* nil "Default casting rules.") (defvar *cast-rules* nil "Specific casting rules added in the command.") -;;; -;;; Handling typmod in the general case, don't apply to ENUM types -;;; -(defun parse-column-typemod (data-type column-type) - "Given int(7), returns the number 7. - - Beware that some data-type are using a typmod looking definition for - things that are not typmods at all: enum." - (unless (or (string= "enum" data-type) - (string= "set" data-type)) - (let ((start-1 (position #\( column-type)) ; just before start position - (end (position #\) column-type))) ; just before end position - (when start-1 - (destructuring-bind (a &optional b) - (mapcar #'parse-integer - (sq:split-sequence #\, column-type - :start (+ 1 start-1) :end end)) - (list a b)))))) - -(defun typemod-expr-matches-p (rule-typemod-expr typemod) - "Check if an expression such as (< 10) matches given typemod." - (funcall (compile nil (typemod-expr-to-function rule-typemod-expr)) typemod)) - (defun parse-column-unsigned (data-type column-type) "See if we find the term unsigned in the column-type." (declare (ignore data-type)) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index 497b154..dbc39b9 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -41,6 +41,29 @@ (intern (string-upcase symbol-name) (find-package "PGLOADER.USER-SYMBOLS")))))))) +;;; +;;; Handling typmod in the general case, don't apply to ENUM types +;;; +(defun parse-column-typemod (data-type column-type) + "Given int(7), returns the number 7. + + Beware that some data-type are using a typmod looking definition for + things that are not typmods at all: enum." + (unless (or (string= "enum" data-type) + (string= "set" data-type)) + (let ((start-1 (position #\( column-type)) ; just before start position + (end (position #\) column-type))) ; just before end position + (when start-1 + (destructuring-bind (a &optional b) + (mapcar #'parse-integer + (sq:split-sequence #\, column-type + :start (+ 1 start-1) :end end)) + (list a b)))))) + +(defun typemod-expr-matches-p (rule-typemod-expr typemod) + "Check if an expression such as (< 10) matches given typemod." + (funcall (compile nil (typemod-expr-to-function rule-typemod-expr)) typemod)) + (defun typemod-expr-to-function (expr) "Transform given EXPR into a callable function object." `(lambda (typemod)