-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
72 lines (66 loc) · 1.49 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pg_conn_str from "npm:pg-connection-string@^2.7.0";
import { Pool, PoolOptions, Wire, WireOptions } from "./wire.ts";
export {
Wire,
WireOptions,
WireError,
Pool,
PoolOptions,
PostgresError,
type Postgres,
type WireEvents,
type PoolEvents,
type LogLevel,
type Parameters,
type Transaction,
type Channel,
type ChannelEvents,
type NotificationHandler,
} from "./wire.ts";
export {
type SqlFragment,
type SqlType,
type SqlTypeMap,
SqlTypeError,
sql,
sql_types,
sql_format,
is_sql,
Query,
type Result,
type Row,
type Rows,
type RowStream,
} from "./query.ts";
export default function postgres(
s: string,
options: Partial<PoolOptions> = {}
) {
return new Pool(PoolOptions.parse(parse_conn(s, options), { mode: "strip" }));
}
postgres.connect = connect;
export async function connect(s: string, options: Partial<WireOptions> = {}) {
return await new Wire(
WireOptions.parse(parse_conn(s, options), { mode: "strip" })
).connect();
}
function parse_conn(s: string, options: Partial<WireOptions>) {
const {
host,
port,
user,
password,
database,
ssl: _ssl, // TODO: ssl support
...runtime_params
} = s ? pg_conn_str.parse(s) : {};
return {
...options,
host: options.host ?? host,
port: options.port ?? port,
user: options.user ?? user,
password: options.password ?? password,
database: options.database ?? database,
runtime_params: { ...runtime_params, ...options.runtime_params },
};
}