MCPcopy Index your code
hub / github.com/denodrivers/postgres

github.com/denodrivers/postgres @v0.19.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.19.5 ↗ · + Follow
306 symbols 734 edges 35 files 70 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

deno-postgres

Build Status Discord server JSR JSR Score Manual Documentation License

A lightweight PostgreSQL driver for Deno focused on developer experience.\ deno-postgres is inspired by the excellent work of node-postgres and pq.

Documentation

The documentation is available on the deno-postgres website.

Join the Discord as well! It's a good place to discuss bugs and features before opening issues.

Examples

// deno run --allow-net --allow-read mod.ts
import { Client } from "jsr:@db/postgres";

const client = new Client({
  user: "user",
  database: "test",
  hostname: "localhost",
  port: 5432,
});

await client.connect();

{
  const result = await client.queryArray("SELECT ID, NAME FROM PEOPLE");
  console.log(result.rows); // [[1, 'Carlos'], [2, 'John'], ...]
}

{
  const result = await client
    .queryArray`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
  console.log(result.rows); // [[1, 'Carlos']]
}

{
  const result = await client.queryObject("SELECT ID, NAME FROM PEOPLE");
  console.log(result.rows); // [{id: 1, name: 'Carlos'}, {id: 2, name: 'Johnru'}, ...]
}

{
  const result = await client
    .queryObject`SELECT ID, NAME FROM PEOPLE WHERE ID = ${1}`;
  console.log(result.rows); // [{id: 1, name: 'Carlos'}]
}

await client.end();

Deno compatibility

Due to breaking changes introduced in the unstable APIs deno-postgres uses, there has been some fragmentation regarding what versions of Deno can be used alongside the driver.

This situation will stabilize as deno-postgres approach version 1.0.

Deno version Min driver version Max version Note
1.8.x 0.5.0 0.10.0
1.9.0 0.11.0 0.11.1
1.9.1 and up 0.11.2 0.11.3
1.11.0 and up 0.12.0 0.12.0
1.14.0 and up 0.13.0 0.13.0
1.16.0 0.14.0 0.14.3
1.17.0 0.15.0 0.17.1
1.40.0 0.17.2 0.19.3 0.19.3 and down are available in deno.land
2.0.0 and up 0.19.4 - Available on JSR! @db/postgres

Breaking changes

Although deno-postgres is reasonably stable and robust, it is a WIP, and we're still exploring the design. Expect some breaking changes as we reach version 1.0 and enhance the feature set. Please check the Releases for more info on breaking changes. Please reach out if there are any undocumented breaking changes.

Found issues?

Please file an issue with any problems with the driver. If you would like to help, please look at the issues as well. You can pick up one of them and try to implement it.

Contributing

Prerequisites

  • You must have docker and docker-compose installed on your machine

  • https://docs.docker.com/get-docker/

  • https://docs.docker.com/compose/install/

  • You don't need deno installed in your machine to run the tests since it will be installed in the Docker container when you build it. However, you will need it to run the linter and formatter locally

  • https://deno.land/

  • deno upgrade stable
  • dvm install stable && dvm use stable

  • You don't need to install Postgres locally on your machine to test the library; it will run as a service in the Docker container when you build it

Running the tests

The tests are found under the ./tests folder, and they are based on query result assertions.

To run the tests, run the following commands:

  1. docker compose build tests
  2. docker compose run tests

The build step will check linting and formatting as well and report it to the command line

It is recommended that you don't rely on any previously initialized data for your tests instead create all the data you need at the moment of running the tests

For example, the following test will create a temporary table that will disappear once the test has been completed

Deno.test("INSERT works correctly", async () => {
  await client.queryArray(`CREATE TEMP TABLE MY_TEST (X INTEGER);`);
  await client.queryArray(`INSERT INTO MY_TEST (X) VALUES (1);`);
  const result = await client.queryObject<{ x: number }>({
    text: `SELECT X FROM MY_TEST`,
    fields: ["x"],
  });
  assertEquals(result.rows[0].x, 1);
});

Setting up an advanced development environment

More advanced features, such as the Deno inspector, test, and permission filtering, database inspection, and test code lens can be achieved by setting up a local testing environment, as shown in the following steps:

  1. Start the development databases using the Docker service with the command\ docker-compose up postgres_clear postgres_md5 postgres_scram\ Though using the detach (-d) option is recommended, this will make the databases run in the background unless you use docker itself to stop them. You can find more info about this here
  2. Set the DENO_POSTGRES_DEVELOPMENT environmental variable to true, either by prepending it before the test command (on Linux) or setting it globally for all environments

The DENO_POSTGRES_DEVELOPMENT variable will tell the testing pipeline to use the local testing settings specified in tests/config.json instead of the CI settings.

  1. Run the tests manually by using the command\ deno test -A

Contributing guidelines

When contributing to the repository, make sure to:

  1. All features and fixes must have an open issue to be discussed
  2. All public interfaces must be typed and have a corresponding JSDoc block explaining their usage
  3. All code must pass the format and lint checks enforced by deno fmt and deno lint respectively. The build will only pass the tests if these conditions are met. Ignore rules will be accepted in the code base when their respective justification is given in a comment
  4. All features and fixes must have a corresponding test added to be accepted

Maintainers guidelines

When publishing a new version, ensure that the version field in deno.json has been updated to match the new version.

License

There are substantial parts of this library based on other libraries. They have preserved their individual licenses and copyrights.

Everything is licensed under the MIT License.

All additional work is copyright 2018 - 2025 — Bartłomiej Iwańczuk, Steven Guerrero, Hector Ayala — All rights reserved.

Extension points exported contracts — how you extend this code

PostgresUri (Interface)
options from URI per https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
connection/connection_params.ts
KeySignatures (Interface)
* Collection of SCRAM authentication keys derived from a plaintext password * in HMAC-derived binary format
connection/scram.ts
Session (Interface)
(no doc)
client.ts
Notice (Interface)
(no doc)
connection/message.ts
Uri (Interface)
(no doc)
utils/utils.ts
QueryOptions (Interface)
(no doc)
query/query.ts
Box (Interface)
(no doc)
query/types.ts
ConnectionOptions (Interface)
(no doc)
connection/connection_params.ts

Core symbols most depended-on inside this repo

queryArray
called by 166
query/transaction.ts
withClient
called by 56
tests/query_client_test.ts
connect
called by 46
pool.ts
queryObject
called by 45
query/transaction.ts
createParams
called by 37
connection/connection_params.ts
end
called by 35
pool.ts
push
called by 30
utils/deferred.ts
addCString
called by 21
connection/packet.ts

Shape

Function 127
Method 113
Class 48
Interface 14
Enum 4

Languages

TypeScript100%

Modules by API surface

query/decoders.ts36 symbols
connection/connection.ts36 symbols
query/query.ts25 symbols
connection/packet.ts24 symbols
query/transaction.ts22 symbols
client.ts22 symbols
connection/scram.ts18 symbols
utils/deferred.ts15 symbols
client/error.ts12 symbols
query/array_parser.ts10 symbols
pool.ts9 symbols
connection/message.ts9 symbols

Datastores touched

database_nameDatabase · 1 repos
deno_postgresDatabase · 1 repos
test_databaseDatabase · 1 repos

For agents

$ claude mcp add postgres \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page