PostgreSQL driver for Deno
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib update Deno types Feb 23, 2019
tests fmt Feb 22, 2019
.gitignore update tsconfig, add gitignore, update deno types Jan 15, 2019
.travis.yml check format during CI Feb 22, 2019
LICENSE add LICENSE and licence notices Jan 19, 2019
README.md fmt Feb 22, 2019
client.ts fmt Feb 22, 2019
connection.ts refactor while loop Feb 23, 2019
connection_params.ts fmt Feb 22, 2019
decode.ts fmt Feb 22, 2019
deps.ts fmt Feb 22, 2019
encode.ts fmt Feb 22, 2019
error.ts fmt Feb 22, 2019
format.ts no format for types def Feb 23, 2019
mod.ts fmt Feb 22, 2019
oid.ts fmt Feb 22, 2019
packet_reader.ts fmt Feb 22, 2019
packet_writer.ts fmt Feb 22, 2019
query.ts fmt Feb 22, 2019
test.ts fmt Feb 22, 2019
tsconfig.json fmt Feb 22, 2019
utils.ts fmt Feb 22, 2019

README.md

deno-postgres Build Status Gitter chat

PostgreSQL driver for Deno.

It's still work in progress, but you can take it for a test drive!

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

To Do:

  • connecting to database
  • password handling - cleartext, MD5
  • 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
  • tests, tests, tests

Example

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

async function main() {
  const client = new Client({
    user: "user",
    database: "test",
    host: "localhost",
    port: "5432"
  });
  await client.connect();
  const result = await client.query("SELECT * FROM people;");
  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

If any of parameters is missing it is read from environmental variable.

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

let config;

config = {
  host: "localhost",
  port: "5432",
  user: "user",
  database: "test",
  application_name: "my_custom_app"
};
// alternatively
config = "postgres://user@localhost:5432/test?application_name=my_custom_app";

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

Queries

Simple query

const result = await client.query("SELECT * FROM people;");
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);

License

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

Eveything is licensed under the MIT License.

All additional work is copyright 2018 - 2019 — Bartłomiej Iwańczuk — All rights reserved.