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
Databases have a `t` property that lists all tables:
@@ -171,9 +170,11 @@ to a module, which you can then import from:
171
170
create_mod(db, 'db_dc')
172
171
```
173
172
173
+
Indexing into a table does a query on primary key:
174
+
174
175
```python
175
176
from db_dc import Track
176
-
Track(**dt.Track.get(1))
177
+
Track(**dt.Track[1])
177
178
```
178
179
179
180
Track(TrackId=1, Name='For Those About To Rock (We Salute You)', AlbumId=1, MediaTypeId=1, GenreId=1, Composer='Angus Young, Malcolm Young, Brian Johnson', Milliseconds=343719, Bytes=11170334, UnitPrice=0.99)
@@ -190,35 +191,46 @@ album(limit=2)
190
191
[Album(AlbumId=1, Title='For Those About To Rock We Salute You', ArtistId=1),
191
192
Album(AlbumId=2, Title='Balls to the Wall', ArtistId=2)]
192
193
193
-
Pass a truthy value as the first param and you’ll get tuples of primary
194
-
keys and records:
194
+
Pass a truthy value as `with_pk`and you’ll get tuples of primary keys
195
+
and records:
195
196
196
197
```python
197
-
album(1, limit=2)
198
+
album(with_pk=1, limit=2)
198
199
```
199
200
200
201
[(1,
201
202
Album(AlbumId=1, Title='For Those About To Rock We Salute You', ArtistId=1)),
202
203
(2, Album(AlbumId=2, Title='Balls to the Wall', ArtistId=2))]
203
204
204
-
`get` also uses the dataclass by default:
205
+
Indexing also uses the dataclass by default:
205
206
206
207
```python
207
-
album.get(1)
208
+
album[5]
208
209
```
209
210
210
-
Album(AlbumId=1, Title='For Those About To Rock We Salute You', ArtistId=1)
211
+
Album(AlbumId=5, Title='Big Ones', ArtistId=3)
212
+
213
+
If you set `xtra` fields, then indexing is also filtered by those. As a
214
+
result, for instance in this case, nothing is returned since album 5 is
215
+
not created by artist 1:
216
+
217
+
```python
218
+
album.xtra(ArtistId=1)
219
+
220
+
try: album[5]
221
+
except NotFoundError: print("Not found")
222
+
```
211
223
212
-
If you want the dataclass-conversion behaviour for *all* tables (and
213
-
optionally views) then you can create them all at once with
0 commit comments