forked from 05bit/peewee-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeewee_asyncext.py
88 lines (61 loc) · 2.68 KB
/
peewee_asyncext.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
peewee-async
============
Asynchronous interface for `peewee`_ ORM powered by `asyncio`_:
https://github.com/05bit/peewee-async
.. _peewee: https://github.com/coleifer/peewee
.. _asyncio: https://docs.python.org/3/library/asyncio.html
Licensed under The MIT License (MIT)
Copyright (c) 2014, Alexey Kinëv <[email protected]>
"""
from playhouse.db_url import register_database
from peewee_async import AsyncPostgresqlMixin
import playhouse.postgres_ext as ext
class PostgresqlExtDatabase(AsyncPostgresqlMixin, ext.PostgresqlExtDatabase):
"""PosgreSQL database extended driver providing **single drop-in sync**
connection and **single async connection** interface.
JSON fields support is always enabled, HStore supports is enabled by default,
but can be disabled with ``register_hstore=False`` argument.
Example::
database = PostgresqlExtDatabase('test', register_hstore=False)
See also:
https://peewee.readthedocs.io/en/latest/peewee/playhouse.html#PostgresqlExtDatabase
"""
def init(self, database, **kwargs):
self.min_connections = 1
self.max_connections = 1
super().init(database, **kwargs)
self.init_async(enable_json=True,
enable_hstore=self.register_hstore)
@property
def use_speedups(self):
return False
@use_speedups.setter
def use_speedups(self, value):
pass
register_database(PostgresqlExtDatabase, 'postgresext+async', 'postgresqlext+async')
class PooledPostgresqlExtDatabase(AsyncPostgresqlMixin, ext.PostgresqlExtDatabase):
"""PosgreSQL database extended driver providing **single drop-in sync**
connection and **async connections pool** interface.
JSON fields support is always enabled, HStore supports is enabled by default,
but can be disabled with ``register_hstore=False`` argument.
:param max_connections: connections pool size
Example::
database = PooledPostgresqlExtDatabase('test', register_hstore=False,
max_connections=20)
See also:
https://peewee.readthedocs.io/en/latest/peewee/playhouse.html#PostgresqlExtDatabase
"""
def init(self, database, **kwargs):
self.min_connections = kwargs.pop('min_connections', 1)
self.max_connections = kwargs.pop('max_connections', 20)
super().init(database, **kwargs)
self.init_async(enable_json=True,
enable_hstore=self.register_hstore)
@property
def use_speedups(self):
return False
@use_speedups.setter
def use_speedups(self, value):
pass
register_database(PooledPostgresqlExtDatabase, 'postgresext+pool+async', 'postgresqlext+pool+async')