Skip to content

Commit f75f9d9

Browse files
feat: Example of importing into remote database using psql
1 parent 607d837 commit f75f9d9

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ CSV DATA (
170170
WITH skip='1', nullif = '', allow_quoted_null;
171171
```
172172

173+
If you're working with a remote database, try importing the CSV file as follows:
174+
175+
``` sh
176+
psql "postgres://root@localhost:26257/defaultdb?sslmode=disable" \
177+
-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
178+
```
179+
173180
### Tables
174181

175182
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 for: examples/person/config.yaml

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
tables:
22
# Generate data for a person table, showing off a couple of column generators.
33
- name: person
4-
count: 100
4+
count: 100000
55
columns:
66
- name: id
7-
type: inc
7+
type: gen
88
processor:
9-
start: 1
10-
format: "P%03d"
9+
value: ${uuid}
1110
- name: full_name
1211
type: gen
1312
processor:
@@ -17,11 +16,6 @@ tables:
1716
processor:
1817
value: ${date}
1918
format: 2006-01-02
20-
- name: sku
21-
type: gen
22-
processor:
23-
value: SKU${uint16}
24-
format: "%05d"
2519
- name: user_type
2620
type: set
2721
processor:

Diff for: examples/person/create.sql

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
CREATE TYPE person_type AS ENUM ('admin', 'regular', 'read-only');
2+
CREATE TYPE animal_type AS ENUM ('rabbit', 'dog', 'cat');
3+
14
CREATE TABLE person (
2-
"uuid" UUID PRIMARY KEY,
3-
"string" STRING,
4-
"date" DATE,
5-
"bool" BOOL,
6-
"int8" INT,
7-
"int16" INT,
8-
"int32" INT,
9-
"int64" INT
5+
"id" UUID PRIMARY KEY,
6+
"full_name" STRING NOT NULL,
7+
"date_of_birth" DATE NOT NULL,
8+
"user_type" person_type NOT NULL,
9+
"favourite_animal" animal_type NOT NULL
1010
);

Diff for: examples/person/insert.sql

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
IMPORT INTO "person"(
2-
"uuid",
3-
"string",
4-
"date",
5-
"bool",
6-
"int8",
7-
"int16",
8-
"int32",
9-
"int64"
2+
"id",
3+
"full_name",
4+
"date_of_birth",
5+
"user_type",
6+
"favourite_animal"
107
)
118
CSV DATA (
129
'http://localhost:3000/person.csv'

0 commit comments

Comments
 (0)