0
|
1 |
|
|
2 |
# |
|
3 |
# See LICENCE for detail |
|
4 |
# Copyright (c) 2014 IRI |
|
5 |
# |
|
6 |
|
|
7 |
import psycopg2.extras |
|
8 |
|
|
9 |
from twisted.python import log |
|
10 |
|
|
11 |
from txpostgres.txpostgres import Connection, ConnectionPool |
|
12 |
|
|
13 |
|
|
14 |
PIANOROLL_CHANNEL = 'PIANOROLL' |
|
15 |
ANNOTATION_CHANNEL = 'ANNOT' |
|
16 |
|
|
17 |
class DictConnection(Connection): |
|
18 |
|
|
19 |
@staticmethod |
|
20 |
def connectionFactory(*args, **kwargs): |
|
21 |
kwargs['connection_factory'] = psycopg2.extras.DictConnection |
|
22 |
return psycopg2.connect(*args, **kwargs) |
|
23 |
|
|
24 |
|
|
25 |
class DictConnectionPool(ConnectionPool): |
|
26 |
connectionFactory = DictConnection |
|
27 |
|
|
28 |
|
|
29 |
def create_connection_pool(conn_string): |
|
30 |
|
|
31 |
created_connection_pool = DictConnectionPool(None, conn_string) |
|
32 |
|
|
33 |
d = created_connection_pool.start() |
|
34 |
d.addErrback(log.err) |
|
35 |
|
|
36 |
return created_connection_pool, d |