tracktolib 0.57.0__tar.gz → 0.58.1__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.1
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.1"
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.1"
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')
@@ -94,7 +94,9 @@ def insert_many(engine: Connection | Cursor, table: LiteralString, data: Sequenc
94
94
 
95
95
 
96
96
  @overload
97
- def insert_one(engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: None = None) -> None: ...
97
+ def insert_one(
98
+ engine: Connection | Cursor, table: LiteralString, data: Mapping[str, Any], returning: None = None
99
+ ) -> None: ...
98
100
 
99
101
 
100
102
  @overload
@@ -103,22 +105,32 @@ def insert_one(
103
105
  ) -> dict: ...
104
106
 
105
107
 
108
+ @overload
109
+ def insert_one(
110
+ engine: Cursor, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString]
111
+ ) -> DictRow | TupleRow | None: ...
112
+
113
+
106
114
  def insert_one(
107
- engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString] | None = None
108
- ) -> dict | None:
115
+ engine: Connection | Cursor,
116
+ table: LiteralString,
117
+ data: Mapping[str, Any],
118
+ returning: list[LiteralString] | None = None,
119
+ ) -> dict | DictRow | TupleRow | None:
109
120
  query, _data = get_insert_data(table, [data])
110
121
  _is_returning = False
111
122
  if returning:
112
123
  query = f"{query} RETURNING {','.join(returning)}"
113
124
  _is_returning = True
114
125
 
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()
126
+ if isinstance(engine, Connection):
127
+ with engine.cursor(row_factory=dict_row) as cur:
128
+ _ = cur.execute(query, _data[0])
129
+ resp = cur.fetchone() if _is_returning else None
130
+ engine.commit()
131
+ else:
132
+ _ = engine.execute(query, _data[0])
133
+ resp = engine.fetchone() if _is_returning else None
122
134
  return resp
123
135
 
124
136
 
File without changes
File without changes