superapp
BackendDatabases

CSV

Query CSV files as tables.

Chat in Claude

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:

OptionTypeDescription
directorystringPath 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

OperationSupported
findMany / findOneYes
createNo
updateNo
deleteNo
count / aggregateYes
TransactionsNo

CSV connections are read-only. Write operations return a 405 Method Not Allowed error.

Directory Layout

data/reports/
├── orders.csv
├── customers.csv
└── organizations.csv

Each 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-17

Querying 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

ProblemCauseFix
No such file or directoryPath does not existVerify the directory path
Could not parse CSVMalformed fileCheck for consistent delimiters and quoting
Empty resultsNo header rowAdd a header row to the CSV file
Wrong column typesAuto-detection mismatchEnsure consistent formatting (dates, numbers) across all rows

On this page