database-wrapper-pgsql 0.2.14__tar.gz → 0.2.17__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.
Files changed (17) hide show
  1. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/PKG-INFO +2 -2
  2. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/connector.py +35 -45
  3. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/db_wrapper_pgsql.py +2 -1
  4. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/db_wrapper_pgsql_async.py +2 -1
  5. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/db_wrapper_pgsql_mixin.py +9 -18
  6. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/pg_introspector.py +1 -0
  7. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/type_mapping.py +5 -4
  8. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql.egg-info/PKG-INFO +2 -2
  9. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql.egg-info/requires.txt +1 -1
  10. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/pyproject.toml +2 -2
  11. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/README.md +0 -0
  12. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/__init__.py +7 -7
  13. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql/py.typed +0 -0
  14. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql.egg-info/SOURCES.txt +0 -0
  15. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql.egg-info/dependency_links.txt +0 -0
  16. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/database_wrapper_pgsql.egg-info/top_level.txt +0 -0
  17. {database_wrapper_pgsql-0.2.14 → database_wrapper_pgsql-0.2.17}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: database_wrapper_pgsql
3
- Version: 0.2.14
3
+ Version: 0.2.17
4
4
  Summary: database_wrapper for PostgreSQL database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.2.14
35
+ Requires-Dist: database_wrapper==0.2.17
36
36
  Requires-Dist: psycopg[binary]>=3.2.0
37
37
  Requires-Dist: psycopg[pool]>=3.2.0
38
38
 
@@ -1,22 +1,16 @@
1
+ from collections.abc import AsyncIterator, Iterator
1
2
  from contextlib import asynccontextmanager, contextmanager
2
3
  from contextvars import ContextVar
3
- from typing import Any, AsyncIterator, Iterator, NotRequired, TypedDict, cast
4
-
5
- from psycopg import (
6
- # Async
7
- AsyncConnection as PgConnectionAsync,
8
- AsyncCursor as PgCursorAsync,
9
- AsyncTransaction,
10
- # Sync
11
- Connection as PgConnection,
12
- Cursor as PgCursor,
13
- Transaction,
14
- )
15
- from psycopg.rows import (
16
- DictRow as PgDictRow,
17
- dict_row as PgDictRowFactory,
18
- )
19
- from psycopg_pool import ConnectionPool, AsyncConnectionPool
4
+ from typing import Any, NotRequired, TypedDict, cast
5
+
6
+ from psycopg import AsyncConnection as PgConnectionAsync # Async
7
+ from psycopg import AsyncCursor as PgCursorAsync
8
+ from psycopg import AsyncTransaction, Transaction
9
+ from psycopg import Connection as PgConnection # Sync
10
+ from psycopg import Cursor as PgCursor
11
+ from psycopg.rows import DictRow as PgDictRow
12
+ from psycopg.rows import dict_row as PgDictRowFactory
13
+ from psycopg_pool import AsyncConnectionPool, ConnectionPool
20
14
 
21
15
  from database_wrapper import DatabaseBackend
22
16
 
@@ -97,7 +91,7 @@ class PgSQL(DatabaseBackend):
97
91
  password=self.config["password"],
98
92
  dbname=self.config["database"],
99
93
  connect_timeout=self.connection_timeout,
100
- row_factory=PgDictRowFactory, # type: ignore
94
+ row_factory=PgDictRowFactory,
101
95
  **self.config["kwargs"],
102
96
  ),
103
97
  )
@@ -147,14 +141,14 @@ class PgSQL(DatabaseBackend):
147
141
  """Commit DB queries"""
148
142
  assert self.connection, "Connection is not initialized"
149
143
 
150
- self.logger.debug(f"Commit DB queries")
144
+ self.logger.debug("Commit DB queries")
151
145
  self.connection.commit()
152
146
 
153
147
  def rollback(self) -> None:
154
148
  """Rollback DB queries"""
155
149
  assert self.connection, "Connection is not initialized"
156
150
 
157
- self.logger.debug(f"Rollback DB queries")
151
+ self.logger.debug("Rollback DB queries")
158
152
  self.connection.rollback()
159
153
 
160
154
 
@@ -216,7 +210,7 @@ class PgSQLAsync(DatabaseBackend):
216
210
  password=self.config["password"],
217
211
  dbname=self.config["database"],
218
212
  connect_timeout=self.connection_timeout,
219
- row_factory=PgDictRowFactory, # type: ignore
213
+ row_factory=PgDictRowFactory,
220
214
  **self.config["kwargs"],
221
215
  )
222
216
  self.cursor = self.connection.cursor(row_factory=PgDictRowFactory)
@@ -275,14 +269,14 @@ class PgSQLAsync(DatabaseBackend):
275
269
  """Commit DB queries"""
276
270
  assert self.connection, "Connection is not initialized"
277
271
 
278
- self.logger.debug(f"Commit DB queries")
272
+ self.logger.debug("Commit DB queries")
279
273
  await self.connection.commit()
280
274
 
281
275
  async def rollback(self) -> None:
282
276
  """Rollback DB queries"""
283
277
  assert self.connection, "Connection is not initialized"
284
278
 
285
- self.logger.debug(f"Rollback DB queries")
279
+ self.logger.debug("Rollback DB queries")
286
280
  await self.connection.rollback()
287
281
 
288
282
 
@@ -352,23 +346,23 @@ class PgSQLWithPooling(DatabaseBackend):
352
346
  super().__init__(db_config, connection_timeout, instance_name)
353
347
 
354
348
  # Set defaults
355
- if not "port" in self.config or not self.config["port"]:
349
+ if "port" not in self.config or not self.config["port"]:
356
350
  self.config["port"] = 5432
357
351
 
358
- if not "ssl" in self.config or not self.config["ssl"]:
352
+ if "ssl" not in self.config or not self.config["ssl"]:
359
353
  self.config["ssl"] = "prefer"
360
354
 
361
- if not "kwargs" in self.config or not self.config["kwargs"]:
355
+ if "kwargs" not in self.config or not self.config["kwargs"]:
362
356
  self.config["kwargs"] = {}
363
357
 
364
- if not "autocommit" in self.config["kwargs"]:
358
+ if "autocommit" not in self.config["kwargs"]:
365
359
  self.config["kwargs"]["autocommit"] = True
366
360
 
367
361
  # Connection pooling defaults
368
- if not "maxconnections" in self.config or not self.config["maxconnections"]:
362
+ if "maxconnections" not in self.config or not self.config["maxconnections"]:
369
363
  self.config["maxconnections"] = 5
370
364
 
371
- if not "pool_kwargs" in self.config or not self.config["pool_kwargs"]:
365
+ if "pool_kwargs" not in self.config or not self.config["pool_kwargs"]:
372
366
  self.config["pool_kwargs"] = {}
373
367
 
374
368
  conn_str = (
@@ -536,14 +530,14 @@ class PgSQLWithPooling(DatabaseBackend):
536
530
  """Commit DB queries"""
537
531
  assert self.connection, "Connection is not initialized"
538
532
 
539
- self.logger.debug(f"Commit DB queries")
533
+ self.logger.debug("Commit DB queries")
540
534
  self.connection.commit()
541
535
 
542
536
  def rollback(self) -> None:
543
537
  """Rollback DB queries"""
544
538
  assert self.connection, "Connection is not initialized"
545
539
 
546
- self.logger.debug(f"Rollback DB queries")
540
+ self.logger.debug("Rollback DB queries")
547
541
  self.connection.rollback()
548
542
 
549
543
 
@@ -594,9 +588,7 @@ class PgSQLWithPoolingAsync(DatabaseBackend):
594
588
  cursor: PgCursorTypeAsync | None
595
589
  """ Cursor to database """
596
590
 
597
- context_connection_async: ContextVar[
598
- tuple[PgConnectionTypeAsync, PgCursorTypeAsync] | None
599
- ]
591
+ context_connection_async: ContextVar[tuple[PgConnectionTypeAsync, PgCursorTypeAsync] | None]
600
592
  """ Connection used in async context manager """
601
593
 
602
594
  ########################
@@ -620,23 +612,23 @@ class PgSQLWithPoolingAsync(DatabaseBackend):
620
612
  super().__init__(db_config, connection_timeout, instance_name)
621
613
 
622
614
  # Set defaults
623
- if not "port" in self.config or not self.config["port"]:
615
+ if "port" not in self.config or not self.config["port"]:
624
616
  self.config["port"] = 5432
625
617
 
626
- if not "ssl" in self.config or not self.config["ssl"]:
618
+ if "ssl" not in self.config or not self.config["ssl"]:
627
619
  self.config["ssl"] = "prefer"
628
620
 
629
- if not "kwargs" in self.config or not self.config["kwargs"]:
621
+ if "kwargs" not in self.config or not self.config["kwargs"]:
630
622
  self.config["kwargs"] = {}
631
623
 
632
- if not "autocommit" in self.config["kwargs"]:
624
+ if "autocommit" not in self.config["kwargs"]:
633
625
  self.config["kwargs"]["autocommit"] = True
634
626
 
635
627
  # Connection pooling defaults
636
- if not "maxconnections" in self.config or not self.config["maxconnections"]:
628
+ if "maxconnections" not in self.config or not self.config["maxconnections"]:
637
629
  self.config["maxconnections"] = 5
638
630
 
639
- if not "pool_kwargs" in self.config or not self.config["pool_kwargs"]:
631
+ if "pool_kwargs" not in self.config or not self.config["pool_kwargs"]:
640
632
  self.config["pool_kwargs"] = {}
641
633
 
642
634
  conn_str = (
@@ -720,9 +712,7 @@ class PgSQLWithPoolingAsync(DatabaseBackend):
720
712
  while not self.shutdown_requested.is_set():
721
713
  connection = None
722
714
  try:
723
- connection = await self.pool_async.getconn(
724
- timeout=self.connection_timeout
725
- )
715
+ connection = await self.pool_async.getconn(timeout=self.connection_timeout)
726
716
  cursor = connection.cursor(row_factory=PgDictRowFactory)
727
717
 
728
718
  # Lets do some socket magic
@@ -824,12 +814,12 @@ class PgSQLWithPoolingAsync(DatabaseBackend):
824
814
  """Commit DB queries"""
825
815
  assert self.connection, "Connection is not initialized"
826
816
 
827
- self.logger.debug(f"Commit DB queries")
817
+ self.logger.debug("Commit DB queries")
828
818
  await self.connection.commit()
829
819
 
830
820
  async def rollback(self) -> None:
831
821
  """Rollback DB queries"""
832
822
  assert self.connection, "Connection is not initialized"
833
823
 
834
- self.logger.debug(f"Rollback DB queries")
824
+ self.logger.debug("Rollback DB queries")
835
825
  await self.connection.rollback()
@@ -2,10 +2,11 @@ import logging
2
2
  from typing import Any
3
3
 
4
4
  from psycopg import Cursor, sql
5
+
5
6
  from database_wrapper import DBWrapper
6
7
 
7
- from .db_wrapper_pgsql_mixin import DBWrapperPgSQLMixin
8
8
  from .connector import PgCursorType
9
+ from .db_wrapper_pgsql_mixin import DBWrapperPgSQLMixin
9
10
 
10
11
 
11
12
  class DBWrapperPgSQL(DBWrapperPgSQLMixin, DBWrapper):
@@ -2,10 +2,11 @@ import logging
2
2
  from typing import Any
3
3
 
4
4
  from psycopg import sql
5
+
5
6
  from database_wrapper import DBWrapperAsync
6
7
 
7
- from .db_wrapper_pgsql_mixin import DBWrapperPgSQLMixin
8
8
  from .connector import PgCursorTypeAsync
9
+ from .db_wrapper_pgsql_mixin import DBWrapperPgSQLMixin
9
10
 
10
11
 
11
12
  class DBWrapperPgSQLAsync(DBWrapperPgSQLMixin, DBWrapperAsync):
@@ -1,7 +1,8 @@
1
1
  from typing import Any
2
2
 
3
3
  from psycopg import sql
4
- from database_wrapper import OrderByItem, NoParam
4
+
5
+ from database_wrapper import NoParam, OrderByItem
5
6
 
6
7
 
7
8
  class DBWrapperPgSQLMixin:
@@ -69,11 +70,8 @@ class DBWrapperPgSQLMixin:
69
70
  if order_by is None:
70
71
  return None
71
72
 
72
- order_list = [
73
- f"{item[0]} {item[1] if len(item) > 1 and item[1] != None else 'ASC'}"
74
- for item in order_by
75
- ]
76
- return sql.SQL("ORDER BY %s" % ", ".join(order_list)) # type: ignore
73
+ order_list = [f"{item[0]} {item[1] if len(item) > 1 and item[1] is not None else 'ASC'}" for item in order_by]
74
+ return sql.SQL("ORDER BY {}".format(", ".join(order_list)))
77
75
 
78
76
  def limit_query(
79
77
  self,
@@ -88,11 +86,9 @@ class DBWrapperPgSQLMixin:
88
86
  def format_filter(self, key: str, filter: Any) -> tuple[Any, ...]:
89
87
  # TODO: For now we assume that we have that method from DBWrapperMixin
90
88
  # TODO: Its 5am and I am tired, I will fix this later
91
- return super().format_filter(key, filter) # type: ignore
89
+ return super().format_filter(key, filter)
92
90
 
93
- def create_filter(
94
- self, filter: dict[str, Any] | None
95
- ) -> tuple[sql.Composed | None, tuple[Any, ...]]:
91
+ def create_filter(self, filter: dict[str, Any] | None) -> tuple[sql.Composed | None, tuple[Any, ...]]:
96
92
  if filter is None or len(filter) == 0:
97
93
  return (None, tuple())
98
94
 
@@ -111,9 +107,8 @@ class DBWrapperPgSQLMixin:
111
107
  order: sql.SQL | sql.Composed | None,
112
108
  limit: sql.SQL | sql.Composed | None,
113
109
  ) -> sql.Composed:
114
-
115
110
  if isinstance(query, str):
116
- query = sql.SQL(query) # type: ignore
111
+ query = sql.SQL(query)
117
112
 
118
113
  query_parts: list[sql.Composable] = [query]
119
114
  if q_filter is not None:
@@ -136,9 +131,7 @@ class DBWrapperPgSQLMixin:
136
131
  keys = store_data.keys()
137
132
  values = list(store_data.values())
138
133
 
139
- return sql.SQL(
140
- "INSERT INTO {table} ({columns}) VALUES ({values}) RETURNING {id_key}"
141
- ).format(
134
+ return sql.SQL("INSERT INTO {table} ({columns}) VALUES ({values}) RETURNING {id_key}").format(
142
135
  table=table_identifier,
143
136
  columns=sql.SQL(", ").join(map(sql.Identifier, keys)),
144
137
  values=sql.SQL(", ").join(sql.Placeholder() * len(values)),
@@ -152,9 +145,7 @@ class DBWrapperPgSQLMixin:
152
145
  update_data: dict[str, Any],
153
146
  ) -> sql.Composed:
154
147
  keys = update_data.keys()
155
- set_clause = sql.SQL(", ").join(
156
- sql.Identifier(key) + sql.SQL(" = %s") for key in keys
157
- )
148
+ set_clause = sql.SQL(", ").join(sql.Identifier(key) + sql.SQL(" = %s") for key in keys)
158
149
  return sql.SQL("UPDATE {table} SET {set_clause} WHERE {id_key} = %s").format(
159
150
  table=table_identifier,
160
151
  set_clause=set_clause,
@@ -1,6 +1,7 @@
1
1
  import psycopg
2
2
 
3
3
  from database_wrapper import ColumnMetaIntrospector, DBIntrospector
4
+
4
5
  from .type_mapping import map_db_type
5
6
 
6
7
 
@@ -1,13 +1,14 @@
1
1
  # type_mapping_pg.py
2
- from typing import Any, Optional, Tuple
3
- from decimal import Decimal
4
2
  import datetime
3
+ from decimal import Decimal
4
+ from typing import Any
5
+
5
6
  from database_wrapper import SerializeType
6
7
 
7
8
  # Flip this if you want lossless decimals
8
9
  USE_DECIMAL = False
9
10
 
10
- _PG_TO_PY_BASE: dict[str, Tuple[type, Optional[SerializeType]]] = {
11
+ _PG_TO_PY_BASE: dict[str, tuple[type, SerializeType | None]] = {
11
12
  # integers
12
13
  "int2": (int, None),
13
14
  "int4": (int, None),
@@ -39,7 +40,7 @@ _PG_TO_PY_BASE: dict[str, Tuple[type, Optional[SerializeType]]] = {
39
40
 
40
41
  def map_db_type(
41
42
  db_type: str, *, length: int | None = None, precision: int | None = None, scale: int | None = None
42
- ) -> tuple[type, Optional[SerializeType]]:
43
+ ) -> tuple[type, SerializeType | None]:
43
44
  t = db_type.lower()
44
45
  if t == "numeric":
45
46
  if USE_DECIMAL:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: database_wrapper_pgsql
3
- Version: 0.2.14
3
+ Version: 0.2.17
4
4
  Summary: database_wrapper for PostgreSQL database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.2.14
35
+ Requires-Dist: database_wrapper==0.2.17
36
36
  Requires-Dist: psycopg[binary]>=3.2.0
37
37
  Requires-Dist: psycopg[pool]>=3.2.0
38
38
 
@@ -1,3 +1,3 @@
1
- database_wrapper==0.2.14
1
+ database_wrapper==0.2.17
2
2
  psycopg[binary]>=3.2.0
3
3
  psycopg[pool]>=3.2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "database_wrapper_pgsql"
7
- version = "0.2.14"
7
+ version = "0.2.17"
8
8
  description = "database_wrapper for PostgreSQL database"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -35,7 +35,7 @@ classifiers = [
35
35
  ]
36
36
  keywords = ["database", "wrapper", "python", "postgresql", "pgsql"]
37
37
  dependencies = [
38
- "database_wrapper == 0.2.14",
38
+ "database_wrapper == 0.2.17",
39
39
  "psycopg[binary] >= 3.2.0",
40
40
  "psycopg[pool] >= 3.2.0",
41
41
  ]
@@ -8,22 +8,22 @@ Part of the database_wrapper package
8
8
 
9
9
  import logging
10
10
 
11
- from .db_wrapper_pgsql import DBWrapperPgSQL
12
- from .db_wrapper_pgsql_async import DBWrapperPgSQLAsync
13
11
  from .connector import (
14
12
  # Basics
15
13
  PgConfig,
14
+ # Connection and Cursor types
15
+ PgConnectionType,
16
+ PgConnectionTypeAsync,
17
+ PgCursorType,
18
+ PgCursorTypeAsync,
16
19
  # Connectors
17
20
  PgSQL,
18
21
  PgSQLAsync,
19
22
  PgSQLWithPooling,
20
23
  PgSQLWithPoolingAsync,
21
- # Connection and Cursor types
22
- PgConnectionType,
23
- PgCursorType,
24
- PgConnectionTypeAsync,
25
- PgCursorTypeAsync,
26
24
  )
25
+ from .db_wrapper_pgsql import DBWrapperPgSQL
26
+ from .db_wrapper_pgsql_async import DBWrapperPgSQLAsync
27
27
  from .pg_introspector import PostgresIntrospector
28
28
 
29
29
  # Set the logger to a quiet default, can be enabled if needed