Skip to content

Commit

Permalink
feat: Example of importing into remote database using psql
Browse files Browse the repository at this point in the history
  • Loading branch information
codingconcepts committed Apr 12, 2024
1 parent 607d837 commit f75f9d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 3 additions & 9 deletions examples/person/config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions examples/person/create.sql
Original file line number Diff line number Diff line change
@@ -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
);
13 changes: 5 additions & 8 deletions examples/person/insert.sql
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit f75f9d9

Please sign in to comment.