mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-08 07:16:58 +02:00
When the notion of a connection class with a generic set of method was invented, the very flexible specification formats available for the file based sources where not integrated into the new connection system. This patch provides a new connection class md-connection with a specific sub-protocol (after opening a connection, the caller is supposed to loop around open-next-stream) so that it's possible to both properly fit into the connection concept and to better share the code in between our three implementation (csv, copy, fixed).
44 lines
1.6 KiB
Common Lisp
44 lines
1.6 KiB
Common Lisp
;;;
|
|
;;; Experimental code, used to be used a long time ago, before this lisp
|
|
;;; code became pgloader. The idea is to use it again sometimes, someway.
|
|
;;;
|
|
(in-package #:pgloader.csv)
|
|
|
|
;;;
|
|
;;; When you exported a whole database as a bunch of CSV files to be found
|
|
;;; in the same directory, each file name being the name of the target
|
|
;;; table, then this function allows to import them all at once.
|
|
;;;
|
|
;;; TODO: expose it from the command language, and test it.
|
|
;;;
|
|
(defun import-database (dbname
|
|
&key
|
|
(fd-path-root *fd-path-root*)
|
|
(skip-lines 0)
|
|
(separator #\Tab)
|
|
(quote cl-csv:*quote*)
|
|
(escape cl-csv:*quote-escape*)
|
|
(truncate t)
|
|
only-tables)
|
|
"Export MySQL data and Import it into PostgreSQL"
|
|
(let ((*state* (pgloader.utils:make-pgstate)))
|
|
(report-header)
|
|
(loop
|
|
for (table-name . date-columns) in (pgloader.pgsql:list-tables dbname)
|
|
for filename = (get-pathname dbname table-name
|
|
:fd-path-root fd-path-root)
|
|
when (or (null only-tables)
|
|
(member table-name only-tables :test #'equal))
|
|
do
|
|
(let ((source (make-instance 'copy-csv
|
|
:target-db dbname
|
|
:source (list :filename filename)
|
|
:target table-name
|
|
:skip-lines skip-lines
|
|
:separator separator
|
|
:quote quote
|
|
:escape escape)))
|
|
(copy-from source :truncate truncate))
|
|
finally
|
|
(report-pgstate-stats *state* "Total import time"))))
|