graphile / graphile/discussion
CLI: `postgraphile copy`
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
I'm submitting a ...
* [ ] bug report
* [x] feature request
* [ ] question
I think a great addition to the CLI (and library) would be a `copy` command with the following semantics:
```sh
Usage: postgraphile copy
Options:
--table the PostgreSQL table name to copy from/to
-c, --connection the PostgreSQL database name or connection string. If omitted, inferred from environmental variables (see https://www.postgresql.org/docs/current/static/libpq-envars.html). Examples: 'db', 'postgres:///db', 'postgres://user:password@domain:port/db?ssl=1'
-s, --schema a Postgres schema to be introspected. Use commas to define multiple schemas
```
This utility would be a lightweight wrapper around native PostgreSQL `COPY` functionality. Importantly, JSON documents read from STDIN (or written to STDOUT) would be transformed through the same inflector logic `postgraphile` normally uses when serializing/deserializing rows to/from GraphQL queries.
**Example CLI Usage:**
```sh
# export data to a file as JSON
postgraphile copy -s public --table authors > authors.json
# import JSON data from a file
cat authors.json | postgraphile copy -s public --table authors
```
**Example Library Usage:**
```ts
import * as fs from 'fs';
import { createReadStream, createWriteStream } from 'postgraphile';
// export data
createReadStream(pgConfig, { schema, table })
.pipe(fs.createWriteStream('./authors.json'));
// import data
fs.createReadStream('./authors.json')
.pipe(createWriteStream(pgConfig, { schema, table });
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.