asyncpg-typed 0.1.1__tar.gz → 0.1.2__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 (23) hide show
  1. {asyncpg_typed-0.1.1/asyncpg_typed.egg-info → asyncpg_typed-0.1.2}/PKG-INFO +27 -4
  2. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/README.md +26 -3
  3. asyncpg_typed-0.1.2/asyncpg_typed/__init__.py +681 -0
  4. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2/asyncpg_typed.egg-info}/PKG-INFO +27 -4
  5. asyncpg_typed-0.1.2/tests/test_code.py +251 -0
  6. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/test_data.py +104 -31
  7. asyncpg_typed-0.1.1/asyncpg_typed/__init__.py +0 -877
  8. asyncpg_typed-0.1.1/tests/test_code.py +0 -186
  9. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/LICENSE +0 -0
  10. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/MANIFEST.in +0 -0
  11. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed/py.typed +0 -0
  12. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed.egg-info/SOURCES.txt +0 -0
  13. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed.egg-info/dependency_links.txt +0 -0
  14. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed.egg-info/requires.txt +0 -0
  15. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed.egg-info/top_level.txt +0 -0
  16. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/asyncpg_typed.egg-info/zip-safe +0 -0
  17. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/pyproject.toml +0 -0
  18. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/setup.cfg +0 -0
  19. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/__init__.py +0 -0
  20. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/connection.py +0 -0
  21. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/test_template.py +0 -0
  22. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/test_type.py +0 -0
  23. {asyncpg_typed-0.1.1 → asyncpg_typed-0.1.2}/tests/test_vector.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: asyncpg_typed
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Type-safe queries for asyncpg
5
5
  Author-email: Levente Hunyadi <hunyadi@gmail.com>
6
6
  Maintainer-email: Levente Hunyadi <hunyadi@gmail.com>
@@ -74,6 +74,25 @@ try:
74
74
 
75
75
  finally:
76
76
  await conn.close()
77
+
78
+ # create a list of data-class instances from a list of typed tuples
79
+ @dataclass
80
+ class DataObject:
81
+ boolean_value: bool
82
+ integer_value: int
83
+ string_value: str | None
84
+
85
+ # ✅ Valid initializer call
86
+ items = [DataObject(*row) for row in rows]
87
+
88
+ @dataclass
89
+ class MismatchedObject:
90
+ boolean_value: bool
91
+ integer_value: int
92
+ string_value: str
93
+
94
+ # ⚠️ Argument of type "int | None" cannot be assigned to parameter "integer_value" of type "int" in function "__init__"; "None" is not assignable to "int"
95
+ items = [MismatchedObject(*row) for row in rows]
77
96
  ```
78
97
 
79
98
 
@@ -137,7 +156,7 @@ The parameters `arg` and `result` take a single type `P` or `R`. Passing a simpl
137
156
 
138
157
  The number of types in `args` must correspond to the number of query parameters. (This is validated on calling `sql(...)` for the *t-string* syntax.) The number of types in `resultset` must correspond to the number of columns returned by the query.
139
158
 
140
- Both `args` and `resultset` types must be compatible with their corresponding PostgreSQL query parameter types and resultset column types, respectively. The following table shows the mapping between PostgreSQL and Python types.
159
+ Both `args` and `resultset` types must be compatible with their corresponding PostgreSQL query parameter types and resultset column types, respectively. The following table shows the mapping between PostgreSQL and Python types. When there are multiple options separated by a slash, either of the types can be specified as a source or target type.
141
160
 
142
161
  | PostgreSQL type | Python type |
143
162
  | ----------------- | ------------------ |
@@ -154,15 +173,19 @@ Both `args` and `resultset` types must be compatible with their corresponding Po
154
173
  | `timetz` | `time` (tz) |
155
174
  | `timestamp` | `datetime` (naive) |
156
175
  | `timestamptz` | `datetime` (tz) |
176
+ | `interval` | `timedelta` |
157
177
  | `char(N)` | `str` |
158
178
  | `varchar(N)` | `str` |
159
179
  | `text` | `str` |
160
180
  | `bytea` | `bytes` |
161
- | `json` | `str` |
162
- | `jsonb` | `str` |
181
+ | `json` | `str`/`JsonType` |
182
+ | `jsonb` | `str`/`JsonType` |
183
+ | `xml` | `str` |
163
184
  | `uuid` | `UUID` |
164
185
  | enumeration | `E: StrEnum` |
165
186
 
187
+ PostgreSQL types `json` and `jsonb` are [returned by asyncpg](https://magicstack.github.io/asyncpg/current/usage.html#type-conversion) as Python type `str`. However, if we specify the union type `JsonType` in `args` or `resultset`, the JSON string is parsed as if by calling `json.loads()`. (`JsonType` is defined in the module `asyncpg_typed`.) If the library `orjson` is present, its faster routines are invoked instead of the slower standard library implementation in the module `json`.
188
+
166
189
  ### Using a SQL object
167
190
 
168
191
  The function `sql` returns an object that derives from the base class `_SQL` and is specific to the number and types of parameters passed in `args` and `resultset`.
@@ -36,6 +36,25 @@ try:
36
36
 
37
37
  finally:
38
38
  await conn.close()
39
+
40
+ # create a list of data-class instances from a list of typed tuples
41
+ @dataclass
42
+ class DataObject:
43
+ boolean_value: bool
44
+ integer_value: int
45
+ string_value: str | None
46
+
47
+ # ✅ Valid initializer call
48
+ items = [DataObject(*row) for row in rows]
49
+
50
+ @dataclass
51
+ class MismatchedObject:
52
+ boolean_value: bool
53
+ integer_value: int
54
+ string_value: str
55
+
56
+ # ⚠️ Argument of type "int | None" cannot be assigned to parameter "integer_value" of type "int" in function "__init__"; "None" is not assignable to "int"
57
+ items = [MismatchedObject(*row) for row in rows]
39
58
  ```
40
59
 
41
60
 
@@ -99,7 +118,7 @@ The parameters `arg` and `result` take a single type `P` or `R`. Passing a simpl
99
118
 
100
119
  The number of types in `args` must correspond to the number of query parameters. (This is validated on calling `sql(...)` for the *t-string* syntax.) The number of types in `resultset` must correspond to the number of columns returned by the query.
101
120
 
102
- Both `args` and `resultset` types must be compatible with their corresponding PostgreSQL query parameter types and resultset column types, respectively. The following table shows the mapping between PostgreSQL and Python types.
121
+ Both `args` and `resultset` types must be compatible with their corresponding PostgreSQL query parameter types and resultset column types, respectively. The following table shows the mapping between PostgreSQL and Python types. When there are multiple options separated by a slash, either of the types can be specified as a source or target type.
103
122
 
104
123
  | PostgreSQL type | Python type |
105
124
  | ----------------- | ------------------ |
@@ -116,15 +135,19 @@ Both `args` and `resultset` types must be compatible with their corresponding Po
116
135
  | `timetz` | `time` (tz) |
117
136
  | `timestamp` | `datetime` (naive) |
118
137
  | `timestamptz` | `datetime` (tz) |
138
+ | `interval` | `timedelta` |
119
139
  | `char(N)` | `str` |
120
140
  | `varchar(N)` | `str` |
121
141
  | `text` | `str` |
122
142
  | `bytea` | `bytes` |
123
- | `json` | `str` |
124
- | `jsonb` | `str` |
143
+ | `json` | `str`/`JsonType` |
144
+ | `jsonb` | `str`/`JsonType` |
145
+ | `xml` | `str` |
125
146
  | `uuid` | `UUID` |
126
147
  | enumeration | `E: StrEnum` |
127
148
 
149
+ PostgreSQL types `json` and `jsonb` are [returned by asyncpg](https://magicstack.github.io/asyncpg/current/usage.html#type-conversion) as Python type `str`. However, if we specify the union type `JsonType` in `args` or `resultset`, the JSON string is parsed as if by calling `json.loads()`. (`JsonType` is defined in the module `asyncpg_typed`.) If the library `orjson` is present, its faster routines are invoked instead of the slower standard library implementation in the module `json`.
150
+
128
151
  ### Using a SQL object
129
152
 
130
153
  The function `sql` returns an object that derives from the base class `_SQL` and is specific to the number and types of parameters passed in `args` and `resultset`.