Skip to content

Commit c9a7995

Browse files
authored
Merge pull request #473 from constructive-io/devin/1766630963-restore-csv-to-pg
feat: restore csv-to-pg package and upgrade to @pgsql/utils
2 parents 0c20bc5 + f5ede1b commit c9a7995

24 files changed

Lines changed: 4562 additions & 7416 deletions

FOOTER.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Common issues and solutions for pgpm, PostgreSQL, and testing.
3838
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
3939
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
4040
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
41-
* [pg-ast](https://www.npmjs.com/package/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
4241

4342
### 🚀 API & Dev Tools
4443

packages/csv-to-pg/CHANGELOG.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
## [2.0.10](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.9...csv-to-pg@2.0.10) (2025-05-30)
7+
8+
**Note:** Version bump only for package csv-to-pg
9+
10+
11+
12+
13+
14+
## [2.0.9](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.8...csv-to-pg@2.0.9) (2025-05-20)
15+
16+
**Note:** Version bump only for package csv-to-pg
17+
18+
19+
20+
21+
22+
## [2.0.8](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.7...csv-to-pg@2.0.8) (2025-05-18)
23+
24+
**Note:** Version bump only for package csv-to-pg
25+
26+
27+
28+
29+
30+
## [2.0.7](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.6...csv-to-pg@2.0.7) (2025-05-18)
31+
32+
**Note:** Version bump only for package csv-to-pg
33+
34+
35+
36+
37+
38+
## [2.0.6](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.5...csv-to-pg@2.0.6) (2025-05-18)
39+
40+
**Note:** Version bump only for package csv-to-pg
41+
42+
43+
44+
45+
46+
## [2.0.5](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.4...csv-to-pg@2.0.5) (2025-05-18)
47+
48+
**Note:** Version bump only for package csv-to-pg
49+
50+
51+
52+
53+
54+
## [2.0.4](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.3...csv-to-pg@2.0.4) (2025-05-16)
55+
56+
**Note:** Version bump only for package csv-to-pg
57+
58+
59+
60+
61+
62+
## [2.0.3](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.2...csv-to-pg@2.0.3) (2025-05-16)
63+
64+
**Note:** Version bump only for package csv-to-pg
65+
66+
67+
68+
69+
70+
## [2.0.2](https://github.com/launchql/launchql/compare/csv-to-pg@2.0.1...csv-to-pg@2.0.2) (2025-05-16)
71+
72+
**Note:** Version bump only for package csv-to-pg
73+
74+
75+
76+
77+
78+
## 2.0.1 (2025-05-16)
79+
80+
**Note:** Version bump only for package csv-to-pg

packages/csv-to-pg/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# csv-to-pg
2+
3+
<p align="center" width="100%">
4+
<img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
9+
<img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
10+
</a>
11+
<a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12+
<a href="https://www.npmjs.com/package/csv-to-pg"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fcsv-to-pg%2Fpackage.json"/></a>
13+
</p>
14+
15+
Create PostgreSQL statements from CSV files
16+
17+
## Installation
18+
19+
```sh
20+
npm install -g csv-to-pg
21+
```
22+
23+
## Usage
24+
25+
The idea for this library was to solve complex CSV scenarios, so currently each CSV requires a config file.
26+
27+
### config
28+
29+
Here is an example of a config.yaml that we can use to parse a csv that has no headers, and uses tab-delimited elements:
30+
31+
```yaml
32+
input: "./myfile.tsv"
33+
output: "./myfile.sql"
34+
schema: myschema
35+
table: mytable
36+
delimeter: "\t"
37+
headers: # order of the headers
38+
- feature
39+
- category
40+
- days
41+
- start
42+
- end
43+
fields:
44+
feature: text
45+
category: text
46+
days: int
47+
start: date
48+
end:
49+
type: date
50+
cast: date # explicitly cast to a date type
51+
```
52+
53+
You can also use JS files or JSON. If you use JS, you can also create ASTs for super custom inserts (read tests).
54+
55+
### run it!
56+
57+
Once you have a config file, simply call it and point to the config:
58+
59+
```sh
60+
csv2pg ./config.yaml
61+
```
62+
63+
## Related LaunchQL Tooling
64+
65+
### 🧪 Testing
66+
67+
* [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
68+
* [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
69+
* [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
70+
71+
### 🧠 Parsing & AST
72+
73+
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
74+
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
75+
* [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
76+
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
77+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
78+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
79+
80+
### 🚀 API & Dev Tools
81+
82+
* [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
83+
* [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
84+
85+
### 🔁 Streaming & Uploads
86+
87+
* [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
88+
* [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
89+
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
90+
* [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
91+
* [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
92+
* [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
93+
94+
### 🧰 CLI & Codegen
95+
96+
* [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
97+
* [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
98+
* [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
99+
* [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
100+
101+
## Disclaimer
102+
103+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
104+
105+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
106+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
schema: 'my-schema',
3+
table: 'my-table',
4+
headers: ['zip', 'lat', 'lon', 'box'],
5+
fields: {
6+
zip: 'int',
7+
bbox: {
8+
type: 'bbox',
9+
from: 'box'
10+
},
11+
location: {
12+
type: 'location',
13+
from: ['lon', 'lat']
14+
}
15+
}
16+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"schema": "my-schema",
3+
"table": "my-table",
4+
"headers": [
5+
"zip",
6+
"lat",
7+
"lon",
8+
"box"
9+
],
10+
"fields": {
11+
"zip": "int",
12+
"bbox": {
13+
"type": "bbox",
14+
"from": "box"
15+
},
16+
"location": {
17+
"type": "location",
18+
"from": [
19+
"lon",
20+
"lat"
21+
]
22+
}
23+
}
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
schema: my-schema
2+
table: my-table
3+
headers:
4+
- zip
5+
- lat
6+
- lon
7+
- box
8+
fields:
9+
zip: int
10+
bbox:
11+
type: bbox
12+
from: box
13+
location:
14+
type: location
15+
from:
16+
- lon
17+
- lat
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zip@latitude@longitude@bbox
2+
90272@34.078725@-118.542228@-118.587533,34.024999,-118.495177,34.13165
3+
90011@34.00707@-118.25867@-118.274021,33.986062,-118.242772,34.030991
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zip,latitude,longitude,bbox
2+
90272,34.078725,-118.542228,"-118.587533,34.024999,-118.495177,34.13165"
3+
90011,34.00707,-118.25867,"-118.274021,33.986062,-118.242772,34.030991"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pyramation,246x246.png (https://images.com/246x246.png)
2+
brazil,246x246.png (https://images.com/246x246.png)
3+
skate,246x246.png (https://images.com/246x246.png)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
391f5dfe-a251-43af-bee5-821e69214d20,95482a0f-ed8e-447d-ab05-318650d2f328,41c74ae0-b474-4aaf-b561-faadbadfc154,id,,,f,,f,uuid,1,,,,,,2020-12-06 01:22:56.703152+00,2020-12-06 01:22:56.703152+00
2+
c32175b2-fe04-496a-8725-4ee35d6b2a3d,95482a0f-ed8e-447d-ab05-318650d2f328,41c74ae0-b474-4aaf-b561-faadbadfc154,owner_id,,,f,,f,uuid,2,,,,,,2020-12-06 01:22:56.703152+00,2020-12-06 01:22:56.703152+00

0 commit comments

Comments
 (0)