Skip to content

caijw/deno-postgres

 
 

Repository files navigation

deno-postgres Build Status Gitter chat

WORK IN PROGRESS PostgreSQL driver for Deno

deno-postgres is being developed based on excellent work of node-postgres and pq.

Most of functionality is not yet implemented.

To Do:

  • connecting to database
  • password handling
  • DSN style connection parameters
  • reading connection parameters from environmental variables
  • termination of connection
  • simple queries (no arguments)
  • parsing Postgres data types to native TS types
  • row description
  • parametrized queries
  • connection pooling
  • parsing error response
  • SSL

Example

import { Client } from "https://deno.land/x/postgres/mod.ts";

async function main() {
    const client = new Client({ user: "user", database: "test" });
    await client.connect();
    const result = await client.query('SELECT $1::text as message', 'Hello world!');
    console.log(result.rows);
    await client.end();
}

main();

API

deno-postgres follows node-postgres API to make transition for Node devs as easy as possible.

Connecting to DB

Currently only explicit connection parameters are handled, but support for environmental variables will be added soon.

import { Client } from "https://deno.land/x/postgres/mod.ts";

const connParameters = {
    user: "user", 
    database: "test",
    application_name: "my_custom_app",
};

const client = new Client(connParameters);
await client.connect();
await client.end();

Queries

Simple query

const result = await client.query('SELECT * FROM some_table;');
console.log(result.rows);

Parametrized query

const result = await client.query('SELECT * FROM people WHERE age > $1 AND age < $2;', 10, 20);
console.log(result.rows);

// equivalent using QueryConfig interface
const result = await client.query({
    text: 'SELECT * FROM people WHERE age > $1 AND age < $2;', 
    args: [10, 20]
});
console.log(result.rows);

About

*WORK IN PROGRESS* PostgreSQL driver for Deno

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%