From f75f9d9d2a5b373489bd39f6650b7f3cc3562147 Mon Sep 17 00:00:00 2001 From: codingconcepts Date: Fri, 12 Apr 2024 13:25:23 +0100 Subject: [PATCH] feat: Example of importing into remote database using psql --- README.md | 7 +++++++ examples/person/config.yaml | 12 +++--------- examples/person/create.sql | 16 ++++++++-------- examples/person/insert.sql | 13 +++++-------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 841b9cc..dc2a2f9 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,13 @@ CSV DATA ( WITH skip='1', nullif = '', allow_quoted_null; ``` +If you're working with a remote database, try importing the CSV file as follows: + +``` sh +psql "postgres://root@localhost:26257/defaultdb?sslmode=disable" \ + -c "COPY person (id, full_name, date_of_birth, user_type, favourite_animal) FROM STDIN WITH DELIMITER ',' CSV HEADER NULL E''" < ./csvs/person/person.csv +``` + ### Tables Table elements instruct dg to generate data for a single table and output it as a csv file. Here are the configuration options for a table: diff --git a/examples/person/config.yaml b/examples/person/config.yaml index 7d335ec..af387a3 100644 --- a/examples/person/config.yaml +++ b/examples/person/config.yaml @@ -1,13 +1,12 @@ tables: # Generate data for a person table, showing off a couple of column generators. - name: person - count: 100 + count: 100000 columns: - name: id - type: inc + type: gen processor: - start: 1 - format: "P%03d" + value: ${uuid} - name: full_name type: gen processor: @@ -17,11 +16,6 @@ tables: processor: value: ${date} format: 2006-01-02 - - name: sku - type: gen - processor: - value: SKU${uint16} - format: "%05d" - name: user_type type: set processor: diff --git a/examples/person/create.sql b/examples/person/create.sql index e5a478e..209fd6d 100644 --- a/examples/person/create.sql +++ b/examples/person/create.sql @@ -1,10 +1,10 @@ +CREATE TYPE person_type AS ENUM ('admin', 'regular', 'read-only'); +CREATE TYPE animal_type AS ENUM ('rabbit', 'dog', 'cat'); + CREATE TABLE person ( - "uuid" UUID PRIMARY KEY, - "string" STRING, - "date" DATE, - "bool" BOOL, - "int8" INT, - "int16" INT, - "int32" INT, - "int64" INT + "id" UUID PRIMARY KEY, + "full_name" STRING NOT NULL, + "date_of_birth" DATE NOT NULL, + "user_type" person_type NOT NULL, + "favourite_animal" animal_type NOT NULL ); \ No newline at end of file diff --git a/examples/person/insert.sql b/examples/person/insert.sql index e2010fe..27459dc 100644 --- a/examples/person/insert.sql +++ b/examples/person/insert.sql @@ -1,12 +1,9 @@ IMPORT INTO "person"( - "uuid", - "string", - "date", - "bool", - "int8", - "int16", - "int32", - "int64" + "id", + "full_name", + "date_of_birth", + "user_type", + "favourite_animal" ) CSV DATA ( 'http://localhost:3000/person.csv'