TypeDAL 3.5.0__py3-none-any.whl → 3.7.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.

Potentially problematic release.


This version of TypeDAL might be problematic. Click here for more details.

typedal/__about__.py CHANGED
@@ -5,4 +5,4 @@ This file contains the Version info for this package.
5
5
  # SPDX-FileCopyrightText: 2023-present Robin van der Noord <robinvandernoord@gmail.com>
6
6
  #
7
7
  # SPDX-License-Identifier: MIT
8
- __version__ = "3.5.0"
8
+ __version__ = "3.7.0"
typedal/cli.py CHANGED
@@ -40,7 +40,7 @@ from pydal2sql.types import (
40
40
  OutputFormat_Option,
41
41
  Tables_Option,
42
42
  )
43
- from pydal2sql_core import core_alter, core_create
43
+ from pydal2sql_core import core_alter, core_create, core_stub
44
44
  from typing_extensions import Never
45
45
 
46
46
  from . import caching
@@ -417,6 +417,38 @@ def fake_migrations(
417
417
  return 0
418
418
 
419
419
 
420
+ @app.command(name="migrations.stub")
421
+ @with_exit_code(hide_tb=IS_DEBUG)
422
+ def migrations_stub(
423
+ migration_name: typing.Annotated[str, typer.Argument()] = "stub_migration",
424
+ connection: typing.Annotated[str, typer.Option("--connection", "-c")] = None,
425
+ output_format: OutputFormat_Option = None,
426
+ output_file: Optional[str] = None,
427
+ dry_run: typing.Annotated[bool, typer.Option("--dry", "--dry-run")] = False,
428
+ is_pydal: typing.Annotated[bool, typer.Option("--pydal", "-p")] = False,
429
+ # defaults to is_typedal of course
430
+ ) -> int:
431
+ """
432
+ Create an empty migration via pydal2sql.
433
+ """
434
+ generic_config = load_config(connection)
435
+ pydal2sql_config = generic_config.to_pydal2sql()
436
+ pydal2sql_config.update(
437
+ format=output_format,
438
+ output=output_file,
439
+ _skip_none=True,
440
+ )
441
+
442
+ core_stub(
443
+ migration_name, # raw, without date or number
444
+ output_format=pydal2sql_config.format,
445
+ output_file=pydal2sql_config.output or None,
446
+ dry_run=dry_run,
447
+ is_typedal=not is_pydal,
448
+ )
449
+ return 0
450
+
451
+
420
452
  AnyNestedDict: typing.TypeAlias = dict[str, AnyDict]
421
453
 
422
454
 
typedal/helpers.py CHANGED
@@ -10,7 +10,12 @@ import typing
10
10
  from collections import ChainMap
11
11
  from typing import Any
12
12
 
13
- from .types import AnyDict
13
+ from pydal import DAL
14
+
15
+ from .types import AnyDict, Field, Table
16
+
17
+ if typing.TYPE_CHECKING:
18
+ from . import TypeDAL, TypedField, TypedTable # noqa: F401
14
19
 
15
20
  T = typing.TypeVar("T")
16
21
 
@@ -274,3 +279,27 @@ def utcnow() -> dt.datetime:
274
279
  """
275
280
  # return dt.datetime.now(dt.UTC)
276
281
  return dt.datetime.now(dt.timezone.utc)
282
+
283
+
284
+ def get_db(table: "TypedTable | Table") -> "DAL":
285
+ """
286
+ Get the underlying DAL instance for a pydal or typedal table.
287
+ """
288
+ return typing.cast("DAL", table._db)
289
+
290
+
291
+ def get_table(table: "TypedTable | Table") -> "Table":
292
+ """
293
+ Get the underlying pydal table for a typedal table.
294
+ """
295
+ return typing.cast("Table", table._table)
296
+
297
+
298
+ def get_field(field: "TypedField[typing.Any] | Field") -> "Field":
299
+ """
300
+ Get the underlying pydal field from a typedal field.
301
+ """
302
+ return typing.cast(
303
+ "Field",
304
+ field, # Table.field already is a Field, but cast to make sure the editor knows this too.
305
+ )
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: TypeDAL
3
- Version: 3.5.0
3
+ Version: 3.7.0
4
4
  Summary: Typing support for PyDAL
5
5
  Project-URL: Documentation, https://typedal.readthedocs.io/
6
6
  Project-URL: Issues, https://github.com/trialandsuccess/TypeDAL/issues
@@ -23,7 +23,7 @@ Requires-Dist: python-slugify
23
23
  Provides-Extra: all
24
24
  Requires-Dist: edwh-migrate>=0.8.0; extra == 'all'
25
25
  Requires-Dist: py4web; extra == 'all'
26
- Requires-Dist: pydal2sql[all]>=1.1.4; extra == 'all'
26
+ Requires-Dist: pydal2sql[all]>=1.2.0; extra == 'all'
27
27
  Requires-Dist: questionary; extra == 'all'
28
28
  Requires-Dist: tabulate; extra == 'all'
29
29
  Requires-Dist: tomlkit; extra == 'all'
@@ -43,7 +43,7 @@ Requires-Dist: types-requests; extra == 'dev'
43
43
  Requires-Dist: types-tabulate; extra == 'dev'
44
44
  Provides-Extra: migrations
45
45
  Requires-Dist: edwh-migrate>=0.8.0; extra == 'migrations'
46
- Requires-Dist: pydal2sql>=1.1.4; extra == 'migrations'
46
+ Requires-Dist: pydal2sql>=1.2.0; extra == 'migrations'
47
47
  Requires-Dist: questionary; extra == 'migrations'
48
48
  Requires-Dist: tabulate; extra == 'migrations'
49
49
  Requires-Dist: tomlkit; extra == 'migrations'
@@ -301,6 +301,28 @@ row: TableName = db.table_name(id=1)
301
301
 
302
302
  See [2. Defining Tables](https://typedal.readthedocs.io/en/stable/2_defining_tables/)
303
303
 
304
+ ### Helpers
305
+
306
+ TypeDAL provides some utility functions to interact with the underlying pyDAL objects:
307
+
308
+ - **`get_db(TableName)`**:
309
+ Retrieve the DAL instance associated with a given TypedTable or pyDAL Table.
310
+
311
+ - **`get_table(TableName)`**:
312
+ Access the original PyDAL Table from a TypedTable instance (`db.table_name`).
313
+
314
+ - **`get_field(TableName.fieldname)`**:
315
+ Get the pyDAL Field from a TypedField. This ensures compatibility when interacting directly with PyDAL.
316
+
317
+ These helpers are useful for scenarios where direct access to the PyDAL objects is needed while still using TypeDAL.
318
+ An example of this is when you need to do a `db.commit()` but you can't import `db` directly:
319
+
320
+ ```python
321
+ MyTable.insert(...)
322
+ db = get_db(MyTable)
323
+ db.commit() # this is usually done automatically but sometimes you want to manually commit.
324
+ ```
325
+
304
326
  ## Caveats
305
327
 
306
328
  - This package depends heavily on the current implementation of annotations (which are computed when the class is
@@ -1,19 +1,19 @@
1
- typedal/__about__.py,sha256=AjgocyPCjgkgwSg0cozJLLzDEJz3aZN-Ze0xcPDV5pc,206
1
+ typedal/__about__.py,sha256=oird-nTofiqIzNTKZCjENhO8ePCfLiFklOCRjlW0gog,206
2
2
  typedal/__init__.py,sha256=QQpLiVl9w9hm2LBxey49Y_tCF_VB2bScVaS_mCjYy54,366
3
3
  typedal/caching.py,sha256=SMcJsahLlZ79yykWCveERFx1ZJUNEKhA9SPmCTIuLp8,11798
4
- typedal/cli.py,sha256=n2TKQGOryck91ByFEcLqwPgh6_kMtoBr3UBIDwU_8n8,18180
4
+ typedal/cli.py,sha256=wzyId6YwRyqfuJ2byxvl6YecDNaKpkLmo-R5HvRuTok,19265
5
5
  typedal/config.py,sha256=0qy1zrTUdtmXPM9jHzFnSR1DJsqGJqcdG6pvhzKQHe0,11625
6
6
  typedal/core.py,sha256=mbNFMv3NJ2QRDuohs03LCGhVVnffsxjsoe-m887U6c8,98367
7
7
  typedal/fields.py,sha256=z2PD9vLWqBR_zXtiY0DthqTG4AeF3yxKoeuVfGXnSdg,5197
8
8
  typedal/for_py4web.py,sha256=d07b8hL_PvNDUS26Z5fDH2OxWb-IETBuAFPSzrRwm04,1285
9
9
  typedal/for_web2py.py,sha256=4RHgzGXgKIO_BYB-7adC5e35u52rX-p1t4tPEz-NK24,1867
10
- typedal/helpers.py,sha256=KbgP4ZRW7KCroyHwTwdErPqylOX4dsqVnKJeZ5TtTFY,7363
10
+ typedal/helpers.py,sha256=uej96exzJ9qVBd6LudP8uJ_7Cmq6vKraerdKvSRBVjc,8128
11
11
  typedal/mixins.py,sha256=OHhVYLBGTzPSJKgp1uovBs1Y6NJa0d-DxHTOk9LyOXA,5414
12
12
  typedal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  typedal/types.py,sha256=W2zsmJSPYbIvhjb5Df_ZANH8riCIJhOOHjI8UCQINls,5239
14
14
  typedal/web2py_py4web_shared.py,sha256=VK9T8P5UwVLvfNBsY4q79ANcABv-jX76YKADt1Zz_co,1539
15
15
  typedal/serializers/as_json.py,sha256=ffo152W-sARYXym4BzwX709rrO2-QwKk2KunWY8RNl4,2229
16
- typedal-3.5.0.dist-info/METADATA,sha256=pffl-arVDPP0CBg3EcVhlze5mxypyCH-Ds_iZ6sZY6s,9462
17
- typedal-3.5.0.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
18
- typedal-3.5.0.dist-info/entry_points.txt,sha256=m1wqcc_10rHWPdlQ71zEkmJDADUAnZtn7Jac_6mbyUc,44
19
- typedal-3.5.0.dist-info/RECORD,,
16
+ typedal-3.7.0.dist-info/METADATA,sha256=10vZGqAXqubFW6l0W6Vl0A7qsoR8PLmMyftmZ8Kk0oY,10294
17
+ typedal-3.7.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
18
+ typedal-3.7.0.dist-info/entry_points.txt,sha256=m1wqcc_10rHWPdlQ71zEkmJDADUAnZtn7Jac_6mbyUc,44
19
+ typedal-3.7.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.17.1
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any