pglite¶
This page explains how to use ts-sql-query with the pglite driver for local PostgreSQL databases.
Supported databases
Tested with
@electric-sql/pglite ^0.5.2
This information reflects the driver version pinned in this project's devDependencies and exercised by the CI suite. Other compatible versions may work but are not actively tested.
Do not share connections between requests
A ts-sql-query connection object — along with the query runner instances passed to its constructor — represents a dedicated connection to the database.
Therefore, you must not share the same connection object between concurrent HTTP requests. Instead, create a new connection object for each request, along with its own query runners.
Even if the query runner internally uses a connection pool, the ts-sql-query connection still represents a single active connection, acquired from the pool. It must be treated as such and never reused across requests.
Using a single connection¶
Executes queries through a dedicated PgLite connection.
import { PGlite } from '@electric-sql/pglite'
import { PgLiteQueryRunner } from 'ts-sql-query/queryRunners/PgLiteQueryRunner'
const db = await PGlite.create('memory://')
async function main() {
const connection = new DBConnection(new PgLiteQueryRunner(db));
// Do your queries here
connection // ...
}