nextorm 0.1.0__tar.gz

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.
Files changed (63) hide show
  1. nextorm-0.1.0/LICENSE +179 -0
  2. nextorm-0.1.0/PKG-INFO +166 -0
  3. nextorm-0.1.0/README.md +135 -0
  4. nextorm-0.1.0/nextorm/__init__.py +317 -0
  5. nextorm-0.1.0/nextorm/async_database.py +1285 -0
  6. nextorm-0.1.0/nextorm/collection.py +505 -0
  7. nextorm-0.1.0/nextorm/database.py +1109 -0
  8. nextorm-0.1.0/nextorm/debug.py +167 -0
  9. nextorm-0.1.0/nextorm/entity.py +1146 -0
  10. nextorm-0.1.0/nextorm/exceptions.py +100 -0
  11. nextorm-0.1.0/nextorm/expr.py +139 -0
  12. nextorm-0.1.0/nextorm/fields.py +562 -0
  13. nextorm-0.1.0/nextorm/generators.py +630 -0
  14. nextorm-0.1.0/nextorm/migrations/__init__.py +27 -0
  15. nextorm-0.1.0/nextorm/migrations/cli.py +110 -0
  16. nextorm-0.1.0/nextorm/migrations/core.py +427 -0
  17. nextorm-0.1.0/nextorm/pool.py +258 -0
  18. nextorm-0.1.0/nextorm/providers/__init__.py +67 -0
  19. nextorm-0.1.0/nextorm/providers/base.py +354 -0
  20. nextorm-0.1.0/nextorm/providers/mariadb.py +319 -0
  21. nextorm-0.1.0/nextorm/providers/postgres.py +343 -0
  22. nextorm-0.1.0/nextorm/providers/sqlite.py +313 -0
  23. nextorm-0.1.0/nextorm/py.typed +0 -0
  24. nextorm-0.1.0/nextorm/query.py +1086 -0
  25. nextorm-0.1.0/nextorm/schema/__init__.py +40 -0
  26. nextorm-0.1.0/nextorm/schema/builder.py +369 -0
  27. nextorm-0.1.0/nextorm/schema/core.py +74 -0
  28. nextorm-0.1.0/nextorm/schema/ddl.py +435 -0
  29. nextorm-0.1.0/nextorm/schema/diff.py +176 -0
  30. nextorm-0.1.0/nextorm/schema/introspect.py +269 -0
  31. nextorm-0.1.0/nextorm/session.py +694 -0
  32. nextorm-0.1.0/nextorm/sql/__init__.py +85 -0
  33. nextorm-0.1.0/nextorm/sql/builder.py +428 -0
  34. nextorm-0.1.0/nextorm/sql/nodes.py +428 -0
  35. nextorm-0.1.0/pyproject.toml +187 -0
  36. nextorm-0.1.0/tests/__init__.py +0 -0
  37. nextorm-0.1.0/tests/conftest.py +26 -0
  38. nextorm-0.1.0/tests/providers/__init__.py +0 -0
  39. nextorm-0.1.0/tests/providers/test_mariadb.py +935 -0
  40. nextorm-0.1.0/tests/providers/test_mariadb_unit.py +599 -0
  41. nextorm-0.1.0/tests/providers/test_postgres.py +959 -0
  42. nextorm-0.1.0/tests/providers/test_sqlite.py +705 -0
  43. nextorm-0.1.0/tests/test_async_database.py +1733 -0
  44. nextorm-0.1.0/tests/test_collection.py +734 -0
  45. nextorm-0.1.0/tests/test_composite_pk.py +372 -0
  46. nextorm-0.1.0/tests/test_database.py +1285 -0
  47. nextorm-0.1.0/tests/test_debug.py +492 -0
  48. nextorm-0.1.0/tests/test_descriptors.py +500 -0
  49. nextorm-0.1.0/tests/test_entity.py +1179 -0
  50. nextorm-0.1.0/tests/test_extended_types.py +477 -0
  51. nextorm-0.1.0/tests/test_generators.py +464 -0
  52. nextorm-0.1.0/tests/test_inheritance.py +226 -0
  53. nextorm-0.1.0/tests/test_migrations.py +1016 -0
  54. nextorm-0.1.0/tests/test_optimistic.py +334 -0
  55. nextorm-0.1.0/tests/test_pool.py +262 -0
  56. nextorm-0.1.0/tests/test_prefetch.py +219 -0
  57. nextorm-0.1.0/tests/test_query.py +1643 -0
  58. nextorm-0.1.0/tests/test_schema.py +1719 -0
  59. nextorm-0.1.0/tests/test_session.py +1560 -0
  60. nextorm-0.1.0/tests/test_sql.py +656 -0
  61. nextorm-0.1.0/tests/test_thread_safety.py +70 -0
  62. nextorm-0.1.0/tests/test_uuid_types.py +510 -0
  63. nextorm-0.1.0/tests/test_validation.py +163 -0
nextorm-0.1.0/LICENSE ADDED
@@ -0,0 +1,179 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Henri Hulski
nextorm-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.1
2
+ Name: nextorm
3
+ Version: 0.1.0
4
+ Summary: Modern Python ORM with async support, full type annotations and a generator-expression query DSL
5
+ Keywords: orm,async,database,sqlite,postgresql,mariadb,ponyorm
6
+ Author-Email: Henri Hulski <henri@sancode.it>
7
+ License: Apache-2.0
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Database
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Typing :: Typed
18
+ Project-URL: Homepage, https://github.com/sancode/nextorm
19
+ Project-URL: Repository, https://github.com/sancode/nextorm
20
+ Project-URL: Documentation, https://nextorm.readthedocs.io/en/latest/
21
+ Project-URL: Changelog, https://github.com/sancode/nextorm/blob/main/CHANGELOG.md
22
+ Requires-Python: >=3.12
23
+ Provides-Extra: sqlite
24
+ Requires-Dist: aiosqlite>=0.20; extra == "sqlite"
25
+ Provides-Extra: postgres
26
+ Requires-Dist: psycopg[binary]>=3.2; extra == "postgres"
27
+ Provides-Extra: mariadb
28
+ Requires-Dist: PyMySQL>=1.1; extra == "mariadb"
29
+ Requires-Dist: asyncmy>=0.2; extra == "mariadb"
30
+ Description-Content-Type: text/markdown
31
+
32
+ # NextORM
33
+
34
+ [![CI](https://github.com/sancode/nextorm/actions/workflows/ci.yml/badge.svg)](https://github.com/sancode/nextorm/actions/workflows/ci.yml)
35
+ [![PyPI](https://img.shields.io/pypi/v/nextorm)](https://pypi.org/project/nextorm/)
36
+ [![Python](https://img.shields.io/pypi/pyversions/nextorm)](https://pypi.org/project/nextorm/)
37
+ [![License](https://img.shields.io/pypi/l/nextorm)](LICENSE)
38
+ [![Docs](https://readthedocs.org/projects/nextorm/badge/?version=latest)](https://nextorm.readthedocs.io/en/latest/)
39
+
40
+ Modern Python ORM with async support, full type annotations and a generator-expression query DSL.
41
+
42
+ ## Features
43
+
44
+ - **Type-annotated fields** &mdash; `PK[int]`, `Req[str]`, `Opt[str]`, `Set[T]`, `Single[T]`
45
+ - **Auto-save sessions** &mdash; create entities inside `db_session` and they are committed automatically
46
+ - **PonyORM-compatible DSL** &mdash; generator-expression queries, `Entity[pk]`, `Entity.get()`, lifecycle hooks
47
+ - **Full async support** &mdash; `AsyncDatabase`, `await db.aselect(...)`, `Entity.aselect()`, `Entity.aget()`
48
+ - **Built-in migrations CLI** &mdash; `nextorm makemigrations` / `nextorm migrate`
49
+ - **Three providers** &mdash; SQLite, PostgreSQL (psycopg3), MariaDB
50
+ - **100% branch coverage** enforced in CI
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install nextorm[sqlite] # SQLite (aiosqlite)
56
+ pip install nextorm[postgres] # PostgreSQL (psycopg3)
57
+ pip install nextorm[mariadb] # MariaDB (asyncmy + PyMySQL)
58
+ pip install "nextorm[sqlite,postgres,mariadb]" # all drivers
59
+ ```
60
+
61
+ ## Quick start
62
+
63
+ ```python
64
+ from nextorm import Database, Entity, PK, Req, Opt, Set, Single, db_session
65
+
66
+ # Define entities — no database coupling required
67
+ class Tag(Entity):
68
+ name: Req[str]
69
+
70
+ class Product(Entity):
71
+ name: Req[str]
72
+ price: Req[float]
73
+ tags: Set[Tag] # many-to-many
74
+
75
+ # Create and connect the database
76
+ db = Database(entities=[Tag, Product])
77
+ db.bind("sqlite", ":memory:")
78
+ db.generate_mapping(create_tables=True)
79
+
80
+ # Write — entities are tracked and committed automatically
81
+ with db_session:
82
+ t = Tag(name="sale")
83
+ p = Product(name="Widget", price=9.99)
84
+ p.tags.add(t)
85
+ # ← INSERT fires here; p.id and t.id are now set
86
+
87
+ # Read — class-level shortcuts (no explicit db reference needed)
88
+ widgets = Product.select().filter(Product.price < 20).fetch_all()
89
+ widget = Product.get(name="Widget") # None if not found
90
+ widget = Product[1] # KeyError if not found
91
+ ```
92
+
93
+ ## Async quick start
94
+
95
+ ```python
96
+ import asyncio
97
+ from nextorm import AsyncDatabase, Entity, PK, Req, db_session
98
+
99
+ class Task(Entity):
100
+ title: Req[str]
101
+ done: Req[bool]
102
+
103
+ async def main() -> None:
104
+ db = AsyncDatabase(entities=[Task])
105
+ await db.bind("sqlite", ":memory:")
106
+ await db.generate_mapping(create_tables=True)
107
+
108
+ async with db_session:
109
+ Task(title="Buy milk", done=False)
110
+
111
+ pending = await Task.aselect().filter(Task.done == False).fetch_all()
112
+ task = await Task.aget(title="Buy milk") # None if not found
113
+ print(pending)
114
+
115
+ asyncio.run(main())
116
+ ```
117
+
118
+ ## Migrations
119
+
120
+ ```bash
121
+ nextorm makemigrations # generate a migration from model changes
122
+ nextorm migrate # apply pending migrations
123
+ nextorm showmigrations # list migration history
124
+ ```
125
+
126
+ ## Migrating from PonyORM
127
+
128
+ NextORM's API is intentionally close to PonyORM's. The main differences:
129
+
130
+ | PonyORM | NextORM |
131
+ |---|---|
132
+ | `class Product(db.Entity)` | `class Product(Entity)` |
133
+ | `Required(str)` | `Req[str]` |
134
+ | `Optional(str)` | `Opt[str]` |
135
+ | `PrimaryKey(int, auto=True)` | `PK[int]` |
136
+ | `Required(Order)` (FK side) | `Single[Order]` |
137
+ | `Set("Line")` (back-reference) | `Set["Line"]` |
138
+ | `select(p for p in Product if ...)` | identical |
139
+ | `Product[42]` | identical |
140
+ | `Product.get(name="x")` | identical |
141
+ | `db.save(p)` required | auto-committed in `db_session` |
142
+
143
+ See the [migration guide](https://nextorm.readthedocs.io/en/latest/ponyorm.html) for details.
144
+
145
+ ## Documentation
146
+
147
+ Full docs at **[nextorm.readthedocs.io](https://nextorm.readthedocs.io/en/latest/)**.
148
+
149
+ ## Development
150
+
151
+ ```bash
152
+ pdm install
153
+ pdm test # run tests
154
+ pdm coverage # tests + branch coverage (must be 100%)
155
+ pdm typecheck # pyright + mypy
156
+ pdm lint # ruff
157
+ pdm format # ruff format
158
+ pdm docs-html # build Sphinx docs
159
+ ```
160
+
161
+ ## Acknowledgements
162
+
163
+ NextORM's API design and query DSL are heavily inspired by
164
+ [PonyORM](https://ponyorm.org), created by Alexander Kozlovsky, Alexey Malashkevich,
165
+ and Alexander Tischenko, released under the Apache License 2.0.
166
+ NextORM is a new, independent implementation and shares no source code with PonyORM.
@@ -0,0 +1,135 @@
1
+ # NextORM
2
+
3
+ [![CI](https://github.com/sancode/nextorm/actions/workflows/ci.yml/badge.svg)](https://github.com/sancode/nextorm/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/nextorm)](https://pypi.org/project/nextorm/)
5
+ [![Python](https://img.shields.io/pypi/pyversions/nextorm)](https://pypi.org/project/nextorm/)
6
+ [![License](https://img.shields.io/pypi/l/nextorm)](LICENSE)
7
+ [![Docs](https://readthedocs.org/projects/nextorm/badge/?version=latest)](https://nextorm.readthedocs.io/en/latest/)
8
+
9
+ Modern Python ORM with async support, full type annotations and a generator-expression query DSL.
10
+
11
+ ## Features
12
+
13
+ - **Type-annotated fields** &mdash; `PK[int]`, `Req[str]`, `Opt[str]`, `Set[T]`, `Single[T]`
14
+ - **Auto-save sessions** &mdash; create entities inside `db_session` and they are committed automatically
15
+ - **PonyORM-compatible DSL** &mdash; generator-expression queries, `Entity[pk]`, `Entity.get()`, lifecycle hooks
16
+ - **Full async support** &mdash; `AsyncDatabase`, `await db.aselect(...)`, `Entity.aselect()`, `Entity.aget()`
17
+ - **Built-in migrations CLI** &mdash; `nextorm makemigrations` / `nextorm migrate`
18
+ - **Three providers** &mdash; SQLite, PostgreSQL (psycopg3), MariaDB
19
+ - **100% branch coverage** enforced in CI
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install nextorm[sqlite] # SQLite (aiosqlite)
25
+ pip install nextorm[postgres] # PostgreSQL (psycopg3)
26
+ pip install nextorm[mariadb] # MariaDB (asyncmy + PyMySQL)
27
+ pip install "nextorm[sqlite,postgres,mariadb]" # all drivers
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ ```python
33
+ from nextorm import Database, Entity, PK, Req, Opt, Set, Single, db_session
34
+
35
+ # Define entities — no database coupling required
36
+ class Tag(Entity):
37
+ name: Req[str]
38
+
39
+ class Product(Entity):
40
+ name: Req[str]
41
+ price: Req[float]
42
+ tags: Set[Tag] # many-to-many
43
+
44
+ # Create and connect the database
45
+ db = Database(entities=[Tag, Product])
46
+ db.bind("sqlite", ":memory:")
47
+ db.generate_mapping(create_tables=True)
48
+
49
+ # Write — entities are tracked and committed automatically
50
+ with db_session:
51
+ t = Tag(name="sale")
52
+ p = Product(name="Widget", price=9.99)
53
+ p.tags.add(t)
54
+ # ← INSERT fires here; p.id and t.id are now set
55
+
56
+ # Read — class-level shortcuts (no explicit db reference needed)
57
+ widgets = Product.select().filter(Product.price < 20).fetch_all()
58
+ widget = Product.get(name="Widget") # None if not found
59
+ widget = Product[1] # KeyError if not found
60
+ ```
61
+
62
+ ## Async quick start
63
+
64
+ ```python
65
+ import asyncio
66
+ from nextorm import AsyncDatabase, Entity, PK, Req, db_session
67
+
68
+ class Task(Entity):
69
+ title: Req[str]
70
+ done: Req[bool]
71
+
72
+ async def main() -> None:
73
+ db = AsyncDatabase(entities=[Task])
74
+ await db.bind("sqlite", ":memory:")
75
+ await db.generate_mapping(create_tables=True)
76
+
77
+ async with db_session:
78
+ Task(title="Buy milk", done=False)
79
+
80
+ pending = await Task.aselect().filter(Task.done == False).fetch_all()
81
+ task = await Task.aget(title="Buy milk") # None if not found
82
+ print(pending)
83
+
84
+ asyncio.run(main())
85
+ ```
86
+
87
+ ## Migrations
88
+
89
+ ```bash
90
+ nextorm makemigrations # generate a migration from model changes
91
+ nextorm migrate # apply pending migrations
92
+ nextorm showmigrations # list migration history
93
+ ```
94
+
95
+ ## Migrating from PonyORM
96
+
97
+ NextORM's API is intentionally close to PonyORM's. The main differences:
98
+
99
+ | PonyORM | NextORM |
100
+ |---|---|
101
+ | `class Product(db.Entity)` | `class Product(Entity)` |
102
+ | `Required(str)` | `Req[str]` |
103
+ | `Optional(str)` | `Opt[str]` |
104
+ | `PrimaryKey(int, auto=True)` | `PK[int]` |
105
+ | `Required(Order)` (FK side) | `Single[Order]` |
106
+ | `Set("Line")` (back-reference) | `Set["Line"]` |
107
+ | `select(p for p in Product if ...)` | identical |
108
+ | `Product[42]` | identical |
109
+ | `Product.get(name="x")` | identical |
110
+ | `db.save(p)` required | auto-committed in `db_session` |
111
+
112
+ See the [migration guide](https://nextorm.readthedocs.io/en/latest/ponyorm.html) for details.
113
+
114
+ ## Documentation
115
+
116
+ Full docs at **[nextorm.readthedocs.io](https://nextorm.readthedocs.io/en/latest/)**.
117
+
118
+ ## Development
119
+
120
+ ```bash
121
+ pdm install
122
+ pdm test # run tests
123
+ pdm coverage # tests + branch coverage (must be 100%)
124
+ pdm typecheck # pyright + mypy
125
+ pdm lint # ruff
126
+ pdm format # ruff format
127
+ pdm docs-html # build Sphinx docs
128
+ ```
129
+
130
+ ## Acknowledgements
131
+
132
+ NextORM's API design and query DSL are heavily inspired by
133
+ [PonyORM](https://ponyorm.org), created by Alexander Kozlovsky, Alexey Malashkevich,
134
+ and Alexander Tischenko, released under the Apache License 2.0.
135
+ NextORM is a new, independent implementation and shares no source code with PonyORM.