-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqueries.py
More file actions
1544 lines (1233 loc) · 59.7 KB
/
queries.py
File metadata and controls
1544 lines (1233 loc) · 59.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Code generated by sqlc. DO NOT EDIT.
# versions:
# sqlc v1.28.0
# sqlc-gen-better-python v0.4.3
"""Module containing queries from file queries.sql."""
from __future__ import annotations
__all__: collections.abc.Sequence[str] = (
"QueryResults",
"create_rows_table",
"delete_last_id_one_sqlite_type",
"delete_one_sqlite_type",
"delete_one_test_inner_sqlite_type",
"delete_result_one_sqlite_type",
"delete_rows_one_sqlite_type",
"delete_type_override",
"get_many_blob",
"get_many_bool",
"get_many_boolean",
"get_many_date",
"get_many_datetime",
"get_many_decimal",
"get_many_inner_sqlite_type",
"get_many_nullable_inner_sqlite_type",
"get_many_sqlite_type",
"get_many_text_type_override",
"get_many_timestamp",
"get_many_type_override",
"get_one_blob",
"get_one_bool",
"get_one_boolean",
"get_one_date",
"get_one_datetime",
"get_one_decimal",
"get_one_inner_sqlite_type",
"get_one_sqlite_type",
"get_one_text_type_override",
"get_one_timestamp",
"get_one_type_override",
"insert_last_id_one_sqlite_type",
"insert_one_inner_sqlite_type",
"insert_one_sqlite_type",
"insert_result_one_sqlite_type",
"insert_rows_one_sqlite_type",
"insert_type_override",
"update_last_id_one_sqlite_type",
"update_result_one_sqlite_type",
"update_rows_one_sqlite_type",
)
from collections import UserString
import aiosqlite
import datetime
import decimal
import operator
import typing
if typing.TYPE_CHECKING:
import collections.abc
import sqlite3
QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None
from test.driver_aiosqlite.attrs.functions import models
def _adapt_date(val: datetime.date) -> str:
return val.isoformat()
def _convert_date(val: bytes) -> datetime.date:
return datetime.date.fromisoformat(val.decode())
def _adapt_decimal(val: decimal.Decimal) -> str:
return str(val)
def _convert_decimal(val: bytes) -> decimal.Decimal:
return decimal.Decimal(val.decode())
def _adapt_datetime(val: datetime.datetime) -> str:
return val.isoformat()
def _convert_datetime(val: bytes) -> datetime.datetime:
return datetime.datetime.fromisoformat(val.decode())
def _adapt_bool(val: bool) -> int:
return int(val)
def _convert_bool(val: bytes) -> bool:
return bool(int(val))
def _adapt_memoryview(val: memoryview) -> bytes:
return val.tobytes()
def _convert_memoryview(val: bytes) -> memoryview:
return memoryview(val)
aiosqlite.register_adapter(datetime.date, _adapt_date)
aiosqlite.register_adapter(decimal.Decimal, _adapt_decimal)
aiosqlite.register_adapter(datetime.datetime, _adapt_datetime)
aiosqlite.register_adapter(bool, _adapt_bool)
aiosqlite.register_adapter(memoryview, _adapt_memoryview)
aiosqlite.register_converter("date", _convert_date)
aiosqlite.register_converter("decimal", _convert_decimal)
aiosqlite.register_converter("datetime", _convert_datetime)
aiosqlite.register_converter("timestamp", _convert_datetime)
aiosqlite.register_converter("bool", _convert_bool)
aiosqlite.register_converter("boolean", _convert_bool)
aiosqlite.register_converter("blob", _convert_memoryview)
CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows
CREATE TABLE test_create_rows_table
(
id int PRIMARY KEY NOT NULL,
test int NOT NULL
)
"""
DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
"""
DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
"""
DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec
DELETE FROM test_inner_sqlite_types
WHERE test_inner_sqlite_types.table_id = ?
"""
DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
"""
DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
"""
DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec
DELETE
FROM test_type_override
WHERE test_type_override.id = ?
"""
GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many
SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ?
"""
GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many
SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ?
"""
GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many
SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ?
"""
GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many
SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ?
"""
GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many
SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ?
"""
GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many
SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ?
"""
GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many
SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ?
"""
GET_MANY_NULLABLE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyNullableInnerSqliteType :many
SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ?
"""
GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many
SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ?
"""
GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many
SELECT text_test FROM test_type_override WHERE test_type_override.id = ?
"""
GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many
SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ?
"""
GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many
SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ?
"""
GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one
SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ?
"""
GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one
SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ?
"""
GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one
SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ?
"""
GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one
SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ?
"""
GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one
SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ?
"""
GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one
SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ?
"""
GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one
SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ?
"""
GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one
SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ?
"""
GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one
SELECT text_test FROM test_type_override WHERE test_type_override.id = ?
"""
GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one
SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ?
"""
GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one
SELECT id, text_test FROM test_type_override WHERE id = ?
"""
INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid
INSERT INTO test_sqlite_types (
id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test,
blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test,
boolean_test, bool_test, date_test, datetime_test, timestamp_test,
character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test,
nvarchar_test, text_test, clob_test, json_test
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?
)
"""
INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec
INSERT INTO test_inner_sqlite_types (
table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test,
blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test,
boolean_test, bool_test, date_test, datetime_test, timestamp_test,
character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test,
nvarchar_test, text_test, clob_test, json_test
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?
)
"""
INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec
INSERT INTO test_sqlite_types (
id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test,
blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test,
boolean_test, bool_test, date_test, datetime_test, timestamp_test,
character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test,
nvarchar_test, text_test, clob_test, json_test
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?
)
"""
INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult
INSERT INTO test_sqlite_types (
id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test,
blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test,
boolean_test, bool_test, date_test, datetime_test, timestamp_test,
character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test,
nvarchar_test, text_test, clob_test, json_test
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?
)
"""
INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows
INSERT INTO test_sqlite_types (
id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test,
blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test,
boolean_test, bool_test, date_test, datetime_test, timestamp_test,
character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test,
nvarchar_test, text_test, clob_test, json_test
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?
)
"""
INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec
INSERT INTO test_type_override (
id, text_test
) VALUES (? ,?)
"""
UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid
UPDATE test_sqlite_types
SET int_test = 187
WHERE test_sqlite_types.id = ?
"""
UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult
UPDATE test_sqlite_types
SET int_test = 187
WHERE test_sqlite_types.id = ?
"""
UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows
UPDATE test_sqlite_types
SET int_test = 187
WHERE test_sqlite_types.id = ?
"""
T = typing.TypeVar("T")
class QueryResults(typing.Generic[T]):
"""Helper class that allows both iteration and normal fetching of data from the db.
Parameters
----------
conn
The connection object of type `aiosqlite.Connection` used to execute queries.
sql
The SQL statement that will be executed when fetching/iterating.
decode_hook
A callback that turns an `sqlite3.Row` object into `T` that will be returned.
*args
Arguments that should be sent when executing the sql query.
"""
__slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql")
def __init__(
self,
conn: aiosqlite.Connection,
sql: str,
decode_hook: collections.abc.Callable[[sqlite3.Row], T],
*args: QueryResultsArgsType,
) -> None:
"""Initialize the QueryResults instance."""
self._conn = conn
self._sql = sql
self._decode_hook = decode_hook
self._args = args
self._cursor: aiosqlite.Cursor | None = None
self._iterator: collections.abc.AsyncIterator[sqlite3.Row] | None = None
def __aiter__(self) -> QueryResults[T]:
"""Initialize iteration support for `async for`.
Returns
-------
QueryResults[T]
Self as an asynchronous iterator.
"""
return self
def __await__(
self,
) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]:
"""Allow `await` on the object to return all rows as a fully decoded sequence.
Returns
-------
collections.abc.Sequence[T]
A sequence of decoded objects of type `T`.
"""
async def _wrapper() -> collections.abc.Sequence[T]:
result = await (await self._conn.execute(self._sql, self._args)).fetchall()
return [self._decode_hook(row) for row in result]
return _wrapper().__await__()
async def __anext__(self) -> T:
"""Yield the next item in the query result using an aiosqlite cursor.
Returns
-------
T
The next decoded result.
Raises
------
StopAsyncIteration
When no more records are available.
"""
if self._cursor is None or self._iterator is None:
self._cursor: aiosqlite.Cursor | None = await self._conn.execute(self._sql, self._args)
self._iterator = self._cursor.__aiter__()
try:
record = await self._iterator.__anext__()
except StopAsyncIteration:
self._cursor = None
self._iterator = None
raise
return self._decode_hook(record)
async def create_rows_table(conn: aiosqlite.Connection) -> int:
"""Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows.
```sql
CREATE TABLE test_create_rows_table
(
id int PRIMARY KEY NOT NULL,
test int NOT NULL
)
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
Returns
-------
int
The number of affected rows. This will be -1 for queries like `CREATE TABLE`.
"""
return (await conn.execute(CREATE_ROWS_TABLE)).rowcount
async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None:
"""Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row.
```sql
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
int | None
The id of the last affected row. Will be `None` if no rows are affected.
"""
return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid
async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None:
"""Execute SQL query with `name: DeleteOneSqliteType :exec`.
```sql
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
"""
await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, ))
async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None:
"""Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`.
```sql
DELETE FROM test_inner_sqlite_types
WHERE test_inner_sqlite_types.table_id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
table_id : int
"""
await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, ))
async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor:
"""Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`.
```sql
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
aiosqlite.Cursor
The result returned when executing the query.
"""
return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, ))
async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int:
"""Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows.
```sql
DELETE
FROM test_sqlite_types
WHERE test_sqlite_types.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
int
The number of affected rows. This will be -1 for queries like `CREATE TABLE`.
"""
return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount
async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None:
"""Execute SQL query with `name: DeleteTypeOverride :exec`.
```sql
DELETE
FROM test_type_override
WHERE test_type_override.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
"""
await conn.execute(DELETE_TYPE_OVERRIDE, (id_, ))
def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]:
"""Fetch many from the db using the SQL query with `name: GetManyBlob :many`.
```sql
SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
blob_test : memoryview
Returns
-------
QueryResults[memoryview]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test)
def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]:
"""Fetch many from the db using the SQL query with `name: GetManyBool :many`.
```sql
SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
bool_test : bool
Returns
-------
QueryResults[bool]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test)
def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]:
"""Fetch many from the db using the SQL query with `name: GetManyBoolean :many`.
```sql
SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
boolean_test : bool
Returns
-------
QueryResults[bool]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test)
def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]:
"""Fetch many from the db using the SQL query with `name: GetManyDate :many`.
```sql
SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
date_test : datetime.date
Returns
-------
QueryResults[datetime.date]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test)
def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]:
"""Fetch many from the db using the SQL query with `name: GetManyDatetime :many`.
```sql
SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
datetime_test : datetime.datetime
Returns
-------
QueryResults[datetime.datetime]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test)
def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]:
"""Fetch many from the db using the SQL query with `name: GetManyDecimal :many`.
```sql
SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
decimal_test : decimal.Decimal
Returns
-------
QueryResults[decimal.Decimal]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test)
def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]:
"""Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`.
```sql
SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
table_id : int
Returns
-------
QueryResults[models.TestInnerSqliteType]
Helper class that allows both iteration and normal fetching of data from the db.
"""
def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType:
return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28])
return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id)
def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]:
"""Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`.
```sql
SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
table_id : int
int_test : int | None
Returns
-------
QueryResults[models.TestInnerSqliteType]
Helper class that allows both iteration and normal fetching of data from the db.
"""
def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType:
return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28])
return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test)
def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]:
"""Fetch many from the db using the SQL query with `name: GetManySqliteType :many`.
```sql
SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
QueryResults[models.TestSqliteType]
Helper class that allows both iteration and normal fetching of data from the db.
"""
def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType:
return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28])
return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_)
def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString]:
"""Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`.
```sql
SELECT text_test FROM test_type_override WHERE test_type_override.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
QueryResults[UserString]
Helper class that allows both iteration and normal fetching of data from the db.
"""
def _decode_hook(row: sqlite3.Row) -> UserString:
return UserString(row[0])
return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_)
def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]:
"""Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`.
```sql
SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
timestamp_test : datetime.datetime
Returns
-------
QueryResults[datetime.datetime]
Helper class that allows both iteration and normal fetching of data from the db.
"""
return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test)
def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]:
"""Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`.
```sql
SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
Returns
-------
QueryResults[models.TestTypeOverride]
Helper class that allows both iteration and normal fetching of data from the db.
"""
def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride:
return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]))
return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_)
async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None:
"""Fetch one from the db using the SQL query with `name: GetOneBlob :one`.
```sql
SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
blob_test : memoryview
Returns
-------
memoryview
Result fetched from the db. Will be `None` if not found.
"""
row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone()
if row is None:
return None
return row[0]
async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None:
"""Fetch one from the db using the SQL query with `name: GetOneBool :one`.
```sql
SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
bool_test : bool
Returns
-------
bool
Result fetched from the db. Will be `None` if not found.
"""
row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone()
if row is None:
return None
return row[0]
async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None:
"""Fetch one from the db using the SQL query with `name: GetOneBoolean :one`.
```sql
SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
boolean_test : bool
Returns
-------
bool
Result fetched from the db. Will be `None` if not found.
"""
row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone()
if row is None:
return None
return row[0]
async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None:
"""Fetch one from the db using the SQL query with `name: GetOneDate :one`.
```sql
SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
date_test : datetime.date
Returns
-------
datetime.date
Result fetched from the db. Will be `None` if not found.
"""
row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone()
if row is None:
return None
return row[0]
async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None:
"""Fetch one from the db using the SQL query with `name: GetOneDatetime :one`.
```sql
SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ?
```
Parameters
----------
conn : aiosqlite.Connection
Connection object of type `aiosqlite.Connection` used to execute the query.
id_ : int
datetime_test : datetime.datetime
Returns
-------
datetime.datetime
Result fetched from the db. Will be `None` if not found.