|
4 | 4 | .. codeauthor:: Tsuyoshi Hombashi <[email protected]> |
5 | 5 | """ |
6 | 6 |
|
| 7 | +from typing import Type |
| 8 | + |
7 | 9 | from simplesqlite import connect_memdb |
8 | 10 | from simplesqlite.model import Blob, Integer, Model, Real, Text |
9 | 11 | from simplesqlite.query import Set, Where |
10 | 12 |
|
11 | 13 |
|
12 | | -def print_all_records(model: Model) -> None: |
| 14 | +def print_all_records(model: Type[Model]) -> None: |
13 | 15 | for record in model.select(): |
14 | 16 | print(record) |
15 | 17 |
|
@@ -45,26 +47,26 @@ def main() -> None: |
45 | 47 |
|
46 | 48 | print(Hoge.fetch_schema().dumps()) |
47 | 49 | table_name = Hoge.get_table_name() |
48 | | - print(f"\nSELECT all the records: {table_name=}") |
| 50 | + print(f"\nSELECT all the records: table={table_name}") |
49 | 51 | for hoge in Hoge.select(): |
50 | 52 | print(hoge.hoge_id, hoge.name) |
51 | 53 |
|
52 | | - print(f"\nSELECT with WHERE: {table_name=}") |
| 54 | + print(f"\nSELECT with WHERE: table={table_name}") |
53 | 55 | for hoge in Hoge.select(where=Where(Hoge.hoge_id, 10)): |
54 | 56 | print(hoge.hoge_id, hoge.name) |
55 | 57 |
|
56 | 58 | print("\n--------------------\n") |
57 | 59 | print(Foo.fetch_schema().dumps()) |
58 | 60 | table_name = Foo.get_table_name() |
59 | 61 |
|
60 | | - print(f"\nSELECT all the records: {table_name=}") |
| 62 | + print(f"\nSELECT all the records: table={table_name}") |
61 | 63 | print_all_records(Foo) |
62 | 64 |
|
63 | | - print(f"\nDELETE: {table_name=}") |
| 65 | + print(f"\nDELETE: table={table_name}") |
64 | 66 | Foo.delete(where=Where(Foo.foo_id, 22)) |
65 | 67 | print_all_records(Foo) |
66 | 68 |
|
67 | | - print(f"\nUPDATE: {table_name=}") |
| 69 | + print(f"\nUPDATE: table={table_name}") |
68 | 70 | Foo.update(set_query=[Set(Foo.value, 1000)], where=Where(Foo.foo_id, 33)) |
69 | 71 | print_all_records(Foo) |
70 | 72 |
|
|
0 commit comments