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.
- 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
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();
deno-postgres
follows node-postgres
API to make transition for Node devs as easy as possible.
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();
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);