-
Notifications
You must be signed in to change notification settings - Fork 2
/
manager.dart
63 lines (49 loc) · 1.64 KB
/
manager.dart
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
import 'dart:async';
import 'package:conn_pool/conn_pool.dart';
import 'package:postgres/postgres.dart';
/// [ConnectionManager] for Postgres database
class PostgresManager extends ConnectionManager<PostgreSQLConnection> {
/// Hostname of database this connection refers to.
final String host;
/// Port of database this connection refers to.
final int port;
/// Name of database this connection refers to.
final String databaseName;
/// Username for authenticating this connection.
final String username;
/// Password for authenticating this connection.
final String password;
/// Whether or not this connection should connect securely.
final bool useSsl;
/// The amount of time this connection will wait during connecting before
/// giving up.
final int timeoutInSeconds;
/// The timezone of this connection for date operations that don't specify a
/// timezone.
final String timeZone;
PostgresManager(this.databaseName,
{this.host: 'localhost',
this.port: 5432,
this.username: 'postgres',
this.password,
this.useSsl: false,
this.timeoutInSeconds: 30,
this.timeZone: "UTC"});
@override
/// Opens a new [PostgreSQLConnection]
Future<PostgreSQLConnection> open() async {
PostgreSQLConnection conn = PostgreSQLConnection(host, port, databaseName,
username: username,
password: password,
useSSL: useSsl,
timeoutInSeconds: timeoutInSeconds,
timeZone: timeZone);
await conn.open();
return conn;
}
@override
/// Closes the [connection]
Future<void> close(PostgreSQLConnection connection) {
return connection.close();
}
}