reydb 1.1.61__py3-none-any.whl → 1.2.1__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/rorm.py CHANGED
@@ -17,7 +17,8 @@ from pydantic import ConfigDict, field_validator as pydantic_field_validator, mo
17
17
  from sqlalchemy import text as sqlalchemy_text
18
18
  from sqlalchemy.orm import SessionTransaction
19
19
  from sqlalchemy.ext.asyncio import AsyncSessionTransaction
20
- from sqlalchemy.sql import sqltypes
20
+ from sqlalchemy import types
21
+ from sqlalchemy.dialects.mysql import types as types_mysql
21
22
  from sqlalchemy.sql.sqltypes import TypeEngine
22
23
  from sqlalchemy.sql.dml import Insert, Update, Delete
23
24
  from sqlmodel import SQLModel, Session, Table
@@ -37,8 +38,9 @@ from .rbase import (
37
38
  __all__ = (
38
39
  'DatabaseORMBase',
39
40
  'DatabaseORMModelMeta',
40
- 'DatabaseORMModel',
41
41
  'DatabaseORMModelField',
42
+ 'DatabaseORMModel',
43
+ 'DatabaseORMModelMethod',
42
44
  'DatabaseORMSuper',
43
45
  'DatabaseORM',
44
46
  'DatabaseORMAsync',
@@ -111,7 +113,7 @@ class DatabaseORMModelMeta(DatabaseORMBase, SQLModelMetaclass):
111
113
 
112
114
  ## Name.
113
115
  if '__name__' in attrs:
114
- name = attrs.pop('__name__')
116
+ attrs['__tablename__'] = attrs.pop('__name__')
115
117
 
116
118
  ## Comment.
117
119
  if '__comment__' in attrs:
@@ -131,108 +133,6 @@ class DatabaseORMModelMeta(DatabaseORMBase, SQLModelMetaclass):
131
133
  return new_cls
132
134
 
133
135
 
134
- model_metaclass: SQLModelMetaclass = DatabaseORMModelMeta
135
-
136
-
137
- class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
138
- """
139
- Database ORM model type.
140
-
141
- Examples
142
- --------
143
- >>> class Foo(DatabaseORMModel, table=True):
144
- ... __comment__ = 'Table comment.'
145
- ... ...
146
- """
147
-
148
-
149
- def update(self, data: 'DatabaseORMModel | dict[dict, Any]') -> None:
150
- """
151
- Update attributes.
152
-
153
- Parameters
154
- ----------
155
- data : `DatabaseORMModel` or `dict`.
156
- """
157
-
158
- # Update.
159
- self.sqlmodel_update(data)
160
-
161
-
162
- def validate(self) -> Self:
163
- """
164
- Validate all attributes, and copy self instance to new instance.
165
- """
166
-
167
- # Validate.
168
- model = self.model_validate(self)
169
-
170
- return model
171
-
172
-
173
- def copy(self) -> Self:
174
- """
175
- Copy self instance to new instance.
176
-
177
- Returns
178
- -------
179
- New instance.
180
- """
181
-
182
- # Copy.
183
- data = self.data
184
- instance = self.__class__(**data)
185
-
186
- return instance
187
-
188
-
189
- @property
190
- def data(self) -> dict[str, Any]:
191
- """
192
- All attributes data.
193
-
194
- Returns
195
- -------
196
- data.
197
- """
198
-
199
- # Get.
200
- data = self.model_dump()
201
-
202
- return data
203
-
204
-
205
- @classmethod
206
- def table(cls_or_self) -> Table | None:
207
- """
208
- Mapping `Table` instance.
209
-
210
- Returns
211
- -------
212
- Instance or null.
213
- """
214
-
215
- # Get.
216
- table: Table | None = getattr(cls_or_self, '__table__', None)
217
-
218
- return table
219
-
220
-
221
- @classmethod
222
- def comment(cls_or_self, comment: str) -> None:
223
- """
224
- Set table comment.
225
-
226
- Parameters
227
- ----------
228
- comment : Comment.
229
- """
230
-
231
- # Set.
232
- table = cls_or_self.table()
233
- table.comment = comment
234
-
235
-
236
136
  class DatabaseORMModelField(DatabaseORMBase, FieldInfo):
237
137
  """
238
138
  Database ORM model filed type.
@@ -289,7 +189,7 @@ class DatabaseORMModelField(DatabaseORMBase, FieldInfo):
289
189
  field_default : Database field defualt value.
290
190
  - `Literal['current_timestamp']`: Set SQL syntax 'current_timestamp', case insensitive.
291
191
  - `Literal['on update current_timestamp']`: Set SQL syntax 'on update current_timestamp', case insensitive.
292
- filed_name : Database field name.
192
+ field_name : Database field name.
293
193
  - `None`: Same as attribute name.
294
194
  field_type : Database field type.
295
195
  - `None`: Based type annotation automatic judgment.
@@ -366,12 +266,12 @@ class DatabaseORMModelField(DatabaseORMBase, FieldInfo):
366
266
  kwargs['sa_column_kwargs']['server_default'] = field_default
367
267
 
368
268
  ## Field name.
369
- if 'filed_name' in kwargs:
370
- kwargs['sa_column_kwargs']['name'] = kwargs.pop('filed_name')
269
+ if 'field_name' in kwargs:
270
+ kwargs['sa_column_kwargs']['name'] = kwargs.pop('field_name')
371
271
 
372
272
  ## Field type.
373
- if 'filed_name' in kwargs:
374
- kwargs['sa_column_kwargs']['type_'] = kwargs.pop('filed_type')
273
+ if 'field_type' in kwargs:
274
+ kwargs['sa_type'] = kwargs.pop('field_type')
375
275
 
376
276
  ## Key auto.
377
277
  if 'key_auto' in kwargs:
@@ -393,6 +293,129 @@ class DatabaseORMModelField(DatabaseORMBase, FieldInfo):
393
293
  super().__init__(**kwargs)
394
294
 
395
295
 
296
+ model_metaclass: SQLModelMetaclass = DatabaseORMModelMeta
297
+
298
+
299
+ class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
300
+ """
301
+ Database ORM model type.
302
+
303
+ Examples
304
+ --------
305
+ >>> class Foo(DatabaseORMModel, table=True):
306
+ ... __name__ = 'Table name, default is class name.'
307
+ ... __comment__ = 'Table comment.'
308
+ ... ...
309
+ """
310
+
311
+
312
+ @classmethod
313
+ def _table(cls_or_self) -> Table:
314
+ """
315
+ Return mapping database table instance.
316
+
317
+ Returns
318
+ -------
319
+ Table instance.
320
+ """
321
+
322
+ # Get.
323
+ table: Table = cls_or_self.__table__
324
+
325
+ return table
326
+
327
+
328
+ @property
329
+ def _m(self):
330
+ """
331
+ Build database ORM model method instance.
332
+
333
+ Returns
334
+ -------
335
+ Instance.
336
+ """
337
+
338
+ # Build.
339
+ method = DatabaseORMModelMethod(self)
340
+
341
+ return method
342
+
343
+
344
+ class DatabaseORMModelMethod(DatabaseORMBase):
345
+ """
346
+ Database ORM model method type.
347
+ """
348
+
349
+
350
+ def __init__(self, model: DatabaseORMModel) -> None:
351
+ """
352
+ Build instance attributes.
353
+
354
+ Parameters
355
+ ----------
356
+ model : Database ORM model instance.
357
+ """
358
+
359
+ # Build.
360
+ self.model = model
361
+
362
+
363
+ @property
364
+ def data(self) -> dict[str, Any]:
365
+ """
366
+ All attributes data.
367
+
368
+ Returns
369
+ -------
370
+ data.
371
+ """
372
+
373
+ # Get.
374
+ data = self.model.model_dump()
375
+
376
+ return data
377
+
378
+
379
+ def update(self, data: 'DatabaseORMModel | dict[dict, Any]') -> None:
380
+ """
381
+ Update attributes.
382
+
383
+ Parameters
384
+ ----------
385
+ data : `DatabaseORMModel` or `dict`.
386
+ """
387
+
388
+ # Update.
389
+ self.model.sqlmodel_update(data)
390
+
391
+
392
+ def validate(self) -> Self:
393
+ """
394
+ Validate all attributes, and copy self instance to new instance.
395
+ """
396
+
397
+ # Validate.
398
+ model = self.model.model_validate(self.model)
399
+
400
+ return model
401
+
402
+
403
+ def copy(self) -> Self:
404
+ """
405
+ Copy self instance to new instance.
406
+
407
+ Returns
408
+ -------
409
+ New instance.
410
+ """
411
+
412
+ # Copy.
413
+ data = self.data
414
+ instance = self.model.__class__(**data)
415
+
416
+ return instance
417
+
418
+
396
419
  class DatabaseORMSuper(DatabaseORMBase, Generic[DatabaseT, DatabaseORMSessionT]):
397
420
  """
398
421
  Database ORM super type.
@@ -412,7 +435,8 @@ class DatabaseORMSuper(DatabaseORMBase, Generic[DatabaseT, DatabaseORMSessionT])
412
435
  Model = DatabaseORMModel
413
436
  Field = DatabaseORMModelField
414
437
  Config = ConfigDict
415
- types = sqltypes
438
+ types = types
439
+ types_mysql = types_mysql
416
440
  wrap_validate_model = pydantic_model_validator
417
441
  wrap_validate_filed = pydantic_field_validator
418
442
 
@@ -819,7 +843,7 @@ class DatabaseORMSession(
819
843
 
820
844
  # Handle parameter.
821
845
  tables = [
822
- model.table()
846
+ model._table()
823
847
  for model in models
824
848
  ]
825
849
 
@@ -848,7 +872,7 @@ class DatabaseORMSession(
848
872
 
849
873
  # Handle parameter.
850
874
  tables = [
851
- model.table()
875
+ model._table()
852
876
  for model in models
853
877
  ]
854
878
 
@@ -1185,7 +1209,7 @@ class DatabaseORMSessionAsync(
1185
1209
 
1186
1210
  # Handle parameter.
1187
1211
  tables = [
1188
- model.table()
1212
+ model._table()
1189
1213
  for model in models
1190
1214
  ]
1191
1215
 
@@ -1215,7 +1239,7 @@ class DatabaseORMSessionAsync(
1215
1239
 
1216
1240
  # Handle parameter.
1217
1241
  tables = [
1218
- model.table()
1242
+ model._table()
1219
1243
  for model in models
1220
1244
  ]
1221
1245
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.1.61
3
+ Version: 1.2.1
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,15 @@
1
+ reydb/__init__.py,sha256=4mnlkfJfkBfxBpCotVUJ86f4AnT8plqlFbGiH3vZ4PM,550
2
+ reydb/rall.py,sha256=IxSPGh77xz7ndDC7J8kZ_66Gq_xTAztGtnELUku1Ouw,364
3
+ reydb/rbase.py,sha256=0QGHxbdrcyDTY6BK7zMCTM9cRDkZyVNlL7S1j7A4Zp0,8260
4
+ reydb/rbuild.py,sha256=R_WQNpp67oHZFZlRuui_vaZAlJL4s_y5NX0gJXZY1yA,40320
5
+ reydb/rconfig.py,sha256=nZY2c6KTKWJuHXim1zEcPrIkMgqhiKb_lQQpVc-fpw8,19033
6
+ reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
+ reydb/rdb.py,sha256=_K8_6_D7ptU8vrmPtijAeH8xCechwBXtCAusziyhxbU,14370
8
+ reydb/rerror.py,sha256=oTICXpVVtkH-u1N8pHs0f4krb1jbNU_FmcFCEHoO4yo,14852
9
+ reydb/rexec.py,sha256=XOx8JH4ApzCjXOuMplVQZQ5MCtf6UJXKGq98t-WRoFo,53102
10
+ reydb/rinfo.py,sha256=yeIZ9VmqBZtCM1Upzntal2aP7GtO0g4YsDW5LLMNOcg,18180
11
+ reydb/rorm.py,sha256=IipUvaFnS0gfHxzYkNSuM60skYsIGNBA9DvD8DnTpCc,40885
12
+ reydb-1.2.1.dist-info/METADATA,sha256=NFcX8OYkzXkDwi_NyV1uzNIqtA0kOHO-EITgjyAzJp8,1621
13
+ reydb-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ reydb-1.2.1.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
+ reydb-1.2.1.dist-info/RECORD,,