|
34 | 34 | """ |
35 | 35 | An example of a SQL-Alchemy like ORM. |
36 | 36 |
|
37 | | -The User and Post classes model a SQLite schema: |
| 37 | +The User, Post, and Comment classes model a SQLite schema: |
38 | 38 | ``` |
39 | 39 | CREATE TABLE users ( |
40 | 40 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
61 | 61 | ); |
62 | 62 | ``` |
63 | 63 |
|
64 | | -Protocols are generated using AddInit[T], Create[T], and Update[T]. |
| 64 | +Users can query using the `select` function, which generates a `Query` object |
| 65 | +with the specified tables and fields. |
| 66 | +
|
| 67 | +Users can then execute the query using `Session.execute`, which returns a |
| 68 | +list of `QueryRow` objects. |
| 69 | +
|
| 70 | +If a single table is selected, the `QueryRow` object will contain the selected |
| 71 | +fields. |
| 72 | +
|
| 73 | +For example, `select(User.name)` will return a list of: |
| 74 | +
|
| 75 | + class QueryRow[...]: |
| 76 | + name: str |
| 77 | +
|
| 78 | +If multiple tables are selected, the `QueryRow` object will contain a field for |
| 79 | +each table, which in turn contains the selected fields. |
| 80 | +
|
| 81 | +For example, `select(User.name, Post.content)` will return a list of: |
| 82 | +
|
| 83 | + class QueryRow[...]: |
| 84 | + User: Select[User, tuple[...]]]: |
| 85 | + Post: Select[Post, tuple[...]]]: |
| 86 | +
|
| 87 | + where, |
| 88 | +
|
| 89 | + class Select[User, tuple[...]]: |
| 90 | + name: str |
| 91 | +
|
| 92 | + class Select[Post, tuple[...]]: |
| 93 | + content: str |
65 | 94 | """ |
66 | 95 |
|
67 | 96 |
|
|
0 commit comments