dataclassdb 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataclassdb/__init__.py +19 -0
- dataclassdb/builders/function_builder.py +407 -0
- dataclassdb/builders/list_utils.py +48 -0
- dataclassdb/builders/query_builder.py +158 -0
- dataclassdb/builders/statement_builder.py +635 -0
- dataclassdb/builders/string_builder.py +98 -0
- dataclassdb/constants.py +372 -0
- dataclassdb/dataclass_db.py +282 -0
- dataclassdb/dataclass_field_codec.py +216 -0
- dataclassdb/dataclass_sqlite_field.py +193 -0
- dataclassdb/dataclass_sqlite_table.py +152 -0
- dataclassdb/dataclass_types.py +22 -0
- dataclassdb/db_engine.py +126 -0
- dataclassdb/utils.py +74 -0
- dataclassdb-0.1.0.dist-info/METADATA +237 -0
- dataclassdb-0.1.0.dist-info/RECORD +19 -0
- dataclassdb-0.1.0.dist-info/WHEEL +5 -0
- dataclassdb-0.1.0.dist-info/licenses/LICENSE +21 -0
- dataclassdb-0.1.0.dist-info/top_level.txt +1 -0
dataclassdb/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from dataclassdb.dataclass_db import DataclassDb as DataclassDb
|
|
2
|
+
from dataclassdb.db_engine import DbEngine as DbEngine
|
|
3
|
+
from dataclassdb.builders.query_builder import QueryBuilder as QueryBuilder
|
|
4
|
+
from dataclassdb.builders.string_builder import StringBuilder as StringBuilder
|
|
5
|
+
from dataclassdb.dataclass_types import Codec as Codec
|
|
6
|
+
from dataclassdb.dataclass_types import CustomCodec as CustomCodec
|
|
7
|
+
from dataclassdb.dataclass_types import IsDataclass as IsDataclass
|
|
8
|
+
from dataclassdb.constants import SQL as SQL
|
|
9
|
+
from dataclassdb.constants import SQL_FUNC as SQL_FUNC
|
|
10
|
+
from dataclassdb.constants import SQL_FUNC_PRAGMA as SQL_FUNC_PRAGMA
|
|
11
|
+
from dataclassdb.constants import SQL_TYPES as SQL_TYPES
|
|
12
|
+
from dataclassdb.dataclass_sqlite_table import (
|
|
13
|
+
DataclassTableCodec as DataclassTableCodec,
|
|
14
|
+
)
|
|
15
|
+
from dataclassdb.dataclass_sqlite_table import decode_dict as decode_dict
|
|
16
|
+
from dataclassdb.dataclass_sqlite_table import decode_field as decode_field
|
|
17
|
+
from dataclassdb.dataclass_sqlite_table import encode_field as encode_field
|
|
18
|
+
from dataclassdb.dataclass_sqlite_table import get_class_codec as get_class_codec
|
|
19
|
+
from dataclassdb.dataclass_sqlite_table import get_field_codec as get_field_codec
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"""This script creates the getter and setter sql files from strenums."""
|
|
2
|
+
|
|
3
|
+
__all__ = ['FunctionBuilder']
|
|
4
|
+
|
|
5
|
+
from typing import Self
|
|
6
|
+
|
|
7
|
+
from dataclassdb.builders.string_builder import StringBuilder
|
|
8
|
+
from dataclassdb.constants import SQL_FUNC, SQL_FUNC_PRAGMA
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FunctionBuilder(StringBuilder):
|
|
12
|
+
# Generated from scripts/generate_builder_files.py
|
|
13
|
+
def Abs(self, *args) -> Self:
|
|
14
|
+
return self.add_func(SQL_FUNC.ABS, *args)
|
|
15
|
+
|
|
16
|
+
def Changes(self, *args) -> Self:
|
|
17
|
+
return self.add_func(SQL_FUNC.CHANGES, *args)
|
|
18
|
+
|
|
19
|
+
def Char(self, *args) -> Self:
|
|
20
|
+
return self.add_func(SQL_FUNC.CHAR, *args)
|
|
21
|
+
|
|
22
|
+
def Coalesce(self, *args) -> Self:
|
|
23
|
+
return self.add_func(SQL_FUNC.COALESCE, *args)
|
|
24
|
+
|
|
25
|
+
def Concat(self, *args) -> Self:
|
|
26
|
+
return self.add_func(SQL_FUNC.CONCAT, *args)
|
|
27
|
+
|
|
28
|
+
def Concat_ws(self, *args) -> Self:
|
|
29
|
+
return self.add_func(SQL_FUNC.CONCAT_WS, *args)
|
|
30
|
+
|
|
31
|
+
def Format(self, *args) -> Self:
|
|
32
|
+
return self.add_func(SQL_FUNC.FORMAT, *args)
|
|
33
|
+
|
|
34
|
+
def Glob(self, *args) -> Self:
|
|
35
|
+
return self.add_func(SQL_FUNC.GLOB, *args)
|
|
36
|
+
|
|
37
|
+
def Hex(self, *args) -> Self:
|
|
38
|
+
return self.add_func(SQL_FUNC.HEX, *args)
|
|
39
|
+
|
|
40
|
+
def If(self, *args) -> Self:
|
|
41
|
+
return self.add_func(SQL_FUNC.IF, *args)
|
|
42
|
+
|
|
43
|
+
def Ifnull(self, *args) -> Self:
|
|
44
|
+
return self.add_func(SQL_FUNC.IFNULL, *args)
|
|
45
|
+
|
|
46
|
+
def Iif(self, *args) -> Self:
|
|
47
|
+
return self.add_func(SQL_FUNC.IIF, *args)
|
|
48
|
+
|
|
49
|
+
def Instr(self, *args) -> Self:
|
|
50
|
+
return self.add_func(SQL_FUNC.INSTR, *args)
|
|
51
|
+
|
|
52
|
+
def Last_insert_rowid(self, *args) -> Self:
|
|
53
|
+
return self.add_func(SQL_FUNC.LAST_INSERT_ROWID, *args)
|
|
54
|
+
|
|
55
|
+
def Length(self, *args) -> Self:
|
|
56
|
+
return self.add_func(SQL_FUNC.LENGTH, *args)
|
|
57
|
+
|
|
58
|
+
def Like(self, *args) -> Self:
|
|
59
|
+
return self.add_func(SQL_FUNC.LIKE, *args)
|
|
60
|
+
|
|
61
|
+
def Likelihood(self, *args) -> Self:
|
|
62
|
+
return self.add_func(SQL_FUNC.LIKELIHOOD, *args)
|
|
63
|
+
|
|
64
|
+
def Likely(self, *args) -> Self:
|
|
65
|
+
return self.add_func(SQL_FUNC.LIKELY, *args)
|
|
66
|
+
|
|
67
|
+
def Load_extension(self, *args) -> Self:
|
|
68
|
+
return self.add_func(SQL_FUNC.LOAD_EXTENSION, *args)
|
|
69
|
+
|
|
70
|
+
def Lower(self, *args) -> Self:
|
|
71
|
+
return self.add_func(SQL_FUNC.LOWER, *args)
|
|
72
|
+
|
|
73
|
+
def Ltrim(self, *args) -> Self:
|
|
74
|
+
return self.add_func(SQL_FUNC.LTRIM, *args)
|
|
75
|
+
|
|
76
|
+
def Max(self, *args) -> Self:
|
|
77
|
+
return self.add_func(SQL_FUNC.MAX, *args)
|
|
78
|
+
|
|
79
|
+
def Min(self, *args) -> Self:
|
|
80
|
+
return self.add_func(SQL_FUNC.MIN, *args)
|
|
81
|
+
|
|
82
|
+
def Nullif(self, *args) -> Self:
|
|
83
|
+
return self.add_func(SQL_FUNC.NULLIF, *args)
|
|
84
|
+
|
|
85
|
+
def Octet_length(self, *args) -> Self:
|
|
86
|
+
return self.add_func(SQL_FUNC.OCTET_LENGTH, *args)
|
|
87
|
+
|
|
88
|
+
def Printf(self, *args) -> Self:
|
|
89
|
+
return self.add_func(SQL_FUNC.PRINTF, *args)
|
|
90
|
+
|
|
91
|
+
def Quote(self, *args) -> Self:
|
|
92
|
+
return self.add_func(SQL_FUNC.QUOTE, *args)
|
|
93
|
+
|
|
94
|
+
def Random(self, *args) -> Self:
|
|
95
|
+
return self.add_func(SQL_FUNC.RANDOM, *args)
|
|
96
|
+
|
|
97
|
+
def Randomblob(self, *args) -> Self:
|
|
98
|
+
return self.add_func(SQL_FUNC.RANDOMBLOB, *args)
|
|
99
|
+
|
|
100
|
+
def Replace(self, *args) -> Self:
|
|
101
|
+
return self.add_func(SQL_FUNC.REPLACE, *args)
|
|
102
|
+
|
|
103
|
+
def Round(self, *args) -> Self:
|
|
104
|
+
return self.add_func(SQL_FUNC.ROUND, *args)
|
|
105
|
+
|
|
106
|
+
def Rtrim(self, *args) -> Self:
|
|
107
|
+
return self.add_func(SQL_FUNC.RTRIM, *args)
|
|
108
|
+
|
|
109
|
+
def Sign(self, *args) -> Self:
|
|
110
|
+
return self.add_func(SQL_FUNC.SIGN, *args)
|
|
111
|
+
|
|
112
|
+
def Soundex(self, *args) -> Self:
|
|
113
|
+
return self.add_func(SQL_FUNC.SOUNDEX, *args)
|
|
114
|
+
|
|
115
|
+
def Sqlite_compileoption_get(self, *args) -> Self:
|
|
116
|
+
return self.add_func(SQL_FUNC.SQLITE_COMPILEOPTION_GET, *args)
|
|
117
|
+
|
|
118
|
+
def Sqlite_compileoption_used(self, *args) -> Self:
|
|
119
|
+
return self.add_func(SQL_FUNC.SQLITE_COMPILEOPTION_USED, *args)
|
|
120
|
+
|
|
121
|
+
def Sqlite_offset(self, *args) -> Self:
|
|
122
|
+
return self.add_func(SQL_FUNC.SQLITE_OFFSET, *args)
|
|
123
|
+
|
|
124
|
+
def Sqlite_source_id(self, *args) -> Self:
|
|
125
|
+
return self.add_func(SQL_FUNC.SQLITE_SOURCE_ID, *args)
|
|
126
|
+
|
|
127
|
+
def Sqlite_version(self, *args) -> Self:
|
|
128
|
+
return self.add_func(SQL_FUNC.SQLITE_VERSION, *args)
|
|
129
|
+
|
|
130
|
+
def Substr(self, *args) -> Self:
|
|
131
|
+
return self.add_func(SQL_FUNC.SUBSTR, *args)
|
|
132
|
+
|
|
133
|
+
def Substring(self, *args) -> Self:
|
|
134
|
+
return self.add_func(SQL_FUNC.SUBSTRING, *args)
|
|
135
|
+
|
|
136
|
+
def Total_changes(self, *args) -> Self:
|
|
137
|
+
return self.add_func(SQL_FUNC.TOTAL_CHANGES, *args)
|
|
138
|
+
|
|
139
|
+
def Trim(self, *args) -> Self:
|
|
140
|
+
return self.add_func(SQL_FUNC.TRIM, *args)
|
|
141
|
+
|
|
142
|
+
def Typeof(self, *args) -> Self:
|
|
143
|
+
return self.add_func(SQL_FUNC.TYPEOF, *args)
|
|
144
|
+
|
|
145
|
+
def Unhex(self, *args) -> Self:
|
|
146
|
+
return self.add_func(SQL_FUNC.UNHEX, *args)
|
|
147
|
+
|
|
148
|
+
def Unicode(self, *args) -> Self:
|
|
149
|
+
return self.add_func(SQL_FUNC.UNICODE, *args)
|
|
150
|
+
|
|
151
|
+
def Unistr(self, *args) -> Self:
|
|
152
|
+
return self.add_func(SQL_FUNC.UNISTR, *args)
|
|
153
|
+
|
|
154
|
+
def Unistr_quote(self, *args) -> Self:
|
|
155
|
+
return self.add_func(SQL_FUNC.UNISTR_QUOTE, *args)
|
|
156
|
+
|
|
157
|
+
def Unlikely(self, *args) -> Self:
|
|
158
|
+
return self.add_func(SQL_FUNC.UNLIKELY, *args)
|
|
159
|
+
|
|
160
|
+
def Upper(self, *args) -> Self:
|
|
161
|
+
return self.add_func(SQL_FUNC.UPPER, *args)
|
|
162
|
+
|
|
163
|
+
def Zeroblob(self, *args) -> Self:
|
|
164
|
+
return self.add_func(SQL_FUNC.ZEROBLOB, *args)
|
|
165
|
+
|
|
166
|
+
def Avg(self, *args) -> Self:
|
|
167
|
+
return self.add_func(SQL_FUNC.AVG, *args)
|
|
168
|
+
|
|
169
|
+
def Group_concat(self, *args) -> Self:
|
|
170
|
+
return self.add_func(SQL_FUNC.GROUP_CONCAT, *args)
|
|
171
|
+
|
|
172
|
+
def Median(self, *args) -> Self:
|
|
173
|
+
return self.add_func(SQL_FUNC.MEDIAN, *args)
|
|
174
|
+
|
|
175
|
+
def Percentile(self, *args) -> Self:
|
|
176
|
+
return self.add_func(SQL_FUNC.PERCENTILE, *args)
|
|
177
|
+
|
|
178
|
+
def Percentile_cont(self, *args) -> Self:
|
|
179
|
+
return self.add_func(SQL_FUNC.PERCENTILE_CONT, *args)
|
|
180
|
+
|
|
181
|
+
def Percentile_disc(self, *args) -> Self:
|
|
182
|
+
return self.add_func(SQL_FUNC.PERCENTILE_DISC, *args)
|
|
183
|
+
|
|
184
|
+
def String_agg(self, *args) -> Self:
|
|
185
|
+
return self.add_func(SQL_FUNC.STRING_AGG, *args)
|
|
186
|
+
|
|
187
|
+
def Sum(self, *args) -> Self:
|
|
188
|
+
return self.add_func(SQL_FUNC.SUM, *args)
|
|
189
|
+
|
|
190
|
+
def Total(self, *args) -> Self:
|
|
191
|
+
return self.add_func(SQL_FUNC.TOTAL, *args)
|
|
192
|
+
|
|
193
|
+
def Count(self, *args) -> Self:
|
|
194
|
+
return self.add_func(SQL_FUNC.COUNT, *args)
|
|
195
|
+
|
|
196
|
+
def Date(self, *args) -> Self:
|
|
197
|
+
return self.add_func(SQL_FUNC.DATE, *args)
|
|
198
|
+
|
|
199
|
+
def Time(self, *args) -> Self:
|
|
200
|
+
return self.add_func(SQL_FUNC.TIME, *args)
|
|
201
|
+
|
|
202
|
+
def Datetime(self, *args) -> Self:
|
|
203
|
+
return self.add_func(SQL_FUNC.DATETIME, *args)
|
|
204
|
+
|
|
205
|
+
def Julianday(self, *args) -> Self:
|
|
206
|
+
return self.add_func(SQL_FUNC.JULIANDAY, *args)
|
|
207
|
+
|
|
208
|
+
def Unixepoch(self, *args) -> Self:
|
|
209
|
+
return self.add_func(SQL_FUNC.UNIXEPOCH, *args)
|
|
210
|
+
|
|
211
|
+
def Strftime(self, *args) -> Self:
|
|
212
|
+
return self.add_func(SQL_FUNC.STRFTIME, *args)
|
|
213
|
+
|
|
214
|
+
def Timediff(self, *args) -> Self:
|
|
215
|
+
return self.add_func(SQL_FUNC.TIMEDIFF, *args)
|
|
216
|
+
|
|
217
|
+
def Integer(self, *args) -> Self:
|
|
218
|
+
return self.add_func(SQL_FUNC.INTEGER, *args)
|
|
219
|
+
|
|
220
|
+
def Text(self, *args) -> Self:
|
|
221
|
+
return self.add_func(SQL_FUNC.TEXT, *args)
|
|
222
|
+
|
|
223
|
+
def Blob(self, *args) -> Self:
|
|
224
|
+
return self.add_func(SQL_FUNC.BLOB, *args)
|
|
225
|
+
|
|
226
|
+
def Real(self, *args) -> Self:
|
|
227
|
+
return self.add_func(SQL_FUNC.REAL, *args)
|
|
228
|
+
|
|
229
|
+
def Numeric(self, *args) -> Self:
|
|
230
|
+
return self.add_func(SQL_FUNC.NUMERIC, *args)
|
|
231
|
+
|
|
232
|
+
def Any(self, *args) -> Self:
|
|
233
|
+
return self.add_func(SQL_FUNC.ANY, *args)
|
|
234
|
+
|
|
235
|
+
def Analysis_limit(self, *args) -> Self:
|
|
236
|
+
return self.add_func(SQL_FUNC_PRAGMA.ANALYSIS_LIMIT, *args)
|
|
237
|
+
|
|
238
|
+
def Application_id(self, *args) -> Self:
|
|
239
|
+
return self.add_func(SQL_FUNC_PRAGMA.APPLICATION_ID, *args)
|
|
240
|
+
|
|
241
|
+
def Auto_vacuum(self, *args) -> Self:
|
|
242
|
+
return self.add_func(SQL_FUNC_PRAGMA.AUTO_VACUUM, *args)
|
|
243
|
+
|
|
244
|
+
def Automatic_index(self, *args) -> Self:
|
|
245
|
+
return self.add_func(SQL_FUNC_PRAGMA.AUTOMATIC_INDEX, *args)
|
|
246
|
+
|
|
247
|
+
def Busy_timeout(self, *args) -> Self:
|
|
248
|
+
return self.add_func(SQL_FUNC_PRAGMA.BUSY_TIMEOUT, *args)
|
|
249
|
+
|
|
250
|
+
def Cache_size(self, *args) -> Self:
|
|
251
|
+
return self.add_func(SQL_FUNC_PRAGMA.CACHE_SIZE, *args)
|
|
252
|
+
|
|
253
|
+
def Cache_spill(self, *args) -> Self:
|
|
254
|
+
return self.add_func(SQL_FUNC_PRAGMA.CACHE_SPILL, *args)
|
|
255
|
+
|
|
256
|
+
def Cell_size_check(self, *args) -> Self:
|
|
257
|
+
return self.add_func(SQL_FUNC_PRAGMA.CELL_SIZE_CHECK, *args)
|
|
258
|
+
|
|
259
|
+
def Checkpoint_fullfsync(self, *args) -> Self:
|
|
260
|
+
return self.add_func(SQL_FUNC_PRAGMA.CHECKPOINT_FULLFSYNC, *args)
|
|
261
|
+
|
|
262
|
+
def Collation_list(self, *args) -> Self:
|
|
263
|
+
return self.add_func(SQL_FUNC_PRAGMA.COLLATION_LIST, *args)
|
|
264
|
+
|
|
265
|
+
def Compile_options(self, *args) -> Self:
|
|
266
|
+
return self.add_func(SQL_FUNC_PRAGMA.COMPILE_OPTIONS, *args)
|
|
267
|
+
|
|
268
|
+
def Data_version(self, *args) -> Self:
|
|
269
|
+
return self.add_func(SQL_FUNC_PRAGMA.DATA_VERSION, *args)
|
|
270
|
+
|
|
271
|
+
def Database_list(self, *args) -> Self:
|
|
272
|
+
return self.add_func(SQL_FUNC_PRAGMA.DATABASE_LIST, *args)
|
|
273
|
+
|
|
274
|
+
def Defer_foreign_keys(self, *args) -> Self:
|
|
275
|
+
return self.add_func(SQL_FUNC_PRAGMA.DEFER_FOREIGN_KEYS, *args)
|
|
276
|
+
|
|
277
|
+
def Encoding(self, *args) -> Self:
|
|
278
|
+
return self.add_func(SQL_FUNC_PRAGMA.ENCODING, *args)
|
|
279
|
+
|
|
280
|
+
def Foreign_key_check(self, *args) -> Self:
|
|
281
|
+
return self.add_func(SQL_FUNC_PRAGMA.FOREIGN_KEY_CHECK, *args)
|
|
282
|
+
|
|
283
|
+
def Foreign_key_list(self, *args) -> Self:
|
|
284
|
+
return self.add_func(SQL_FUNC_PRAGMA.FOREIGN_KEY_LIST, *args)
|
|
285
|
+
|
|
286
|
+
def Foreign_keys(self, *args) -> Self:
|
|
287
|
+
return self.add_func(SQL_FUNC_PRAGMA.FOREIGN_KEYS, *args)
|
|
288
|
+
|
|
289
|
+
def Freelist_count(self, *args) -> Self:
|
|
290
|
+
return self.add_func(SQL_FUNC_PRAGMA.FREELIST_COUNT, *args)
|
|
291
|
+
|
|
292
|
+
def Fullfsync(self, *args) -> Self:
|
|
293
|
+
return self.add_func(SQL_FUNC_PRAGMA.FULLFSYNC, *args)
|
|
294
|
+
|
|
295
|
+
def Function_list(self, *args) -> Self:
|
|
296
|
+
return self.add_func(SQL_FUNC_PRAGMA.FUNCTION_LIST, *args)
|
|
297
|
+
|
|
298
|
+
def Hard_heap_limit(self, *args) -> Self:
|
|
299
|
+
return self.add_func(SQL_FUNC_PRAGMA.HARD_HEAP_LIMIT, *args)
|
|
300
|
+
|
|
301
|
+
def Ignore_check_constraints(self, *args) -> Self:
|
|
302
|
+
return self.add_func(SQL_FUNC_PRAGMA.IGNORE_CHECK_CONSTRAINTS, *args)
|
|
303
|
+
|
|
304
|
+
def Incremental_vacuum(self, *args) -> Self:
|
|
305
|
+
return self.add_func(SQL_FUNC_PRAGMA.INCREMENTAL_VACUUM, *args)
|
|
306
|
+
|
|
307
|
+
def Index_info(self, *args) -> Self:
|
|
308
|
+
return self.add_func(SQL_FUNC_PRAGMA.INDEX_INFO, *args)
|
|
309
|
+
|
|
310
|
+
def Index_list(self, *args) -> Self:
|
|
311
|
+
return self.add_func(SQL_FUNC_PRAGMA.INDEX_LIST, *args)
|
|
312
|
+
|
|
313
|
+
def Index_xinfo(self, *args) -> Self:
|
|
314
|
+
return self.add_func(SQL_FUNC_PRAGMA.INDEX_XINFO, *args)
|
|
315
|
+
|
|
316
|
+
def Integrity_check(self, *args) -> Self:
|
|
317
|
+
return self.add_func(SQL_FUNC_PRAGMA.INTEGRITY_CHECK, *args)
|
|
318
|
+
|
|
319
|
+
def Journal_mode(self, *args) -> Self:
|
|
320
|
+
return self.add_func(SQL_FUNC_PRAGMA.JOURNAL_MODE, *args)
|
|
321
|
+
|
|
322
|
+
def Journal_size_limit(self, *args) -> Self:
|
|
323
|
+
return self.add_func(SQL_FUNC_PRAGMA.JOURNAL_SIZE_LIMIT, *args)
|
|
324
|
+
|
|
325
|
+
def Legacy_alter_table(self, *args) -> Self:
|
|
326
|
+
return self.add_func(SQL_FUNC_PRAGMA.LEGACY_ALTER_TABLE, *args)
|
|
327
|
+
|
|
328
|
+
def Legacy_file_format(self, *args) -> Self:
|
|
329
|
+
return self.add_func(SQL_FUNC_PRAGMA.LEGACY_FILE_FORMAT, *args)
|
|
330
|
+
|
|
331
|
+
def Locking_mode(self, *args) -> Self:
|
|
332
|
+
return self.add_func(SQL_FUNC_PRAGMA.LOCKING_MODE, *args)
|
|
333
|
+
|
|
334
|
+
def Max_page_count(self, *args) -> Self:
|
|
335
|
+
return self.add_func(SQL_FUNC_PRAGMA.MAX_PAGE_COUNT, *args)
|
|
336
|
+
|
|
337
|
+
def Mmap_size(self, *args) -> Self:
|
|
338
|
+
return self.add_func(SQL_FUNC_PRAGMA.MMAP_SIZE, *args)
|
|
339
|
+
|
|
340
|
+
def Module_list(self, *args) -> Self:
|
|
341
|
+
return self.add_func(SQL_FUNC_PRAGMA.MODULE_LIST, *args)
|
|
342
|
+
|
|
343
|
+
def Optimize(self, *args) -> Self:
|
|
344
|
+
return self.add_func(SQL_FUNC_PRAGMA.OPTIMIZE, *args)
|
|
345
|
+
|
|
346
|
+
def Page_count(self, *args) -> Self:
|
|
347
|
+
return self.add_func(SQL_FUNC_PRAGMA.PAGE_COUNT, *args)
|
|
348
|
+
|
|
349
|
+
def Page_size(self, *args) -> Self:
|
|
350
|
+
return self.add_func(SQL_FUNC_PRAGMA.PAGE_SIZE, *args)
|
|
351
|
+
|
|
352
|
+
def Pragma_list(self, *args) -> Self:
|
|
353
|
+
return self.add_func(SQL_FUNC_PRAGMA.PRAGMA_LIST, *args)
|
|
354
|
+
|
|
355
|
+
def Query_only(self, *args) -> Self:
|
|
356
|
+
return self.add_func(SQL_FUNC_PRAGMA.QUERY_ONLY, *args)
|
|
357
|
+
|
|
358
|
+
def Quick_check(self, *args) -> Self:
|
|
359
|
+
return self.add_func(SQL_FUNC_PRAGMA.QUICK_CHECK, *args)
|
|
360
|
+
|
|
361
|
+
def Read_uncommitted(self, *args) -> Self:
|
|
362
|
+
return self.add_func(SQL_FUNC_PRAGMA.READ_UNCOMMITTED, *args)
|
|
363
|
+
|
|
364
|
+
def Recursive_triggers(self, *args) -> Self:
|
|
365
|
+
return self.add_func(SQL_FUNC_PRAGMA.RECURSIVE_TRIGGERS, *args)
|
|
366
|
+
|
|
367
|
+
def Reverse_unordered_selects(self, *args) -> Self:
|
|
368
|
+
return self.add_func(SQL_FUNC_PRAGMA.REVERSE_UNORDERED_SELECTS, *args)
|
|
369
|
+
|
|
370
|
+
def Secure_delete(self, *args) -> Self:
|
|
371
|
+
return self.add_func(SQL_FUNC_PRAGMA.SECURE_DELETE, *args)
|
|
372
|
+
|
|
373
|
+
def Shrink_memory(self, *args) -> Self:
|
|
374
|
+
return self.add_func(SQL_FUNC_PRAGMA.SHRINK_MEMORY, *args)
|
|
375
|
+
|
|
376
|
+
def Soft_heap_limit(self, *args) -> Self:
|
|
377
|
+
return self.add_func(SQL_FUNC_PRAGMA.SOFT_HEAP_LIMIT, *args)
|
|
378
|
+
|
|
379
|
+
def Synchronous(self, *args) -> Self:
|
|
380
|
+
return self.add_func(SQL_FUNC_PRAGMA.SYNCHRONOUS, *args)
|
|
381
|
+
|
|
382
|
+
def Table_info(self, *args) -> Self:
|
|
383
|
+
return self.add_func(SQL_FUNC_PRAGMA.TABLE_INFO, *args)
|
|
384
|
+
|
|
385
|
+
def Table_list(self, *args) -> Self:
|
|
386
|
+
return self.add_func(SQL_FUNC_PRAGMA.TABLE_LIST, *args)
|
|
387
|
+
|
|
388
|
+
def Table_xinfo(self, *args) -> Self:
|
|
389
|
+
return self.add_func(SQL_FUNC_PRAGMA.TABLE_XINFO, *args)
|
|
390
|
+
|
|
391
|
+
def Temp_store(self, *args) -> Self:
|
|
392
|
+
return self.add_func(SQL_FUNC_PRAGMA.TEMP_STORE, *args)
|
|
393
|
+
|
|
394
|
+
def Threads(self, *args) -> Self:
|
|
395
|
+
return self.add_func(SQL_FUNC_PRAGMA.THREADS, *args)
|
|
396
|
+
|
|
397
|
+
def Trusted_schema(self, *args) -> Self:
|
|
398
|
+
return self.add_func(SQL_FUNC_PRAGMA.TRUSTED_SCHEMA, *args)
|
|
399
|
+
|
|
400
|
+
def User_version(self, *args) -> Self:
|
|
401
|
+
return self.add_func(SQL_FUNC_PRAGMA.USER_VERSION, *args)
|
|
402
|
+
|
|
403
|
+
def Wal_autocheckpoint(self, *args) -> Self:
|
|
404
|
+
return self.add_func(SQL_FUNC_PRAGMA.WAL_AUTOCHECKPOINT, *args)
|
|
405
|
+
|
|
406
|
+
def Wal_checkpoint(self, *args) -> Self:
|
|
407
|
+
return self.add_func(SQL_FUNC_PRAGMA.WAL_CHECKPOINT, *args)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from dataclasses import is_dataclass
|
|
2
|
+
|
|
3
|
+
__all__ = ["flatten", "add_commas", "add_parenthesis", "add_quotes", "placeholders"]
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _flatten_generator(*args):
|
|
8
|
+
for arg in args:
|
|
9
|
+
if isinstance(arg, list) | isinstance(arg, tuple):
|
|
10
|
+
yield from _flatten_generator(*arg)
|
|
11
|
+
else:
|
|
12
|
+
yield arg
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def flatten(*args):
|
|
16
|
+
return list(_flatten_generator(*args))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def add_commas(*args):
|
|
20
|
+
params = flatten(*args)
|
|
21
|
+
if len(params) > 1:
|
|
22
|
+
params[:-1] = [f"{param}," for param in params[:-1]]
|
|
23
|
+
return params
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_parenthesis(*args):
|
|
27
|
+
params = flatten(*args)
|
|
28
|
+
params = [item.__name__ if is_dataclass(item) else item for item in params]
|
|
29
|
+
if not params:
|
|
30
|
+
return ["()"]
|
|
31
|
+
elif len(params) == 1:
|
|
32
|
+
params[0] = f"({params[0]})"
|
|
33
|
+
else:
|
|
34
|
+
params[0] = f"({params[0]}"
|
|
35
|
+
params[-1] = f"{params[-1]})"
|
|
36
|
+
return params
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def add_quotes(*args):
|
|
40
|
+
params = [f'"{item}"' for item in flatten(*args)]
|
|
41
|
+
return params
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def placeholders(*args, count = None):
|
|
45
|
+
if count:
|
|
46
|
+
return ["?"] * count
|
|
47
|
+
else:
|
|
48
|
+
return ["?"] * len(flatten(*args)) if args else []
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
__all__ = ["QueryBuilder"]
|
|
2
|
+
from typing import Self
|
|
3
|
+
|
|
4
|
+
import dataclassdb.builders.list_utils as lu
|
|
5
|
+
from dataclassdb.builders.function_builder import FunctionBuilder
|
|
6
|
+
from dataclassdb.builders.statement_builder import StatementBuilder
|
|
7
|
+
from dataclassdb.db_engine import DbEngine
|
|
8
|
+
from dataclassdb.dataclass_types import IsDataclass
|
|
9
|
+
from dataclassdb.utils import PragmaTableInfo
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class QueryBuilder(DbEngine, StatementBuilder, FunctionBuilder):
|
|
13
|
+
_affinity_map = {
|
|
14
|
+
"INT": "INTEGER",
|
|
15
|
+
"INTEGER": "INTEGER",
|
|
16
|
+
"TINYINT": "INTEGER",
|
|
17
|
+
"SMALLINT": "INTEGER",
|
|
18
|
+
"MEDIUMINT": "INTEGER",
|
|
19
|
+
"BIGINT": "INTEGER",
|
|
20
|
+
"UNSIGNED BIG INT": "INTEGER",
|
|
21
|
+
"INT2": "INTEGER",
|
|
22
|
+
"INT8": "INTEGER",
|
|
23
|
+
"CHARACTER": "TEXT",
|
|
24
|
+
"VARCHAR": "TEXT",
|
|
25
|
+
"VARYING CHARACTER": "TEXT",
|
|
26
|
+
"NCHAR": "TEXT",
|
|
27
|
+
"NVARCHAR": "TEXT",
|
|
28
|
+
"TEXT": "TEXT",
|
|
29
|
+
"CLOB": "TEXT",
|
|
30
|
+
"BLOB": "BLOB",
|
|
31
|
+
"REAL": "REAL",
|
|
32
|
+
"DOUBLE": "REAL",
|
|
33
|
+
"DOUBLE PRECISION": "REAL",
|
|
34
|
+
"FLOAT": "REAL",
|
|
35
|
+
"NUMERIC": "REAL",
|
|
36
|
+
"DECIMAL": "REAL",
|
|
37
|
+
"BOOLEAN": "INTEGER",
|
|
38
|
+
"DATE": "TEXT", # Overridden
|
|
39
|
+
"DATETIME": "TEXT", # Overridden
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def eq(self) -> Self:
|
|
44
|
+
return self.add("=")
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def neq(self) -> Self:
|
|
48
|
+
return self.add("<>")
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def lpar(self) -> Self:
|
|
52
|
+
return self.add("(")
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def rpar(self) -> Self:
|
|
56
|
+
return self.add(")")
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def comma(self) -> Self:
|
|
60
|
+
if self.query:
|
|
61
|
+
self.query[-1] = f"{self.query[-1]},"
|
|
62
|
+
else:
|
|
63
|
+
self.query.append(",")
|
|
64
|
+
return self
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def end(self):
|
|
68
|
+
if self.query:
|
|
69
|
+
self.query[-1] = f"{self.query[-1]};"
|
|
70
|
+
else:
|
|
71
|
+
self.query.append(";")
|
|
72
|
+
return self
|
|
73
|
+
|
|
74
|
+
def par(self, *args, commas=True, quotes=False) -> Self:
|
|
75
|
+
return self.add(*args, commas=commas, quotes=quotes, par=True)
|
|
76
|
+
|
|
77
|
+
def quote(self, *args, commas=True, par=False) -> Self:
|
|
78
|
+
return self.add(*args, commas=commas, quotes=True, par=par)
|
|
79
|
+
|
|
80
|
+
def dot(self, rside: str = "") -> Self:
|
|
81
|
+
"""Appends `.{rside}` to the right of the last item in the query."""
|
|
82
|
+
dot_str = f".{rside}"
|
|
83
|
+
if self.query:
|
|
84
|
+
self.query[-1] = f"{self.query[-1]}{dot_str}"
|
|
85
|
+
else:
|
|
86
|
+
self.add(dot_str)
|
|
87
|
+
return self
|
|
88
|
+
|
|
89
|
+
def placeholders(self, *args, count=None, par=True) -> Self:
|
|
90
|
+
return self.add(lu.placeholders(*args, count=count), par=par)
|
|
91
|
+
|
|
92
|
+
def get_current_fields(self, _data_class) -> list[PragmaTableInfo]:
|
|
93
|
+
query = QueryBuilder().PRAGMA.Table_info(_data_class)
|
|
94
|
+
output = self.execute(sql_str=str(query), as_dict=True)
|
|
95
|
+
return PragmaTableInfo.from_list(output)
|
|
96
|
+
|
|
97
|
+
def get_curr_cols(self, _data_class) -> list[str]:
|
|
98
|
+
row = (
|
|
99
|
+
QueryBuilder(self.connection)
|
|
100
|
+
.SELECT("sql")
|
|
101
|
+
.FROM("sqlite_schema")
|
|
102
|
+
.WHERE("name")
|
|
103
|
+
.eq.quote(_data_class)
|
|
104
|
+
# .AND("name")
|
|
105
|
+
# .eq.quote(_data_class)
|
|
106
|
+
).execute_one()
|
|
107
|
+
if not row:
|
|
108
|
+
return []
|
|
109
|
+
|
|
110
|
+
cols = row[0].split("(", 1)[-1].rsplit(")", 1)[0].split(",")
|
|
111
|
+
cols = [col.replace("\n", "").strip() for col in cols]
|
|
112
|
+
return cols
|
|
113
|
+
|
|
114
|
+
def select(self, *args):
|
|
115
|
+
"""This version of select handles the case where dot notation
|
|
116
|
+
is used in a select.
|
|
117
|
+
`SELECT user.id -> SELECT user.id AS [user.id]`
|
|
118
|
+
Without this change sqlite will ignore the prefix when creating
|
|
119
|
+
the output row.
|
|
120
|
+
"""
|
|
121
|
+
params = []
|
|
122
|
+
for arg in args:
|
|
123
|
+
if "." in arg:
|
|
124
|
+
params.append(f"{arg} AS [{arg}]")
|
|
125
|
+
else:
|
|
126
|
+
params.append(arg)
|
|
127
|
+
return self.SELECT(*params)
|
|
128
|
+
|
|
129
|
+
def from_(self, table: str | IsDataclass, as_=""):
|
|
130
|
+
self.FROM(table)
|
|
131
|
+
if as_:
|
|
132
|
+
self.AS(as_)
|
|
133
|
+
return self
|
|
134
|
+
|
|
135
|
+
def join(
|
|
136
|
+
self, table: str | IsDataclass, as_="", on="", using_cols=[], join_type=""
|
|
137
|
+
):
|
|
138
|
+
if on and using_cols:
|
|
139
|
+
raise SyntaxError("Cannot have both 'ON' and 'USING' statements in a join.")
|
|
140
|
+
if join_type:
|
|
141
|
+
self(join_type)
|
|
142
|
+
self.JOIN(table)
|
|
143
|
+
if as_:
|
|
144
|
+
self.AS(as_)
|
|
145
|
+
if on:
|
|
146
|
+
self.ON(on)
|
|
147
|
+
elif using_cols:
|
|
148
|
+
self.USING(lu.flatten(using_cols), par=True)
|
|
149
|
+
return self
|
|
150
|
+
|
|
151
|
+
@staticmethod
|
|
152
|
+
def get_sql_col_affinity(col_name) -> str | None:
|
|
153
|
+
if "(" in col_name:
|
|
154
|
+
col = col_name.split("(")[0]
|
|
155
|
+
else:
|
|
156
|
+
col = col_name
|
|
157
|
+
|
|
158
|
+
return QueryBuilder._affinity_map.get(col, None)
|