Skip to content

Commit

Permalink
doc: postgres datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo committed Feb 7, 2022
1 parent 78f9a8a commit 3a13448
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/docs/content/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ Synth's `datasource` generator is used to pull data from an external source. The
number, or booleans as well as complex values like an array or object.

The `path` option is a URI like the `--from` option for the [import command](/docs/getting_started/command-line#command-import).
Currently only JSON files are supported, and hence only the `json:` scheme is valid. For any file, the path is relative
to where `synth generate` is run from.
Currently only JSON files and Postgres are supported, and hence only the `json:` and `postgres:` schemes are valid. For
any file, the path is relative to where `synth generate` is run from.

The `cycle` is optional and defaults to `false`. It allows you to read a datasource from the beginning once it has been
exhausted when set to `true`.

The `query` option is required when pulling data from any database source. The option defines the query used for fetching
each item from the database.

The `schema` option only works for a Postgres `path` to optionally change the schema the `query` will be run against.

### JSON
When pulling from a JSON file, the JSON is expected to be an array with every item being the value for a single Synth
generator. The following is a valid JSON datasource:
Expand All @@ -34,3 +39,18 @@ When generating more than 3 items `cycle` will need to be `true` for this dataso
"cycle": true
}
```

### Postgres
Pulling from Postgres will need a query of the data to pull. Unlike a JSON source, the output will always be an object
where the column names will be keys.

#### Example

```json synth
{
"type": "datasource",
"path": "postgres://user:password@db-address:5432",
"query": "SELECT name FROM doctors",
"schema": "anonymized"
}
```

0 comments on commit 3a13448

Please sign in to comment.