CSV
Query CSV files as tables.
Point at a directory of CSV files and query them as read-only tables. Useful for reports, data imports, and static datasets.
import { createEngine } from '@superapp/backend'
const engine = createEngine({
connections: {
reports: { directory: './data/reports' },
},
})Connection Config
CSV connections use an object with a directory field:
| Option | Type | Description |
|---|---|---|
directory | string | Path to directory containing .csv files |
Each .csv file in the directory becomes a table. The file name (without extension) is the table name: orders.csv becomes reports.orders.
How It Works
When the engine starts, it scans the directory and loads each CSV file into memory as a read-only table. Column types, delimiters, and headers are auto-detected.
Capabilities
| Operation | Supported |
|---|---|
findMany / findOne | Yes |
create | No |
update | No |
delete | No |
count / aggregate | Yes |
| Transactions | No |
CSV connections are read-only. Write operations return a 405 Method Not Allowed error.
Directory Layout
data/reports/
├── orders.csv
├── customers.csv
└── organizations.csvEach file should have a header row:
id,amount,status,customer_id,created_at
1,99.99,active,1,2024-01-15
2,149.50,active,2,2024-01-16
3,29.00,pending,1,2024-01-17Querying CSV Data
Once connected, CSV tables work like any other table in the client SDK:
const orders = await db.reports.orders.findMany({
select: ['id', 'amount', 'status'],
where: { status: { $eq: 'active' } },
orderBy: { amount: 'desc' },
limit: 100,
})Combining with Other Sources
A common pattern is a primary Postgres database alongside CSV files for imported data:
const engine = createEngine({
connections: {
main: process.env.PG_URL!,
imports: { directory: './data/imports' },
},
})Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
No such file or directory | Path does not exist | Verify the directory path |
Could not parse CSV | Malformed file | Check for consistent delimiters and quoting |
| Empty results | No header row | Add a header row to the CSV file |
| Wrong column types | Auto-detection mismatch | Ensure consistent formatting (dates, numbers) across all rows |