tracktolib 0.57.0__tar.gz → 0.58.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: tracktolib
3
- Version: 0.57.0
3
+ Version: 0.58.0
4
4
  Summary: Utility library for python
5
5
  License: MIT
6
6
  Keywords: utility
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tracktolib"
3
- version = "0.57.0"
3
+ version = "0.58.0"
4
4
  description = "Utility library for python"
5
5
  authors = ["Julien Brayere <julien.brayere@tracktor.fr>"]
6
6
  license = "MIT"
@@ -83,7 +83,7 @@ pythonPlatform = "Linux"
83
83
 
84
84
  [tool.commitizen]
85
85
  name = "cz_conventional_commits"
86
- version = "0.57.0"
86
+ version = "0.58.0"
87
87
  tag_format = "$version"
88
88
  version_files = [
89
89
  "pyproject.toml:version"
@@ -7,7 +7,7 @@ try:
7
7
  from psycopg import Connection, Cursor
8
8
  from psycopg.abc import Query
9
9
  from psycopg.errors import InvalidCatalogName
10
- from psycopg.rows import dict_row
10
+ from psycopg.rows import dict_row, DictRow, TupleRow
11
11
  from psycopg.types.json import Json
12
12
  except ImportError:
13
13
  raise ImportError('Please install psycopg or tracktolib with "pg-sync" to use this module')
@@ -103,22 +103,32 @@ def insert_one(
103
103
  ) -> dict: ...
104
104
 
105
105
 
106
+ @overload
106
107
  def insert_one(
107
- engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString] | None = None
108
- ) -> dict | None:
108
+ engine: Cursor, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString]
109
+ ) -> DictRow | TupleRow | None: ...
110
+
111
+
112
+ def insert_one(
113
+ engine: Connection | Cursor,
114
+ table: LiteralString,
115
+ data: Mapping[str, Any],
116
+ returning: list[LiteralString] | None = None,
117
+ ) -> dict | DictRow | TupleRow | None:
109
118
  query, _data = get_insert_data(table, [data])
110
119
  _is_returning = False
111
120
  if returning:
112
121
  query = f"{query} RETURNING {','.join(returning)}"
113
122
  _is_returning = True
114
123
 
115
- with engine.cursor(row_factory=dict_row) as cur:
116
- _ = cur.execute(query, _data[0])
117
- if _is_returning:
118
- resp = cur.fetchone()
119
- else:
120
- resp = None
121
- engine.commit()
124
+ if isinstance(engine, Connection):
125
+ with engine.cursor(row_factory=dict_row) as cur:
126
+ _ = cur.execute(query, _data[0])
127
+ resp = cur.fetchone() if _is_returning else None
128
+ engine.commit()
129
+ else:
130
+ _ = engine.execute(query, _data[0])
131
+ resp = engine.fetchone() if _is_returning else None
122
132
  return resp
123
133
 
124
134
 
File without changes
File without changes