You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,7 @@ import asyncio
42
42
43
43
# ...
44
44
45
+
45
46
asyncdefa_query() -> None:
46
47
# we'll come back to this part
47
48
# just know that it usins async/await to call Client.execute_and_return
@@ -66,6 +67,7 @@ import asyncio
66
67
67
68
# ...
68
69
70
+
69
71
asyncdefa_query() -> None:
70
72
query ='SELECT table_name' \
71
73
'FROM information_schema.tables' \
@@ -93,6 +95,7 @@ To define a `Model`'s expected type, you simply need to subclass `ModelData` & s
93
95
```python
94
96
from db_wrapper import ModelData
95
97
98
+
96
99
classAModel(ModelData):
97
100
a_string_value: str
98
101
a_number_value: int
@@ -123,6 +126,7 @@ from db_wrapper import (
123
126
connection_parameters = ConnectionParameters(...)
124
127
client = Client(...)
125
128
129
+
126
130
classAModel(ModelData):
127
131
# ...
128
132
@@ -136,6 +140,73 @@ from typing import List
136
140
137
141
# ...
138
142
143
+
139
144
async get_some_record() -> List[AModel]:
140
145
returnawait a_model.read.one_by_id('some record id') #NOTE: in reality the id would be a UUID
141
146
```
147
+
148
+
Of course, just having methods for creating, reading, updating, or deleting a single record at a time often won't be enough.
149
+
Adding additional queries is accomplished by extending Model's CRUD properties.
150
+
151
+
For example, if you want to write an additional query for reading any record that that has a value of `'some value'` in the field `a_field`, you would start by subclassing `Read`, the class that `Model.read` is an instance of:
Finally, using your `ExtendedModel` is simple, just initialize the class with a `Client` instance & use it just as you would your previous `Model` instance, `a_model`:
0 commit comments