reydb 1.1.49__py3-none-any.whl → 1.1.50__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.
reydb/__init__.py CHANGED
@@ -19,5 +19,6 @@ rerror : Database error methods.
19
19
  rexec : Database execute methods.
20
20
  rfile : Database file methods.
21
21
  rinfo : Database information methods.
22
+ rorm : Database ORM methods.
22
23
  rparam : Database parameter methods.
23
24
  """
reydb/rall.py CHANGED
@@ -18,4 +18,5 @@ from .rerror import *
18
18
  from .rexec import *
19
19
  from .rfile import *
20
20
  from .rinfo import *
21
+ from .rorm import *
21
22
  from .rparam import *
reydb/rbuild.py CHANGED
@@ -15,7 +15,6 @@ from reykit.rbase import throw
15
15
  from reykit.rstdout import ask
16
16
 
17
17
  from .rbase import DatabaseBase, extract_path
18
- from .rconn import DatabaseConnection
19
18
  from .rdb import Database
20
19
 
21
20
 
@@ -52,17 +51,17 @@ class DatabaseBuild(DatabaseBase):
52
51
  """
53
52
 
54
53
 
55
- def __init__(self, database: Database | DatabaseConnection) -> None:
54
+ def __init__(self, db: Database) -> None:
56
55
  """
57
56
  Build instance attributes.
58
57
 
59
58
  Parameters
60
59
  ----------
61
- database : Database or DatabaseConnection instance.
60
+ db: Database instance.
62
61
  """
63
62
 
64
63
  # Set attribute.
65
- self.database = database
64
+ self.db = db
66
65
  self._schema: dict[str, dict[str, list[str]]] | None = None
67
66
 
68
67
 
@@ -93,7 +92,7 @@ class DatabaseBuild(DatabaseBase):
93
92
 
94
93
  # Execute.
95
94
  if execute:
96
- self.database.execute(sql)
95
+ self.db.execute(sql)
97
96
 
98
97
  return sql
99
98
 
@@ -343,7 +342,7 @@ class DatabaseBuild(DatabaseBase):
343
342
 
344
343
  # Execute.
345
344
  if execute:
346
- self.database.execute(sql)
345
+ self.db.execute(sql)
347
346
 
348
347
  return sql
349
348
 
@@ -379,7 +378,7 @@ class DatabaseBuild(DatabaseBase):
379
378
 
380
379
  # Execute.
381
380
  if execute:
382
- self.database.execute(sql)
381
+ self.db.execute(sql)
383
382
 
384
383
  return sql
385
384
 
@@ -472,7 +471,7 @@ class DatabaseBuild(DatabaseBase):
472
471
 
473
472
  # Execute.
474
473
  if execute:
475
- self.database.execute(sql)
474
+ self.db.execute(sql)
476
475
 
477
476
  return sql
478
477
 
@@ -505,7 +504,7 @@ class DatabaseBuild(DatabaseBase):
505
504
 
506
505
  # Execute.
507
506
  if execute:
508
- self.database.execute(sql)
507
+ self.db.execute(sql)
509
508
 
510
509
  return sql
511
510
 
@@ -538,7 +537,7 @@ class DatabaseBuild(DatabaseBase):
538
537
 
539
538
  # Execute.
540
539
  if execute:
541
- self.database.execute(sql)
540
+ self.db.execute(sql)
542
541
 
543
542
  return sql
544
543
 
@@ -588,7 +587,7 @@ class DatabaseBuild(DatabaseBase):
588
587
 
589
588
  # Execute.
590
589
  if execute:
591
- self.database.execute(sql)
590
+ self.db.execute(sql)
592
591
 
593
592
  return sql
594
593
 
@@ -703,7 +702,7 @@ class DatabaseBuild(DatabaseBase):
703
702
 
704
703
  # Execute.
705
704
  if execute:
706
- self.database.execute(sql)
705
+ self.db.execute(sql)
707
706
 
708
707
  return sql
709
708
 
@@ -774,7 +773,7 @@ class DatabaseBuild(DatabaseBase):
774
773
 
775
774
  # Execute.
776
775
  if execute:
777
- self.database.execute(sql)
776
+ self.db.execute(sql)
778
777
 
779
778
  return sql
780
779
 
@@ -893,7 +892,7 @@ class DatabaseBuild(DatabaseBase):
893
892
 
894
893
  # Execute.
895
894
  if execute:
896
- self.database.execute(sql)
895
+ self.db.execute(sql)
897
896
 
898
897
  return sql
899
898
 
@@ -928,7 +927,7 @@ class DatabaseBuild(DatabaseBase):
928
927
 
929
928
  # Execute.
930
929
  if execute:
931
- self.database.execute(sql)
930
+ self.db.execute(sql)
932
931
 
933
932
  return sql
934
933
 
@@ -961,7 +960,7 @@ class DatabaseBuild(DatabaseBase):
961
960
 
962
961
  # Execute.
963
962
  if execute:
964
- self.database.execute(sql)
963
+ self.db.execute(sql)
965
964
 
966
965
  return sql
967
966
 
@@ -987,7 +986,7 @@ class DatabaseBuild(DatabaseBase):
987
986
  # Handle parameter.
988
987
  database, table, column = extract_path(path)
989
988
  if self._schema is None:
990
- self._schema = self.database.schema(False)
989
+ self._schema = self.db.schema(False)
991
990
 
992
991
  # Judge.
993
992
  judge = (
@@ -1077,7 +1076,7 @@ class DatabaseBuild(DatabaseBase):
1077
1076
  database = params['name']
1078
1077
 
1079
1078
  ## Exist.
1080
- exist = self.database.build.exist((database, None, None))
1079
+ exist = self.db.build.exist((database, None, None))
1081
1080
  if exist:
1082
1081
  continue
1083
1082
 
@@ -1088,7 +1087,7 @@ class DatabaseBuild(DatabaseBase):
1088
1087
  self.input_confirm_build(sql)
1089
1088
 
1090
1089
  ## Execute.
1091
- self.database.execute(sql)
1090
+ self.db.execute(sql)
1092
1091
 
1093
1092
  ## Report.
1094
1093
  text = f"Database '{database}' build completed."
@@ -1100,7 +1099,7 @@ class DatabaseBuild(DatabaseBase):
1100
1099
  database, table, _ = extract_path(path)
1101
1100
 
1102
1101
  ## Exist.
1103
- exist = self.database.build.exist((database, table, None))
1102
+ exist = self.db.build.exist((database, table, None))
1104
1103
  if exist:
1105
1104
  continue
1106
1105
 
@@ -1111,7 +1110,7 @@ class DatabaseBuild(DatabaseBase):
1111
1110
  self.input_confirm_build(sql)
1112
1111
 
1113
1112
  ## Execute.
1114
- self.database.execute(sql)
1113
+ self.db.execute(sql)
1115
1114
 
1116
1115
  ## Report.
1117
1116
  text = f"Table '{table}' of database '{database}' build completed."
@@ -1123,7 +1122,7 @@ class DatabaseBuild(DatabaseBase):
1123
1122
  database, view, _ = extract_path(path)
1124
1123
 
1125
1124
  ## Exist.
1126
- exist = self.database.build.exist((database, view, None))
1125
+ exist = self.db.build.exist((database, view, None))
1127
1126
  if exist:
1128
1127
  continue
1129
1128
 
@@ -1134,7 +1133,7 @@ class DatabaseBuild(DatabaseBase):
1134
1133
  self.input_confirm_build(sql)
1135
1134
 
1136
1135
  ## Execute.
1137
- self.database.execute(sql)
1136
+ self.db.execute(sql)
1138
1137
 
1139
1138
  ## Report.
1140
1139
  text = f"View '{view}' of database '{database}' build completed."
@@ -1146,7 +1145,7 @@ class DatabaseBuild(DatabaseBase):
1146
1145
  database, view, _ = extract_path(path)
1147
1146
 
1148
1147
  ## Exist.
1149
- exist = self.database.build.exist((database, view, None))
1148
+ exist = self.db.build.exist((database, view, None))
1150
1149
  if exist:
1151
1150
  continue
1152
1151
 
@@ -1157,7 +1156,7 @@ class DatabaseBuild(DatabaseBase):
1157
1156
  self.input_confirm_build(sql)
1158
1157
 
1159
1158
  ## Execute.
1160
- self.database.execute(sql)
1159
+ self.db.execute(sql)
1161
1160
 
1162
1161
  ## Report.
1163
1162
  text = f"View '{view}' of database '{database}' build completed."
reydb/rconfig.py CHANGED
@@ -19,7 +19,6 @@ from datetime import (
19
19
  )
20
20
  from reykit.rbase import null, throw
21
21
 
22
- from .rconn import DatabaseConnection
23
22
  from .rdb import Database
24
23
 
25
24
 
@@ -49,13 +48,17 @@ class DatabaseConfig(object):
49
48
  """
50
49
 
51
50
 
52
- def __init__(self, database: Database | DatabaseConnection) -> None:
51
+ def __init__(self, db: Database) -> None:
53
52
  """
54
53
  Build instance attributes.
54
+
55
+ Parameters
56
+ ----------
57
+ db: Database instance.
55
58
  """
56
59
 
57
60
  # Build.
58
- self.database = database
61
+ self.db = db
59
62
 
60
63
  ## Database path name.
61
64
  self.db_names = {
@@ -180,7 +183,7 @@ class DatabaseConfig(object):
180
183
  ]
181
184
 
182
185
  # Build.
183
- self.database.build.build(databases, tables, views_stats=views_stats)
186
+ self.db.build.build(databases, tables, views_stats=views_stats)
184
187
 
185
188
 
186
189
  @property
@@ -194,7 +197,7 @@ class DatabaseConfig(object):
194
197
  """
195
198
 
196
199
  # Get.
197
- result = self.database.execute.select(
200
+ result = self.db.execute.select(
198
201
  (self.db_names['base'], self.db_names['base.config']),
199
202
  ['key', 'value', 'type', 'note'],
200
203
  order='IFNULL(`update_time`, `create_time`) DESC'
@@ -230,7 +233,7 @@ class DatabaseConfig(object):
230
233
 
231
234
  # Get.
232
235
  where = '`key` = :key'
233
- result = self.database.execute.select(
236
+ result = self.db.execute.select(
234
237
  (self.db_names['base'], self.db_names['base.config']),
235
238
  '`value`',
236
239
  where,
@@ -276,7 +279,7 @@ class DatabaseConfig(object):
276
279
  'type': type(default).__name__,
277
280
  'note': default_note
278
281
  }
279
- result = self.database.execute.insert(
282
+ result = self.db.execute.insert(
280
283
  (self.db_names['base'], self.db_names['base.config']),
281
284
  data,
282
285
  'ignore'
@@ -317,7 +320,7 @@ class DatabaseConfig(object):
317
320
  row['type'] = type(row['value']).__name__
318
321
 
319
322
  # Update.
320
- self.database.execute.insert(
323
+ self.db.execute.insert(
321
324
  (self.db_names['base'], self.db_names['base.config']),
322
325
  data,
323
326
  'update'
@@ -340,7 +343,7 @@ class DatabaseConfig(object):
340
343
  else:
341
344
  where = '`key` in :key'
342
345
  limit = None
343
- result = self.database.execute.delete(
346
+ result = self.db.execute.delete(
344
347
  (self.db_names['base'], self.db_names['base.config']),
345
348
  where,
346
349
  limit=limit,
@@ -362,7 +365,7 @@ class DatabaseConfig(object):
362
365
  """
363
366
 
364
367
  # Get.
365
- result = self.database.execute.select(
368
+ result = self.db.execute.select(
366
369
  (self.db_names['base'], self.db_names['base.config']),
367
370
  ['key', 'value']
368
371
  )
@@ -388,7 +391,7 @@ class DatabaseConfig(object):
388
391
  """
389
392
 
390
393
  # Get.
391
- result = self.database.execute.select(
394
+ result = self.db.execute.select(
392
395
  (self.db_names['base'], self.db_names['base.config']),
393
396
  '`key`'
394
397
  )
@@ -413,7 +416,7 @@ class DatabaseConfig(object):
413
416
  """
414
417
 
415
418
  # Get.
416
- result = self.database.execute.select(
419
+ result = self.db.execute.select(
417
420
  (self.db_names['base'], self.db_names['base.config']),
418
421
  '`value`'
419
422
  )
@@ -475,7 +478,7 @@ class DatabaseConfig(object):
475
478
  'type': type(value).__name__,
476
479
  'note': note
477
480
  }
478
- self.database.execute.insert(
481
+ self.db.execute.insert(
479
482
  (self.db_names['base'], self.db_names['base.config']),
480
483
  data,
481
484
  'update'
reydb/rdb.py CHANGED
@@ -25,11 +25,13 @@ __all__ = (
25
25
 
26
26
  class Database(DatabaseBase):
27
27
  """
28
- Database type.
29
- Based `MySQL`.
28
+ Database type, based `MySQL`.
29
+
30
+ Attributes
31
+ ----------
32
+ default_report : Whether default to report execution.
30
33
  """
31
34
 
32
- # Whether default to report execution.
33
35
  default_report: bool = False
34
36
 
35
37
 
@@ -206,45 +208,6 @@ class Database(DatabaseBase):
206
208
  return keep_n, overflow_n
207
209
 
208
210
 
209
- def connect(self, autocommit: bool = False):
210
- """
211
- Build `DatabaseConnection` instance.
212
-
213
- Parameters
214
- ----------
215
- autocommit: Whether automatic commit connection.
216
-
217
- Returns
218
- -------
219
- Database connection instance.
220
- """
221
-
222
- # Import.
223
- from .rconn import DatabaseConnection
224
-
225
- # Build.
226
- conn = DatabaseConnection(self, autocommit)
227
-
228
- return conn
229
-
230
-
231
- @property
232
- def execute(self):
233
- """
234
- Build `database execute` instance.
235
-
236
- Returns
237
- -------
238
- Instance.
239
- """
240
-
241
- # Build.
242
- dbconn = self.connect(True)
243
- exec = dbconn.execute
244
-
245
- return exec
246
-
247
-
248
211
  def schema(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
249
212
  """
250
213
  Get schemata of databases and tables and columns.
@@ -309,12 +272,70 @@ class Database(DatabaseBase):
309
272
  column_list.append(column)
310
273
 
311
274
  ## Add empty database.
312
- for database_name in database_names:
313
- schema_dict[database_name] = None
275
+ for name in database_names:
276
+ schema_dict[name] = None
314
277
 
315
278
  return schema_dict
316
279
 
317
280
 
281
+ def connect(self, autocommit: bool = False):
282
+ """
283
+ Build `DatabaseConnection` instance.
284
+
285
+ Parameters
286
+ ----------
287
+ autocommit: Whether automatic commit connection.
288
+
289
+ Returns
290
+ -------
291
+ Database connection instance.
292
+ """
293
+
294
+ # Import.
295
+ from .rconn import DatabaseConnection
296
+
297
+ # Build.
298
+ conn = DatabaseConnection(self, autocommit)
299
+
300
+ return conn
301
+
302
+
303
+ @property
304
+ def execute(self):
305
+ """
306
+ Build `DatabaseExecute` instance.
307
+
308
+ Returns
309
+ -------
310
+ Instance.
311
+ """
312
+
313
+ # Build.
314
+ dbconn = self.connect(True)
315
+ exec = dbconn.execute
316
+
317
+ return exec
318
+
319
+
320
+ @property
321
+ def orm(self):
322
+ """
323
+ Build `DatabaseORM` instance.
324
+
325
+ Returns
326
+ -------
327
+ Instance.
328
+ """
329
+
330
+ # Import.
331
+ from .rorm import DatabaseORM
332
+
333
+ # Build.
334
+ orm = DatabaseORM(self)
335
+
336
+ return orm
337
+
338
+
318
339
  @property
319
340
  def info(self):
320
341
  """
reydb/rerror.py CHANGED
@@ -13,10 +13,9 @@ from typing import Any
13
13
  from collections.abc import Callable
14
14
  from traceback import StackSummary
15
15
  from functools import wraps as functools_wraps
16
- from reykit.rbase import T, Exit, throw, catch_exc
16
+ from reykit.rbase import T, Exit, catch_exc
17
17
 
18
18
  from .rbase import DatabaseBase
19
- from .rconn import DatabaseConnection
20
19
  from .rdb import Database
21
20
 
22
21
 
@@ -32,17 +31,17 @@ class DatabaseError(DatabaseBase):
32
31
  """
33
32
 
34
33
 
35
- def __init__(self, database: Database | DatabaseConnection) -> None:
34
+ def __init__(self, db: Database) -> None:
36
35
  """
37
36
  Build instance attributes.
38
37
 
39
38
  Parameters
40
39
  ----------
41
- database : Database or DatabaseConnection instance.
40
+ db: Database instance.
42
41
  """
43
42
 
44
43
  # Build.
45
- self.database = database
44
+ self.db = db
46
45
 
47
46
  ## Database path name.
48
47
  self.db_names = {
@@ -184,7 +183,7 @@ class DatabaseError(DatabaseBase):
184
183
  ]
185
184
 
186
185
  # Build.
187
- self.database.build.build(databases, tables, views_stats=views_stats)
186
+ self.db.build.build(databases, tables, views_stats=views_stats)
188
187
 
189
188
 
190
189
  def record(
@@ -223,7 +222,7 @@ class DatabaseError(DatabaseBase):
223
222
  }
224
223
 
225
224
  # Insert.
226
- self.database.execute.insert(
225
+ self.db.execute.insert(
227
226
  (self.db_names['base'], self.db_names['base.error']),
228
227
  data=data
229
228
  )
reydb/rfile.py CHANGED
@@ -11,11 +11,9 @@
11
11
 
12
12
  from typing import TypedDict, overload
13
13
  from datetime import datetime
14
- from reykit.rbase import throw
15
14
  from reykit.ros import File, Folder, get_md5
16
15
 
17
16
  from .rbase import DatabaseBase
18
- from .rconn import DatabaseConnection
19
17
  from .rdb import Database
20
18
 
21
19
 
@@ -34,17 +32,17 @@ class DatabaseFile(DatabaseBase):
34
32
  """
35
33
 
36
34
 
37
- def __init__(self, database: Database | DatabaseConnection) -> None:
35
+ def __init__(self, db: Database) -> None:
38
36
  """
39
37
  Build instance attributes.
40
38
 
41
39
  Parameters
42
40
  ----------
43
- database : Database or DatabaseConnection instance.
41
+ db: Database instance.
44
42
  """
45
43
 
46
44
  # Build.
47
- self.database = database
45
+ self.db = db
48
46
 
49
47
  ## Database path name.
50
48
  self.db_names = {
@@ -274,7 +272,7 @@ class DatabaseFile(DatabaseBase):
274
272
  ]
275
273
 
276
274
  # Build.
277
- self.database.build.build(databases, tables, views, views_stats)
275
+ self.db.build.build(databases, tables, views, views_stats)
278
276
 
279
277
 
280
278
  def upload(
@@ -302,7 +300,7 @@ class DatabaseFile(DatabaseBase):
302
300
  """
303
301
 
304
302
  # Handle parameter.
305
- conn = self.database.connect()
303
+ conn = self.db.connect()
306
304
  match source:
307
305
 
308
306
  ## File path.
@@ -419,7 +417,7 @@ class DatabaseFile(DatabaseBase):
419
417
  )
420
418
 
421
419
  # Execute SQL.
422
- result = self.database.execute(sql, file_id=file_id)
420
+ result = self.db.execute(sql, file_id=file_id)
423
421
 
424
422
  # Check.
425
423
  if result.empty:
@@ -471,7 +469,7 @@ class DatabaseFile(DatabaseBase):
471
469
  )
472
470
 
473
471
  # Execute SQL.
474
- result = self.database.execute(sql, file_id=file_id)
472
+ result = self.db.execute(sql, file_id=file_id)
475
473
 
476
474
  # Check.
477
475
  if result.empty:
reydb/rinfo.py CHANGED
@@ -11,10 +11,8 @@
11
11
 
12
12
  from __future__ import annotations
13
13
  from typing import Any, Literal, overload
14
- from reykit.rbase import throw
15
14
 
16
15
  from .rbase import DatabaseBase
17
- from .rconn import DatabaseConnection
18
16
  from .rdb import Database
19
17
 
20
18
 
@@ -151,11 +149,11 @@ class DatabaseInformation(DatabaseBase):
151
149
  # Build.
152
150
  match self:
153
151
  case DatabaseInformationSchema():
154
- table = DatabaseInformationDatabase(self._rdatabase, name)
152
+ table = DatabaseInformationDatabase(self.db, name)
155
153
  case DatabaseInformationDatabase():
156
- table = DatabaseInformationTable(self._rdatabase, self._database_name, name)
154
+ table = DatabaseInformationTable(self.db, self.database, name)
157
155
  case DatabaseInformationTable():
158
- table = DatabaseInformationColumn(self._rdatabase, self._database_name, self._table_name, name)
156
+ table = DatabaseInformationColumn(self.db, self.database, self.table, name)
159
157
  case _:
160
158
  raise AssertionError("class '%s' does not have this method" % type(self).__name__)
161
159
 
@@ -193,18 +191,18 @@ class DatabaseInformationSchema(DatabaseInformation):
193
191
 
194
192
  def __init__(
195
193
  self,
196
- rdatabase: Database | DatabaseConnection
194
+ db: Database
197
195
  ) -> None:
198
196
  """
199
197
  Build instance attributes.
200
198
 
201
199
  Parameters
202
200
  ----------
203
- rdatabase : Database or DatabaseConnection instance.
201
+ db: Database instance.
204
202
  """
205
203
 
206
204
  # Set parameter.
207
- self._rdatabase = rdatabase
205
+ self.db = db
208
206
 
209
207
 
210
208
  def _get_info_table(self) -> list[dict]:
@@ -217,7 +215,7 @@ class DatabaseInformationSchema(DatabaseInformation):
217
215
  """
218
216
 
219
217
  # Select.
220
- result = self._rdatabase.execute.select(
218
+ result = self.db.execute.select(
221
219
  'information_schema.SCHEMATA',
222
220
  order='`schema_name`'
223
221
  )
@@ -256,21 +254,21 @@ class DatabaseInformationDatabase(DatabaseInformation):
256
254
 
257
255
  def __init__(
258
256
  self,
259
- rdatabase: Database | DatabaseConnection,
260
- database_name: str
257
+ db: Database,
258
+ database: str
261
259
  ) -> None:
262
260
  """
263
261
  Build instance attributes.
264
262
 
265
263
  Parameters
266
264
  ----------
267
- rdatabase : Database or DatabaseConnection instance.
268
- database_name : Database name.
265
+ db: Database instance.
266
+ database : Database name.
269
267
  """
270
268
 
271
269
  # Set parameter.
272
- self._rdatabase = rdatabase
273
- self._database_name = database_name
270
+ self.db = db
271
+ self.database = database
274
272
 
275
273
 
276
274
  def _get_info_attrs(self) -> dict:
@@ -283,19 +281,19 @@ class DatabaseInformationDatabase(DatabaseInformation):
283
281
  """
284
282
 
285
283
  # Select.
286
- where = '`SCHEMA_NAME` = :database_name'
287
- result = self._rdatabase.execute.select(
284
+ where = '`SCHEMA_NAME` = :database'
285
+ result = self.db.execute.select(
288
286
  'information_schema.SCHEMATA',
289
287
  where=where,
290
288
  limit=1,
291
- database_name=self._database_name
289
+ database=self.database
292
290
  )
293
291
 
294
292
  # Convert.
295
293
  info_table = result.to_table()
296
294
 
297
295
  ## Check.
298
- assert len(info_table) != 0, "database '%s' not exist" % self._database_name
296
+ assert len(info_table) != 0, "database '%s' not exist" % self.database
299
297
 
300
298
  info_attrs = info_table[0]
301
299
 
@@ -312,19 +310,19 @@ class DatabaseInformationDatabase(DatabaseInformation):
312
310
  """
313
311
 
314
312
  # Select.
315
- where = '`TABLE_SCHEMA` = :database_name'
316
- result = self._rdatabase.execute.select(
313
+ where = '`TABLE_SCHEMA` = :database'
314
+ result = self.db.execute.select(
317
315
  'information_schema.TABLES',
318
316
  where=where,
319
317
  order='`TABLE_NAME`',
320
- database_name=self._database_name
318
+ database=self.database
321
319
  )
322
320
 
323
321
  # Convert.
324
322
  info_table = result.to_table()
325
323
 
326
324
  ## Check.
327
- assert len(info_table) != 0, "database '%s' not exist" % self._database_name
325
+ assert len(info_table) != 0, "database '%s' not exist" % self.database
328
326
 
329
327
  return info_table
330
328
 
@@ -351,24 +349,24 @@ class DatabaseInformationTable(DatabaseInformation):
351
349
 
352
350
  def __init__(
353
351
  self,
354
- rdatabase: Database | DatabaseConnection,
355
- database_name: str,
356
- table_name: str
352
+ db: Database,
353
+ database: str,
354
+ table: str
357
355
  ) -> None:
358
356
  """
359
357
  Build instance attributes.
360
358
 
361
359
  Parameters
362
360
  ----------
363
- rdatabase : Database or DatabaseConnection instance.
364
- database_name : Database name.
365
- table_name : Table name.
361
+ db: Database instance.
362
+ database : Database name.
363
+ table : Table name.
366
364
  """
367
365
 
368
366
  # Set parameter.
369
- self._rdatabase = rdatabase
370
- self._database_name = database_name
371
- self._table_name = table_name
367
+ self.db = db
368
+ self.database = database
369
+ self.table = table
372
370
 
373
371
 
374
372
  def _get_info_attrs(self) -> dict:
@@ -381,20 +379,20 @@ class DatabaseInformationTable(DatabaseInformation):
381
379
  """
382
380
 
383
381
  # Select.
384
- where = '`TABLE_SCHEMA` = :database_name AND `TABLE_NAME` = :table_name'
385
- result = self._rdatabase.execute.select(
382
+ where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_'
383
+ result = self.db.execute.select(
386
384
  'information_schema.TABLES',
387
385
  where=where,
388
386
  limit=1,
389
- database_name=self._database_name,
390
- table_name=self._table_name
387
+ database=self.database,
388
+ table_=self.table
391
389
  )
392
390
 
393
391
  # Convert.
394
392
  info_table = result.to_table()
395
393
 
396
394
  ## Check.
397
- assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self._database_name, self._table_name)
395
+ assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self.database, self.table)
398
396
 
399
397
  info_attrs = info_table[0]
400
398
 
@@ -411,20 +409,20 @@ class DatabaseInformationTable(DatabaseInformation):
411
409
  """
412
410
 
413
411
  # Select.
414
- where = '`TABLE_SCHEMA` = :database_name AND `TABLE_NAME` = :table_name'
415
- result = self._rdatabase.execute.select(
412
+ where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_'
413
+ result = self.db.execute.select(
416
414
  'information_schema.COLUMNS',
417
415
  where=where,
418
416
  order='`ORDINAL_POSITION`',
419
- database_name=self._database_name,
420
- table_name=self._table_name
417
+ database=self.database,
418
+ table_=self.table
421
419
  )
422
420
 
423
421
  # Convert.
424
422
  info_table = result.to_table()
425
423
 
426
424
  ## Check.
427
- assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self._database_name, self._table_name)
425
+ assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self.database, self.table)
428
426
 
429
427
  return info_table
430
428
 
@@ -445,27 +443,27 @@ class DatabaseInformationColumn(DatabaseInformation):
445
443
 
446
444
  def __init__(
447
445
  self,
448
- rdatabase: Database | DatabaseConnection,
449
- database_name: str,
450
- table_name: str,
451
- column_name: str
446
+ db: Database,
447
+ database: str,
448
+ table: str,
449
+ column: str
452
450
  ) -> None:
453
451
  """
454
452
  Build instance attributes.
455
453
 
456
454
  Parameters
457
455
  ----------
458
- rdatabase : Database or DatabaseConnection instance.
459
- database_name : Database name.
460
- table_name : Table name.
461
- column_name : Column name.
456
+ db: Database instance.
457
+ database : Database name.
458
+ table : Table name.
459
+ column : Column name.
462
460
  """
463
461
 
464
462
  # Set parameter.
465
- self._rdatabase = rdatabase
466
- self._database_name = database_name
467
- self._table_name = table_name
468
- self._column_name = column_name
463
+ self.db = db
464
+ self.database = database
465
+ self.table = table
466
+ self.column = column
469
467
 
470
468
 
471
469
  def _get_info_attrs(self) -> dict:
@@ -478,21 +476,21 @@ class DatabaseInformationColumn(DatabaseInformation):
478
476
  """
479
477
 
480
478
  # Select.
481
- where = '`TABLE_SCHEMA` = :database_name AND `TABLE_NAME` = :table_name AND `COLUMN_NAME` = :column_name'
482
- result = self._rdatabase.execute.select(
479
+ where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_ AND `COLUMN_NAME` = :column'
480
+ result = self.db.execute.select(
483
481
  'information_schema.COLUMNS',
484
482
  where=where,
485
483
  limit=1,
486
- database_name=self._database_name,
487
- table_name=self._table_name,
488
- column_name=self._column_name
484
+ database=self.database,
485
+ table_=self.table,
486
+ column=self.column
489
487
  )
490
488
 
491
489
  # Convert.
492
490
  info_table = result.to_table()
493
491
 
494
492
  ## Check.
495
- assert len(info_table) != 0, "database '%s' or table '%s' or column '%s' not exist" % (self._database_name, self._table_name, self._column_name)
493
+ assert len(info_table) != 0, "database '%s' or table '%s' or column '%s' not exist" % (self.database, self.table, self.column)
496
494
 
497
495
  info_attrs = info_table[0]
498
496
 
reydb/rorm.py ADDED
@@ -0,0 +1,39 @@
1
+ # !/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ @Time : 2025-09-23 00:50:32
6
+ @Author : Rey
7
+ @Contact : reyxbo@163.com
8
+ @Explain : Database ORM methods.
9
+ """
10
+
11
+
12
+ from sqlmodel import SQLModel, Session
13
+
14
+ from .rbase import DatabaseBase
15
+ from .rdb import Database
16
+
17
+
18
+ __all__ = (
19
+ 'DatabaseORM',
20
+ )
21
+
22
+
23
+ class DatabaseORM(DatabaseBase):
24
+ """
25
+ Database ORM type.
26
+ """
27
+
28
+
29
+ def __init__(self, db: Database) -> None:
30
+ """
31
+ Build instance attributes.
32
+
33
+ Parameters
34
+ ----------
35
+ db: Database instance.
36
+ """
37
+
38
+ # Build.
39
+ self.db = db
reydb/rparam.py CHANGED
@@ -12,7 +12,6 @@
12
12
  from typing import overload
13
13
 
14
14
  from .rbase import DatabaseBase
15
- from .rconn import DatabaseConnection
16
15
  from .rdb import Database
17
16
 
18
17
 
@@ -32,7 +31,7 @@ class DatabaseParameters(DatabaseBase):
32
31
 
33
32
  def __init__(
34
33
  self,
35
- rdatabase: Database | DatabaseConnection,
34
+ db: Database,
36
35
  global_: bool
37
36
  ) -> None:
38
37
  """
@@ -40,12 +39,12 @@ class DatabaseParameters(DatabaseBase):
40
39
 
41
40
  Parameters
42
41
  ----------
43
- rdatabase : Database or DatabaseConnection instance.
42
+ db: Database instance.
44
43
  global\\_ : Whether base global.
45
44
  """
46
45
 
47
46
  # Set parameter.
48
- self.rdatabase = rdatabase
47
+ self.db = db
49
48
  self.global_ = global_
50
49
 
51
50
 
@@ -126,13 +125,13 @@ class DatabaseParametersStatus(DatabaseParameters):
126
125
 
127
126
  ## Dictionary.
128
127
  if key is None:
129
- result = self.rdatabase.execute(sql, key=key)
128
+ result = self.db.execute(sql, key=key)
130
129
  status = result.to_dict(val_field=1)
131
130
 
132
131
  ## Value.
133
132
  else:
134
133
  sql += ' LIKE :key'
135
- result = self.rdatabase.execute(sql, key=key)
134
+ result = self.db.execute(sql, key=key)
136
135
  row = result.first()
137
136
  if row is None:
138
137
  status = None
@@ -196,13 +195,13 @@ class DatabaseParametersVariable(DatabaseParameters):
196
195
 
197
196
  ## Dictionary.
198
197
  if key is None:
199
- result = self.rdatabase.execute(sql, key=key)
198
+ result = self.db.execute(sql, key=key)
200
199
  variables = result.to_dict(val_field=1)
201
200
 
202
201
  ## Value.
203
202
  else:
204
203
  sql += ' LIKE :key'
205
- result = self.rdatabase.execute(sql, key=key)
204
+ result = self.db.execute(sql, key=key)
206
205
  row = result.first()
207
206
  if row is None:
208
207
  variables = None
@@ -244,7 +243,7 @@ class DatabaseParametersVariable(DatabaseParameters):
244
243
  sql = f'SET {sql_set}'
245
244
 
246
245
  # Execute SQL.
247
- self.rdatabase.execute(sql)
246
+ self.db.execute(sql)
248
247
 
249
248
 
250
249
  class DatabaseParametersPragma(DatabaseParameters):
@@ -255,18 +254,18 @@ class DatabaseParametersPragma(DatabaseParameters):
255
254
 
256
255
  def __init__(
257
256
  self,
258
- rdatabase: Database | DatabaseConnection
257
+ db: Database
259
258
  ) -> None:
260
259
  """
261
260
  Build instance attributes.
262
261
 
263
262
  Parameters
264
263
  ----------
265
- rdatabase : Database or DatabaseConnection instance.
264
+ db: Database instance.
266
265
  """
267
266
 
268
267
  # Set parameter.
269
- self.rdatabase = rdatabase
268
+ self.db = db
270
269
 
271
270
 
272
271
  def get(self, key: str) -> str | None:
@@ -286,7 +285,7 @@ class DatabaseParametersPragma(DatabaseParameters):
286
285
  sql = f'PRAGMA %s' % key
287
286
 
288
287
  # Execute SQL.
289
- result = self.rdatabase.execute(sql)
288
+ result = self.db.execute(sql)
290
289
  row = result.first()
291
290
  if row is None:
292
291
  variables = None
@@ -320,4 +319,4 @@ class DatabaseParametersPragma(DatabaseParameters):
320
319
  sql = ';\n'.join(sql_set_list)
321
320
 
322
321
  # Execute SQL.
323
- self.rdatabase.execute(sql)
322
+ self.db.execute(sql)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.1.49
3
+ Version: 1.1.50
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -0,0 +1,17 @@
1
+ reydb/__init__.py,sha256=vwShFPkCDpLTrVGCq1AZgKCGQ8tBBodCxrvrib9ptrs,574
2
+ reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
3
+ reydb/rbase.py,sha256=A7or663TcrQyq56P813WsV4BlApZIzXOPdZLsT7KwWw,7040
4
+ reydb/rbuild.py,sha256=8sYuqYR3jKlPfIrCwXk9o-q8cx-VNU0XsIsA6XKIKPo,31850
5
+ reydb/rconfig.py,sha256=4vT0kKVdb9hJjHPQGtmvenPPRbtR1EP2k7jCgfPR0s8,12657
6
+ reydb/rconn.py,sha256=IGRiOkk0TzWj-NQ2o6A1FnMqYnDvg2G1Dd-7cA0dpP0,2765
7
+ reydb/rdb.py,sha256=Ijxja3lb73YmJfzpJBT3bQrqz9rV3TC5w2shQfwj0gQ,12919
8
+ reydb/rerror.py,sha256=TBAzMsf7BrmelhXr5hbqOYVmmRFQtFkyC2SZQx81oYA,9941
9
+ reydb/rexec.py,sha256=xIUbTULfmMkLBYZTPX6lyN5yob-eg6M7Xir1j3jf6PM,29071
10
+ reydb/rfile.py,sha256=k5y3U179NED3gWdyZQ_JRuHmzFTKsZ8aMhxg04ENuHg,15180
11
+ reydb/rinfo.py,sha256=aM3mMFwgT9pemrusS_YjXAVUCJOJ3V709bEWuB-fkuc,12737
12
+ reydb/rorm.py,sha256=ZdXPCeflshlg-ABFpEAI7UFJWdqdBYbbi5yrCAE8Fo8,625
13
+ reydb/rparam.py,sha256=M_tT8nesAResxoDVhk8cmG2N5woYMxXinSGIC2i_8ak,6799
14
+ reydb-1.1.50.dist-info/METADATA,sha256=JtY5fp1zwawCi2KPhLqytLCK_ze6ZxgJ91r5fjIKmmc,1550
15
+ reydb-1.1.50.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ reydb-1.1.50.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
17
+ reydb-1.1.50.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- reydb/__init__.py,sha256=SqjJEBMiUMnKkNfmOvw_jprZcj9Edi0jyBKt67xeYUE,544
2
- reydb/rall.py,sha256=UWnbtl4oG4YqXyqTMN_5uqE-QqD5nb_-dvarotlTUeU,388
3
- reydb/rbase.py,sha256=A7or663TcrQyq56P813WsV4BlApZIzXOPdZLsT7KwWw,7040
4
- reydb/rbuild.py,sha256=GafJ8ocDolj8OsvD9EvMZbR7hKb1WpyQv8LuQO4auKg,32083
5
- reydb/rconfig.py,sha256=h6L1QFtTcLgUcqzsn35lZfChcVBT0eVBzf5NOqzCUmQ,12721
6
- reydb/rconn.py,sha256=IGRiOkk0TzWj-NQ2o6A1FnMqYnDvg2G1Dd-7cA0dpP0,2765
7
- reydb/rdb.py,sha256=E6bFLCKI2f4XXatEsfKDRiZOnT42eYnvsJBV5-OyxQY,12600
8
- reydb/rerror.py,sha256=UcBU_EuiponHhraU2tqULcip-s5uNRnDmEQIA4IgrYc,10067
9
- reydb/rexec.py,sha256=xIUbTULfmMkLBYZTPX6lyN5yob-eg6M7Xir1j3jf6PM,29071
10
- reydb/rfile.py,sha256=OjQQRIZI-vZj0kv9Jljm4_kdp0aL005fAoTl0nAiYAg,15343
11
- reydb/rinfo.py,sha256=WXuN2sJtI7EK83HceLyoVXewILYtPxo9wDJFg7SQoJ8,13508
12
- reydb/rparam.py,sha256=6cnSjNlX54iPS1uxMQdpazPM5XL4J87vVgfL6CIYG3U,7031
13
- reydb-1.1.49.dist-info/METADATA,sha256=7Ae3lNDDvWlwHt4iyfsRzXkF-PlOgoEp7KL7k-U5LSg,1550
14
- reydb-1.1.49.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- reydb-1.1.49.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
16
- reydb-1.1.49.dist-info/RECORD,,
File without changes