mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-05 02:46:10 +02:00
Move all typemod functions at the same place.
Having the parse-column-typemod function in the pgloader.transforms package makes it available from everywhere in the pgloader code base.
This commit is contained in:
parent
1f354131d0
commit
8fce6c84fc
@ -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
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user