postgreslite 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {postgreslite-0.1.2 → postgreslite-0.1.4}/PKG-INFO +1 -1
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite/__init__.py +1 -1
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite/handler.py +6 -1
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite/pool.py +27 -8
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite.egg-info/PKG-INFO +1 -1
- {postgreslite-0.1.2 → postgreslite-0.1.4}/LICENSE +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/README.md +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite.egg-info/SOURCES.txt +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite.egg-info/dependency_links.txt +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/postgreslite.egg-info/top_level.txt +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/setup.cfg +0 -0
- {postgreslite-0.1.2 → postgreslite-0.1.4}/setup.py +0 -0
|
@@ -9,6 +9,11 @@ __all__ = (
|
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
class CustomCursor(sqlite3.Cursor):
|
|
13
|
+
def __init__(self, *args, **kwargs):
|
|
14
|
+
super().__init__(*args, **kwargs)
|
|
15
|
+
|
|
16
|
+
|
|
12
17
|
def dict_factory(cursor: sqlite3.Cursor, row: list) -> dict:
|
|
13
18
|
""" Convert SQLite3 data to dict """
|
|
14
19
|
d = {}
|
|
@@ -44,7 +49,7 @@ class PostgresLite:
|
|
|
44
49
|
db = conn.cursor()
|
|
45
50
|
return PoolConnection(db)
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
def connect_async(self) -> AsyncPoolConnection:
|
|
48
53
|
""" Makes a connection to the database and returns the pool (async) """
|
|
49
54
|
conn = sqlite3.connect(
|
|
50
55
|
self._filename,
|
|
@@ -41,7 +41,7 @@ class PoolConnection:
|
|
|
41
41
|
""" Execute SQL command with args for 'Prepared Statements' """
|
|
42
42
|
data = self._init_executor(query, *args)
|
|
43
43
|
|
|
44
|
-
status_word = query.split(" ")[0].
|
|
44
|
+
status_word = query.strip().split(" ")[0].upper()
|
|
45
45
|
status_code = data.rowcount if data.rowcount > 0 else 0
|
|
46
46
|
if status_word == "SELECT":
|
|
47
47
|
status_code = len(data.fetchall())
|
|
@@ -72,10 +72,12 @@ class AsyncPoolConnection(PoolConnection):
|
|
|
72
72
|
async def _queue_manager(self):
|
|
73
73
|
while True:
|
|
74
74
|
query, args, future = await self._queue.get()
|
|
75
|
+
|
|
75
76
|
try:
|
|
76
77
|
await self._background_task(query, *args, future=future)
|
|
77
|
-
except Exception
|
|
78
|
-
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
|
|
79
81
|
self._queue.task_done()
|
|
80
82
|
|
|
81
83
|
async def _background_task(self, query: str, *args: Any, future: asyncio.Future) -> None:
|
|
@@ -88,6 +90,7 @@ class AsyncPoolConnection(PoolConnection):
|
|
|
88
90
|
query,
|
|
89
91
|
prep.prepared
|
|
90
92
|
)
|
|
93
|
+
|
|
91
94
|
future.set_result(cursor)
|
|
92
95
|
except Exception as e:
|
|
93
96
|
future.set_exception(e)
|
|
@@ -96,7 +99,12 @@ class AsyncPoolConnection(PoolConnection):
|
|
|
96
99
|
""" Initialize SQL executor with args for 'Prepared Statements' """
|
|
97
100
|
future = self.loop.create_future()
|
|
98
101
|
await self._queue.put((query, args, future))
|
|
99
|
-
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
await future
|
|
105
|
+
return future.result()
|
|
106
|
+
except Exception:
|
|
107
|
+
raise future.exception()
|
|
100
108
|
|
|
101
109
|
@property
|
|
102
110
|
def queue_size(self) -> int:
|
|
@@ -111,9 +119,12 @@ class AsyncPoolConnection(PoolConnection):
|
|
|
111
119
|
|
|
112
120
|
async def execute(self, query: str, *args: Any) -> str:
|
|
113
121
|
""" Execute SQL command with args for 'Prepared Statements' """
|
|
114
|
-
|
|
122
|
+
try:
|
|
123
|
+
data = await self._init_executor(query, *args)
|
|
124
|
+
except Exception as e:
|
|
125
|
+
raise e
|
|
115
126
|
|
|
116
|
-
status_word = query.split(" ")[0].
|
|
127
|
+
status_word = query.strip().split(" ")[0].upper()
|
|
117
128
|
status_code = data.rowcount if data.rowcount > 0 else 0
|
|
118
129
|
if status_word == "SELECT":
|
|
119
130
|
status_code = len(data.fetchall())
|
|
@@ -122,10 +133,18 @@ class AsyncPoolConnection(PoolConnection):
|
|
|
122
133
|
|
|
123
134
|
async def fetch(self, query: str, *args: Any) -> list:
|
|
124
135
|
""" Fetch DB data with args for 'Prepared Statements' """
|
|
125
|
-
|
|
136
|
+
try:
|
|
137
|
+
data = await self._init_executor(query, *args)
|
|
138
|
+
except Exception as e:
|
|
139
|
+
raise e
|
|
140
|
+
|
|
126
141
|
return data.fetchall()
|
|
127
142
|
|
|
128
143
|
async def fetchrow(self, query: str, *args: Any) -> dict:
|
|
129
144
|
""" Fetch DB row (one row only) with args for 'Prepared Statements' """
|
|
130
|
-
|
|
145
|
+
try:
|
|
146
|
+
data = await self._init_executor(query, *args)
|
|
147
|
+
except Exception as e:
|
|
148
|
+
raise e
|
|
149
|
+
|
|
131
150
|
return data.fetchone()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|