DB-First 1.0.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.
db_first-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Konstantin Fadeev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ recursive-include src/db_first *
2
+ graft examples
3
+ graft tests
4
+ global-exclude *.pyc
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.1
2
+ Name: DB-First
3
+ Version: 1.0.0
4
+ Summary: CRUD tools for working with database via SQLAlchemy.
5
+ Author-email: Konstantin Fadeev <fadeev@legalact.pro>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Konstantin Fadeev
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: changelog, https://github.com/flask-pro/db_first/blob/master/CHANGES.md
29
+ Project-URL: repository, https://github.com/flask-pro/db_first
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: Implementation :: CPython
36
+ Classifier: Topic :: Database
37
+ Classifier: Topic :: Software Development :: Libraries
38
+ Requires-Python: >=3.9
39
+ Description-Content-Type: text/markdown
40
+ License-File: LICENSE
41
+ Requires-Dist: SQLAlchemy>=2.0.9
42
+ Requires-Dist: marshmallow>=3.14.1
43
+ Provides-Extra: dev
44
+ Requires-Dist: build==1.2.2; extra == "dev"
45
+ Requires-Dist: pre-commit==3.8.0; extra == "dev"
46
+ Requires-Dist: pytest==8.3.3; extra == "dev"
47
+ Requires-Dist: pytest-cov==5.0.0; extra == "dev"
48
+ Requires-Dist: python-dotenv==1.0.1; extra == "dev"
49
+ Requires-Dist: tox==4.21.2; extra == "dev"
50
+ Requires-Dist: twine==5.1.1; extra == "dev"
51
+
52
+ # DB-First
53
+
54
+ CRUD tools for working with database via SQLAlchemy.
55
+
56
+ <!--TOC-->
57
+
58
+ - [DB-First](#db-first)
59
+ - [Features](#features)
60
+ - [Installation](#installation)
61
+ - [Example](#example)
62
+
63
+ <!--TOC-->
64
+
65
+ ## Features
66
+
67
+ * CreateMixin, ReadMixin, UpdateMixin, DeleteMixin for CRUD operation for database.
68
+ * PaginateMixin for get paginated data from database.
69
+ * QueryMaker class for create query 'per-one-model'.
70
+ * Marshmallow (https://github.com/marshmallow-code/marshmallow) schemas for validating input data.
71
+ * Marshmallow schemas for deserialization SQLAlchemy result object to `dict`.
72
+
73
+ ## Installation
74
+
75
+ Recommended using the latest version of Python. DB-First supports Python 3.9 and newer.
76
+
77
+ Install and update using `pip`:
78
+
79
+ ```shell
80
+ $ pip install -U db_first
81
+ ```
82
+
83
+ ## Example
84
+
85
+ File with application initialization `main.py`:
86
+
87
+ ```python
88
+ from uuid import UUID
89
+
90
+ from db_first import BaseCRUD
91
+ from db_first.base_model import ModelMixin
92
+ from db_first.mixins import CreateMixin
93
+ from db_first.mixins import DeleteMixin
94
+ from db_first.mixins import PaginationMixin
95
+ from db_first.mixins import ReadMixin
96
+ from db_first.mixins import UpdateMixin
97
+ from marshmallow import fields
98
+ from marshmallow import Schema
99
+ from sqlalchemy import create_engine
100
+ from sqlalchemy.orm import declarative_base
101
+ from sqlalchemy.orm import Mapped
102
+ from sqlalchemy.orm import mapped_column
103
+ from sqlalchemy.orm import Session
104
+
105
+ engine = create_engine('sqlite://', echo=True, future=True)
106
+ session = Session(engine)
107
+ Base = declarative_base()
108
+
109
+
110
+ class Items(ModelMixin, Base):
111
+ __tablename__ = 'items'
112
+ data: Mapped[str] = mapped_column(comment='Data of item.')
113
+
114
+
115
+ Base.metadata.create_all(engine)
116
+
117
+
118
+ class InputSchemaOfCreate(Schema):
119
+ data = fields.String()
120
+
121
+
122
+ class InputSchemaOfUpdate(InputSchemaOfCreate):
123
+ id = fields.UUID()
124
+
125
+
126
+ class OutputSchema(InputSchemaOfUpdate):
127
+ created_at = fields.DateTime()
128
+
129
+
130
+ class ItemController(CreateMixin, ReadMixin, UpdateMixin, DeleteMixin, PaginationMixin, BaseCRUD):
131
+ class Meta:
132
+ session = session
133
+ model = Items
134
+ input_schema_of_create = InputSchemaOfCreate
135
+ input_schema_of_update = InputSchemaOfUpdate
136
+ output_schema_of_create = OutputSchema
137
+ output_schema_of_read = OutputSchema
138
+ output_schema_of_update = OutputSchema
139
+ output_schema_of_paginate = OutputSchema
140
+ sortable = ['created_at']
141
+
142
+
143
+ if __name__ == '__main__':
144
+ item = ItemController()
145
+
146
+ first_new_item = item.create(data={'data': 'first'})
147
+ print('Item as object:', first_new_item)
148
+ second_new_item = item.create(data={'data': 'second'}, jsonify=True)
149
+ print('Item as dict:', second_new_item)
150
+
151
+ first_item = item.read(first_new_item.id)
152
+ print('Item as object:', first_item)
153
+ first_item = item.read(first_new_item.id, jsonify=True)
154
+ print('Item as dict:', first_item)
155
+
156
+ updated_first_item = item.update(data={'id': first_new_item.id, 'data': 'updated_first'})
157
+ print('Item as object:', updated_first_item)
158
+ updated_second_item = item.update(
159
+ data={'id': UUID(second_new_item['id']), 'data': 'updated_second'}, jsonify=True
160
+ )
161
+ print('Item as dict:', updated_second_item)
162
+
163
+ items = item.paginate(sort_created_at='desc')
164
+ print('Items as objects:', items)
165
+ items = item.paginate(sort_created_at='desc', jsonify=True)
166
+ print('Items as dicts:', items)
167
+
168
+ ```
@@ -0,0 +1,117 @@
1
+ # DB-First
2
+
3
+ CRUD tools for working with database via SQLAlchemy.
4
+
5
+ <!--TOC-->
6
+
7
+ - [DB-First](#db-first)
8
+ - [Features](#features)
9
+ - [Installation](#installation)
10
+ - [Example](#example)
11
+
12
+ <!--TOC-->
13
+
14
+ ## Features
15
+
16
+ * CreateMixin, ReadMixin, UpdateMixin, DeleteMixin for CRUD operation for database.
17
+ * PaginateMixin for get paginated data from database.
18
+ * QueryMaker class for create query 'per-one-model'.
19
+ * Marshmallow (https://github.com/marshmallow-code/marshmallow) schemas for validating input data.
20
+ * Marshmallow schemas for deserialization SQLAlchemy result object to `dict`.
21
+
22
+ ## Installation
23
+
24
+ Recommended using the latest version of Python. DB-First supports Python 3.9 and newer.
25
+
26
+ Install and update using `pip`:
27
+
28
+ ```shell
29
+ $ pip install -U db_first
30
+ ```
31
+
32
+ ## Example
33
+
34
+ File with application initialization `main.py`:
35
+
36
+ ```python
37
+ from uuid import UUID
38
+
39
+ from db_first import BaseCRUD
40
+ from db_first.base_model import ModelMixin
41
+ from db_first.mixins import CreateMixin
42
+ from db_first.mixins import DeleteMixin
43
+ from db_first.mixins import PaginationMixin
44
+ from db_first.mixins import ReadMixin
45
+ from db_first.mixins import UpdateMixin
46
+ from marshmallow import fields
47
+ from marshmallow import Schema
48
+ from sqlalchemy import create_engine
49
+ from sqlalchemy.orm import declarative_base
50
+ from sqlalchemy.orm import Mapped
51
+ from sqlalchemy.orm import mapped_column
52
+ from sqlalchemy.orm import Session
53
+
54
+ engine = create_engine('sqlite://', echo=True, future=True)
55
+ session = Session(engine)
56
+ Base = declarative_base()
57
+
58
+
59
+ class Items(ModelMixin, Base):
60
+ __tablename__ = 'items'
61
+ data: Mapped[str] = mapped_column(comment='Data of item.')
62
+
63
+
64
+ Base.metadata.create_all(engine)
65
+
66
+
67
+ class InputSchemaOfCreate(Schema):
68
+ data = fields.String()
69
+
70
+
71
+ class InputSchemaOfUpdate(InputSchemaOfCreate):
72
+ id = fields.UUID()
73
+
74
+
75
+ class OutputSchema(InputSchemaOfUpdate):
76
+ created_at = fields.DateTime()
77
+
78
+
79
+ class ItemController(CreateMixin, ReadMixin, UpdateMixin, DeleteMixin, PaginationMixin, BaseCRUD):
80
+ class Meta:
81
+ session = session
82
+ model = Items
83
+ input_schema_of_create = InputSchemaOfCreate
84
+ input_schema_of_update = InputSchemaOfUpdate
85
+ output_schema_of_create = OutputSchema
86
+ output_schema_of_read = OutputSchema
87
+ output_schema_of_update = OutputSchema
88
+ output_schema_of_paginate = OutputSchema
89
+ sortable = ['created_at']
90
+
91
+
92
+ if __name__ == '__main__':
93
+ item = ItemController()
94
+
95
+ first_new_item = item.create(data={'data': 'first'})
96
+ print('Item as object:', first_new_item)
97
+ second_new_item = item.create(data={'data': 'second'}, jsonify=True)
98
+ print('Item as dict:', second_new_item)
99
+
100
+ first_item = item.read(first_new_item.id)
101
+ print('Item as object:', first_item)
102
+ first_item = item.read(first_new_item.id, jsonify=True)
103
+ print('Item as dict:', first_item)
104
+
105
+ updated_first_item = item.update(data={'id': first_new_item.id, 'data': 'updated_first'})
106
+ print('Item as object:', updated_first_item)
107
+ updated_second_item = item.update(
108
+ data={'id': UUID(second_new_item['id']), 'data': 'updated_second'}, jsonify=True
109
+ )
110
+ print('Item as dict:', updated_second_item)
111
+
112
+ items = item.paginate(sort_created_at='desc')
113
+ print('Items as objects:', items)
114
+ items = item.paginate(sort_created_at='desc', jsonify=True)
115
+ print('Items as dicts:', items)
116
+
117
+ ```
@@ -0,0 +1,79 @@
1
+ from uuid import UUID
2
+
3
+ from db_first import BaseCRUD
4
+ from db_first.base_model import ModelMixin
5
+ from db_first.mixins import CreateMixin
6
+ from db_first.mixins import DeleteMixin
7
+ from db_first.mixins import PaginationMixin
8
+ from db_first.mixins import ReadMixin
9
+ from db_first.mixins import UpdateMixin
10
+ from marshmallow import fields
11
+ from marshmallow import Schema
12
+ from sqlalchemy import create_engine
13
+ from sqlalchemy.orm import declarative_base
14
+ from sqlalchemy.orm import Mapped
15
+ from sqlalchemy.orm import mapped_column
16
+ from sqlalchemy.orm import Session
17
+
18
+ engine = create_engine('sqlite://', echo=True, future=True)
19
+ session = Session(engine)
20
+ Base = declarative_base()
21
+
22
+
23
+ class Items(ModelMixin, Base):
24
+ __tablename__ = 'items'
25
+ data: Mapped[str] = mapped_column(comment='Data of item.')
26
+
27
+
28
+ Base.metadata.create_all(engine)
29
+
30
+
31
+ class InputSchemaOfCreate(Schema):
32
+ data = fields.String()
33
+
34
+
35
+ class InputSchemaOfUpdate(InputSchemaOfCreate):
36
+ id = fields.UUID()
37
+
38
+
39
+ class OutputSchema(InputSchemaOfUpdate):
40
+ created_at = fields.DateTime()
41
+
42
+
43
+ class ItemController(CreateMixin, ReadMixin, UpdateMixin, DeleteMixin, PaginationMixin, BaseCRUD):
44
+ class Meta:
45
+ session = session
46
+ model = Items
47
+ input_schema_of_create = InputSchemaOfCreate
48
+ input_schema_of_update = InputSchemaOfUpdate
49
+ output_schema_of_create = OutputSchema
50
+ output_schema_of_read = OutputSchema
51
+ output_schema_of_update = OutputSchema
52
+ output_schema_of_paginate = OutputSchema
53
+ sortable = ['created_at']
54
+
55
+
56
+ if __name__ == '__main__':
57
+ item = ItemController()
58
+
59
+ first_new_item = item.create(data={'data': 'first'})
60
+ print('Item as object:', first_new_item)
61
+ second_new_item = item.create(data={'data': 'second'}, jsonify=True)
62
+ print('Item as dict:', second_new_item)
63
+
64
+ first_item = item.read(first_new_item.id)
65
+ print('Item as object:', first_item)
66
+ first_item = item.read(first_new_item.id, jsonify=True)
67
+ print('Item as dict:', first_item)
68
+
69
+ updated_first_item = item.update(data={'id': first_new_item.id, 'data': 'updated_first'})
70
+ print('Item as object:', updated_first_item)
71
+ updated_second_item = item.update(
72
+ data={'id': UUID(second_new_item['id']), 'data': 'updated_second'}, jsonify=True
73
+ )
74
+ print('Item as dict:', updated_second_item)
75
+
76
+ items = item.paginate(sort_created_at='desc')
77
+ print('Items as objects:', items)
78
+ items = item.paginate(sort_created_at='desc', jsonify=True)
79
+ print('Items as dicts:', items)
@@ -0,0 +1,91 @@
1
+ [build-system]
2
+ build-backend = "setuptools.build_meta"
3
+ requires = ["setuptools>=69", "wheel"]
4
+
5
+ [project]
6
+ authors = [
7
+ {name = "Konstantin Fadeev", email = "fadeev@legalact.pro"}
8
+ ]
9
+ classifiers = [
10
+ "Development Status :: 5 - Production/Stable",
11
+ "Intended Audience :: Developers",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ "Programming Language :: Python :: 3 :: Only",
15
+ "Programming Language :: Python :: Implementation :: CPython",
16
+ "Topic :: Database",
17
+ "Topic :: Software Development :: Libraries"
18
+ ]
19
+ dependencies = [
20
+ "SQLAlchemy>=2.0.9",
21
+ "marshmallow>=3.14.1"
22
+ ]
23
+ description = "CRUD tools for working with database via SQLAlchemy."
24
+ license = {file = "LICENSE"}
25
+ name = "DB-First"
26
+ readme = "README.md"
27
+ requires-python = ">=3.9"
28
+ version = "1.0.0"
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "build==1.2.2",
33
+ "pre-commit==3.8.0",
34
+ "pytest==8.3.3",
35
+ "pytest-cov==5.0.0",
36
+ "python-dotenv==1.0.1",
37
+ "tox==4.21.2",
38
+ "twine==5.1.1"
39
+ ]
40
+
41
+ [project.urls]
42
+ changelog = "https://github.com/flask-pro/db_first/blob/master/CHANGES.md"
43
+ repository = "https://github.com/flask-pro/db_first"
44
+
45
+ [tool.bandit]
46
+ exclude_dirs = ["tests"]
47
+
48
+ [tool.black]
49
+ include = '\.pyi?$'
50
+ line-length = 100
51
+ skip-string-normalization = true
52
+ target-version = ['py312']
53
+
54
+ [tool.docformatter]
55
+ black = true
56
+ non-cap = ["docformatter"]
57
+ non-strict = false
58
+ recursive = true
59
+ style = 'sphinx'
60
+ wrap-descriptions = 100
61
+ wrap-summaries = 100
62
+
63
+ [tool.docsig]
64
+ check-class = true
65
+ check-dunders = true
66
+ check-nested = true
67
+ check-overridden = true
68
+ check-property-returns = true
69
+ check-protected = true
70
+ check-protected-class-methods = true
71
+ disable = ["SIG101"]
72
+
73
+ [tool.setuptools.packages.find]
74
+ include = ["db_first*"]
75
+ where = ["src"]
76
+
77
+ [tool.tox]
78
+ legacy_tox_ini = """
79
+ [tox]
80
+ env_list =
81
+ py312
82
+ py311
83
+ py310
84
+ py39
85
+ [testenv]
86
+ allowlist_externals = *
87
+ commands =
88
+ pip install -q -e ".[dev]"
89
+ pip install -q -e .
90
+ pytest
91
+ """
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.1
2
+ Name: DB-First
3
+ Version: 1.0.0
4
+ Summary: CRUD tools for working with database via SQLAlchemy.
5
+ Author-email: Konstantin Fadeev <fadeev@legalact.pro>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Konstantin Fadeev
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: changelog, https://github.com/flask-pro/db_first/blob/master/CHANGES.md
29
+ Project-URL: repository, https://github.com/flask-pro/db_first
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: Implementation :: CPython
36
+ Classifier: Topic :: Database
37
+ Classifier: Topic :: Software Development :: Libraries
38
+ Requires-Python: >=3.9
39
+ Description-Content-Type: text/markdown
40
+ License-File: LICENSE
41
+ Requires-Dist: SQLAlchemy>=2.0.9
42
+ Requires-Dist: marshmallow>=3.14.1
43
+ Provides-Extra: dev
44
+ Requires-Dist: build==1.2.2; extra == "dev"
45
+ Requires-Dist: pre-commit==3.8.0; extra == "dev"
46
+ Requires-Dist: pytest==8.3.3; extra == "dev"
47
+ Requires-Dist: pytest-cov==5.0.0; extra == "dev"
48
+ Requires-Dist: python-dotenv==1.0.1; extra == "dev"
49
+ Requires-Dist: tox==4.21.2; extra == "dev"
50
+ Requires-Dist: twine==5.1.1; extra == "dev"
51
+
52
+ # DB-First
53
+
54
+ CRUD tools for working with database via SQLAlchemy.
55
+
56
+ <!--TOC-->
57
+
58
+ - [DB-First](#db-first)
59
+ - [Features](#features)
60
+ - [Installation](#installation)
61
+ - [Example](#example)
62
+
63
+ <!--TOC-->
64
+
65
+ ## Features
66
+
67
+ * CreateMixin, ReadMixin, UpdateMixin, DeleteMixin for CRUD operation for database.
68
+ * PaginateMixin for get paginated data from database.
69
+ * QueryMaker class for create query 'per-one-model'.
70
+ * Marshmallow (https://github.com/marshmallow-code/marshmallow) schemas for validating input data.
71
+ * Marshmallow schemas for deserialization SQLAlchemy result object to `dict`.
72
+
73
+ ## Installation
74
+
75
+ Recommended using the latest version of Python. DB-First supports Python 3.9 and newer.
76
+
77
+ Install and update using `pip`:
78
+
79
+ ```shell
80
+ $ pip install -U db_first
81
+ ```
82
+
83
+ ## Example
84
+
85
+ File with application initialization `main.py`:
86
+
87
+ ```python
88
+ from uuid import UUID
89
+
90
+ from db_first import BaseCRUD
91
+ from db_first.base_model import ModelMixin
92
+ from db_first.mixins import CreateMixin
93
+ from db_first.mixins import DeleteMixin
94
+ from db_first.mixins import PaginationMixin
95
+ from db_first.mixins import ReadMixin
96
+ from db_first.mixins import UpdateMixin
97
+ from marshmallow import fields
98
+ from marshmallow import Schema
99
+ from sqlalchemy import create_engine
100
+ from sqlalchemy.orm import declarative_base
101
+ from sqlalchemy.orm import Mapped
102
+ from sqlalchemy.orm import mapped_column
103
+ from sqlalchemy.orm import Session
104
+
105
+ engine = create_engine('sqlite://', echo=True, future=True)
106
+ session = Session(engine)
107
+ Base = declarative_base()
108
+
109
+
110
+ class Items(ModelMixin, Base):
111
+ __tablename__ = 'items'
112
+ data: Mapped[str] = mapped_column(comment='Data of item.')
113
+
114
+
115
+ Base.metadata.create_all(engine)
116
+
117
+
118
+ class InputSchemaOfCreate(Schema):
119
+ data = fields.String()
120
+
121
+
122
+ class InputSchemaOfUpdate(InputSchemaOfCreate):
123
+ id = fields.UUID()
124
+
125
+
126
+ class OutputSchema(InputSchemaOfUpdate):
127
+ created_at = fields.DateTime()
128
+
129
+
130
+ class ItemController(CreateMixin, ReadMixin, UpdateMixin, DeleteMixin, PaginationMixin, BaseCRUD):
131
+ class Meta:
132
+ session = session
133
+ model = Items
134
+ input_schema_of_create = InputSchemaOfCreate
135
+ input_schema_of_update = InputSchemaOfUpdate
136
+ output_schema_of_create = OutputSchema
137
+ output_schema_of_read = OutputSchema
138
+ output_schema_of_update = OutputSchema
139
+ output_schema_of_paginate = OutputSchema
140
+ sortable = ['created_at']
141
+
142
+
143
+ if __name__ == '__main__':
144
+ item = ItemController()
145
+
146
+ first_new_item = item.create(data={'data': 'first'})
147
+ print('Item as object:', first_new_item)
148
+ second_new_item = item.create(data={'data': 'second'}, jsonify=True)
149
+ print('Item as dict:', second_new_item)
150
+
151
+ first_item = item.read(first_new_item.id)
152
+ print('Item as object:', first_item)
153
+ first_item = item.read(first_new_item.id, jsonify=True)
154
+ print('Item as dict:', first_item)
155
+
156
+ updated_first_item = item.update(data={'id': first_new_item.id, 'data': 'updated_first'})
157
+ print('Item as object:', updated_first_item)
158
+ updated_second_item = item.update(
159
+ data={'id': UUID(second_new_item['id']), 'data': 'updated_second'}, jsonify=True
160
+ )
161
+ print('Item as dict:', updated_second_item)
162
+
163
+ items = item.paginate(sort_created_at='desc')
164
+ print('Items as objects:', items)
165
+ items = item.paginate(sort_created_at='desc', jsonify=True)
166
+ print('Items as dicts:', items)
167
+
168
+ ```
@@ -0,0 +1,23 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ examples/full_example.py
6
+ src/DB_First.egg-info/PKG-INFO
7
+ src/DB_First.egg-info/SOURCES.txt
8
+ src/DB_First.egg-info/dependency_links.txt
9
+ src/DB_First.egg-info/requires.txt
10
+ src/DB_First.egg-info/top_level.txt
11
+ src/db_first/__init__.py
12
+ src/db_first/base.py
13
+ src/db_first/base_model.py
14
+ src/db_first/exc.py
15
+ src/db_first/query_maker.py
16
+ src/db_first/mixins/__init__.py
17
+ src/db_first/mixins/crud.py
18
+ src/db_first/mixins/pagination.py
19
+ tests/__init__.py
20
+ tests/conftest.py
21
+ tests/test_crud_mixin.py
22
+ tests/test_pagination_mixin.py
23
+ tests/test_query_maker.py
@@ -0,0 +1,11 @@
1
+ SQLAlchemy>=2.0.9
2
+ marshmallow>=3.14.1
3
+
4
+ [dev]
5
+ build==1.2.2
6
+ pre-commit==3.8.0
7
+ pytest==8.3.3
8
+ pytest-cov==5.0.0
9
+ python-dotenv==1.0.1
10
+ tox==4.21.2
11
+ twine==5.1.1