sqla-fancy-core 0.2.0__tar.gz → 0.3.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.
Potentially problematic release.
This version of sqla-fancy-core might be problematic. Click here for more details.
- sqla_fancy_core-0.3.0/.github/workflows/ci.yaml +29 -0
- sqla_fancy_core-0.3.0/.gitignore +160 -0
- sqla_fancy_core-0.3.0/PKG-INFO +110 -0
- {sqla_fancy_core-0.2.0 → sqla_fancy_core-0.3.0}/README.md +5 -7
- sqla_fancy_core-0.3.0/pyproject.toml +50 -0
- {sqla_fancy_core-0.2.0 → sqla_fancy_core-0.3.0}/sqla_fancy_core/__init__.py +9 -4
- sqla_fancy_core-0.3.0/tests/__init__.py +0 -0
- sqla_fancy_core-0.3.0/tests/test_table_factory.py +57 -0
- sqla_fancy_core-0.2.0/PKG-INFO +0 -86
- sqla_fancy_core-0.2.0/pyproject.toml +0 -20
- sqla_fancy_core-0.2.0/setup.py +0 -30
- {sqla_fancy_core-0.2.0 → sqla_fancy_core-0.3.0}/LICENSE +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Python package
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v3
|
|
14
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
15
|
+
uses: actions/setup-python@v4
|
|
16
|
+
with:
|
|
17
|
+
python-version: ${{ matrix.python-version }}
|
|
18
|
+
- name: Install dependencies
|
|
19
|
+
run: |
|
|
20
|
+
pip install -e ".[test]"
|
|
21
|
+
- name: Lint with flake8
|
|
22
|
+
run: |
|
|
23
|
+
# stop the build if there are Python syntax errors or undefined names
|
|
24
|
+
flake8 sqla_fancy_core --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
25
|
+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
|
26
|
+
flake8 sqla_fancy_core --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
27
|
+
- name: Test with pytest
|
|
28
|
+
run: |
|
|
29
|
+
pytest
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sqla-fancy-core
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: SQLAlchemy core, but fancier
|
|
5
|
+
Project-URL: Homepage, https://github.com/sayanarijit/sqla-fancy-core
|
|
6
|
+
Author-email: Arijit Basu <sayanarijit@gmail.com>
|
|
7
|
+
Maintainer-email: Arijit Basu <sayanarijit@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2023 Arijit Basu
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: sql,sqlalchemy,sqlalchemy-core
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Requires-Python: >=3.7
|
|
41
|
+
Requires-Dist: sqlalchemy
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: flake8; extra == 'test'
|
|
44
|
+
Requires-Dist: pytest; extra == 'test'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
# sqla-fancy-core
|
|
48
|
+
|
|
49
|
+
SQLAlchemy core, but fancier.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import sqlalchemy as sa
|
|
53
|
+
|
|
54
|
+
from sqla_fancy_core import TableFactory
|
|
55
|
+
|
|
56
|
+
tf = TableFactory()
|
|
57
|
+
|
|
58
|
+
# Define a table
|
|
59
|
+
class Author:
|
|
60
|
+
|
|
61
|
+
id = tf.auto_id()
|
|
62
|
+
name = tf.string("name")
|
|
63
|
+
created_at = tf.created_at()
|
|
64
|
+
updated_at = tf.updated_at()
|
|
65
|
+
|
|
66
|
+
Table = tf("author")
|
|
67
|
+
|
|
68
|
+
# Define a table
|
|
69
|
+
class Book:
|
|
70
|
+
|
|
71
|
+
id = tf.auto_id()
|
|
72
|
+
title = tf.string("title")
|
|
73
|
+
author_id = tf.foreign_key("author_id", Author.id)
|
|
74
|
+
created_at = tf.created_at()
|
|
75
|
+
updated_at = tf.updated_at()
|
|
76
|
+
|
|
77
|
+
Table = tf("book")
|
|
78
|
+
|
|
79
|
+
# Create the tables
|
|
80
|
+
engine = sa.create_engine("sqlite:///:memory:")
|
|
81
|
+
tf.metadata.create_all(engine)
|
|
82
|
+
|
|
83
|
+
with engine.connect() as conn:
|
|
84
|
+
# Insert author
|
|
85
|
+
qry = (
|
|
86
|
+
sa.insert(Author.Table)
|
|
87
|
+
.values({Author.name: "John Doe"})
|
|
88
|
+
.returning(Author.id)
|
|
89
|
+
)
|
|
90
|
+
author = next(conn.execute(qry))
|
|
91
|
+
author_id = author._mapping[Author.id]
|
|
92
|
+
assert author_id == 1
|
|
93
|
+
|
|
94
|
+
# Insert book
|
|
95
|
+
qry = (
|
|
96
|
+
sa.insert(Book.Table)
|
|
97
|
+
.values({Book.title: "My Book", Book.author_id: author_id})
|
|
98
|
+
.returning(Book.id)
|
|
99
|
+
)
|
|
100
|
+
book = next(conn.execute(qry))
|
|
101
|
+
assert book._mapping[Book.id] == 1
|
|
102
|
+
|
|
103
|
+
# Query the data
|
|
104
|
+
qry = sa.select(Author.name, Book.title).join(
|
|
105
|
+
Book.Table,
|
|
106
|
+
Book.author_id == Author.id,
|
|
107
|
+
)
|
|
108
|
+
result = conn.execute(qry).fetchall()
|
|
109
|
+
assert result == [("John Doe", "My Book")], result
|
|
110
|
+
```
|
|
@@ -7,7 +7,6 @@ import sqlalchemy as sa
|
|
|
7
7
|
|
|
8
8
|
from sqla_fancy_core import TableFactory
|
|
9
9
|
|
|
10
|
-
metadata = sa.MetaData()
|
|
11
10
|
tf = TableFactory()
|
|
12
11
|
|
|
13
12
|
# Define a table
|
|
@@ -18,7 +17,7 @@ class Author:
|
|
|
18
17
|
created_at = tf.created_at()
|
|
19
18
|
updated_at = tf.updated_at()
|
|
20
19
|
|
|
21
|
-
Table = tf("author"
|
|
20
|
+
Table = tf("author")
|
|
22
21
|
|
|
23
22
|
# Define a table
|
|
24
23
|
class Book:
|
|
@@ -29,11 +28,11 @@ class Book:
|
|
|
29
28
|
created_at = tf.created_at()
|
|
30
29
|
updated_at = tf.updated_at()
|
|
31
30
|
|
|
32
|
-
Table = tf("book"
|
|
31
|
+
Table = tf("book")
|
|
33
32
|
|
|
34
33
|
# Create the tables
|
|
35
34
|
engine = sa.create_engine("sqlite:///:memory:")
|
|
36
|
-
metadata.create_all(engine)
|
|
35
|
+
tf.metadata.create_all(engine)
|
|
37
36
|
|
|
38
37
|
with engine.connect() as conn:
|
|
39
38
|
# Insert author
|
|
@@ -43,7 +42,7 @@ with engine.connect() as conn:
|
|
|
43
42
|
.returning(Author.id)
|
|
44
43
|
)
|
|
45
44
|
author = next(conn.execute(qry))
|
|
46
|
-
|
|
45
|
+
author_id = author._mapping[Author.id]
|
|
47
46
|
assert author_id == 1
|
|
48
47
|
|
|
49
48
|
# Insert book
|
|
@@ -53,8 +52,7 @@ with engine.connect() as conn:
|
|
|
53
52
|
.returning(Book.id)
|
|
54
53
|
)
|
|
55
54
|
book = next(conn.execute(qry))
|
|
56
|
-
|
|
57
|
-
assert book_id == 1
|
|
55
|
+
assert book._mapping[Book.id] == 1
|
|
58
56
|
|
|
59
57
|
# Query the data
|
|
60
58
|
qry = sa.select(Author.name, Book.title).join(
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = 'sqla-fancy-core'
|
|
3
|
+
version = '0.3.0'
|
|
4
|
+
description = 'SQLAlchemy core, but fancier'
|
|
5
|
+
readme = 'README.md'
|
|
6
|
+
requires-python = ">=3.7"
|
|
7
|
+
license = {file = "LICENSE"}
|
|
8
|
+
keywords = ["sql", "sqlalchemy", "sqlalchemy-core"]
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Arijit Basu", email = "sayanarijit@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
maintainers = [
|
|
13
|
+
{name = "Arijit Basu", email = "sayanarijit@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
classifiers = [ # Optional
|
|
16
|
+
# How mature is this project? Common values are
|
|
17
|
+
# 3 - Alpha
|
|
18
|
+
# 4 - Beta
|
|
19
|
+
# 5 - Production/Stable
|
|
20
|
+
"Development Status :: 3 - Alpha",
|
|
21
|
+
|
|
22
|
+
# Indicate who your project is intended for
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Pick your license as you wish
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
|
|
29
|
+
# Specify the Python versions you support here. In particular, ensure
|
|
30
|
+
# that you indicate you support Python 3. These classifiers are *not*
|
|
31
|
+
# checked by "pip install". See instead "python_requires" below.
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.7",
|
|
34
|
+
"Programming Language :: Python :: 3.8",
|
|
35
|
+
"Programming Language :: Python :: 3.9",
|
|
36
|
+
"Programming Language :: Python :: 3.10",
|
|
37
|
+
"Programming Language :: Python :: 3.11",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
dependencies = ["sqlalchemy"]
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
test = ["pytest", "flake8"]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
"Homepage" = "https://github.com/sayanarijit/sqla-fancy-core"
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = ["hatchling"]
|
|
50
|
+
build-backend = "hatchling.build"
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"""SQLAlchemy core, but fancier."""
|
|
2
2
|
|
|
3
|
+
from typing import Optional, Union
|
|
4
|
+
|
|
3
5
|
import sqlalchemy as sa
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
class TableFactory:
|
|
7
9
|
"""A factory for creating SQLAlchemy columns with default values."""
|
|
8
10
|
|
|
9
|
-
def __init__(self):
|
|
11
|
+
def __init__(self, metadata: Optional[sa.MetaData] = None):
|
|
10
12
|
"""Initialize the factory with default values."""
|
|
13
|
+
if metadata is None:
|
|
14
|
+
metadata = sa.MetaData()
|
|
15
|
+
self.metadata = metadata
|
|
11
16
|
self.c = []
|
|
12
17
|
|
|
13
18
|
def col(self, *args, **kwargs) -> sa.Column:
|
|
@@ -66,7 +71,7 @@ class TableFactory:
|
|
|
66
71
|
def false(self, name: str, *args, **kwargs):
|
|
67
72
|
return self.boolean(name, default=False, *args, **kwargs)
|
|
68
73
|
|
|
69
|
-
def foreign_key(self, name: str, ref: str
|
|
74
|
+
def foreign_key(self, name: str, ref: Union[str, sa.Column], *args, **kwargs):
|
|
70
75
|
return self.col(name, sa.ForeignKey(ref), *args, **kwargs)
|
|
71
76
|
|
|
72
77
|
def enum(self, name: str, enum: type, *args, **kwargs) -> sa.Column:
|
|
@@ -130,7 +135,7 @@ class TableFactory:
|
|
|
130
135
|
def created_at(self, name="created_at", *args, **kwargs) -> sa.Column:
|
|
131
136
|
return self.datetime(name, default=sa.func.now(), *args, **kwargs)
|
|
132
137
|
|
|
133
|
-
def __call__(self, name,
|
|
138
|
+
def __call__(self, name, *args, **kwargs):
|
|
134
139
|
cols = self.c
|
|
135
140
|
self.c = []
|
|
136
|
-
return sa.Table(name, metadata, *args, *cols, **kwargs)
|
|
141
|
+
return sa.Table(name, self.metadata, *args, *cols, **kwargs)
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
def test_table_factory():
|
|
2
|
+
import sqlalchemy as sa
|
|
3
|
+
|
|
4
|
+
from sqla_fancy_core import TableFactory
|
|
5
|
+
|
|
6
|
+
tf = TableFactory()
|
|
7
|
+
|
|
8
|
+
# Define a table
|
|
9
|
+
class Author:
|
|
10
|
+
id = tf.auto_id()
|
|
11
|
+
name = tf.string("name")
|
|
12
|
+
created_at = tf.created_at()
|
|
13
|
+
updated_at = tf.updated_at()
|
|
14
|
+
|
|
15
|
+
Table = tf("author")
|
|
16
|
+
|
|
17
|
+
# Define a table
|
|
18
|
+
class Book:
|
|
19
|
+
id = tf.auto_id()
|
|
20
|
+
title = tf.string("title")
|
|
21
|
+
author_id = tf.foreign_key("author_id", Author.id)
|
|
22
|
+
created_at = tf.created_at()
|
|
23
|
+
updated_at = tf.updated_at()
|
|
24
|
+
|
|
25
|
+
Table = tf("book")
|
|
26
|
+
|
|
27
|
+
# Create the tables
|
|
28
|
+
engine = sa.create_engine("sqlite:///:memory:")
|
|
29
|
+
tf.metadata.create_all(engine)
|
|
30
|
+
|
|
31
|
+
with engine.connect() as conn:
|
|
32
|
+
# Insert author
|
|
33
|
+
qry = (
|
|
34
|
+
sa.insert(Author.Table)
|
|
35
|
+
.values({Author.name: "John Doe"})
|
|
36
|
+
.returning(Author.id)
|
|
37
|
+
)
|
|
38
|
+
author = next(conn.execute(qry))
|
|
39
|
+
author_id = author._mapping[Author.id]
|
|
40
|
+
assert author_id == 1
|
|
41
|
+
|
|
42
|
+
# Insert book
|
|
43
|
+
qry = (
|
|
44
|
+
sa.insert(Book.Table)
|
|
45
|
+
.values({Book.title: "My Book", Book.author_id: author_id})
|
|
46
|
+
.returning(Book.id)
|
|
47
|
+
)
|
|
48
|
+
book = next(conn.execute(qry))
|
|
49
|
+
assert book._mapping[Book.id] == 1
|
|
50
|
+
|
|
51
|
+
# Query the data
|
|
52
|
+
qry = sa.select(Author.name, Book.title).join(
|
|
53
|
+
Book.Table,
|
|
54
|
+
Book.author_id == Author.id,
|
|
55
|
+
)
|
|
56
|
+
result = conn.execute(qry).fetchall()
|
|
57
|
+
assert result == [("John Doe", "My Book")], result
|
sqla_fancy_core-0.2.0/PKG-INFO
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: sqla-fancy-core
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: SQLAlchemy core, but fancier
|
|
5
|
-
License: MIT
|
|
6
|
-
Keywords: sql,sqlalchemy,sqlalchemy-core
|
|
7
|
-
Author: Arijit Basu
|
|
8
|
-
Author-email: sayanarijit@gmail.com
|
|
9
|
-
Requires-Python: >=3.7,<4.0
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Requires-Dist: sqlalchemy
|
|
18
|
-
Description-Content-Type: text/markdown
|
|
19
|
-
|
|
20
|
-
# sqla-fancy-core
|
|
21
|
-
|
|
22
|
-
SQLAlchemy core, but fancier.
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
import sqlalchemy as sa
|
|
26
|
-
|
|
27
|
-
from sqla_fancy_core import TableFactory
|
|
28
|
-
|
|
29
|
-
metadata = sa.MetaData()
|
|
30
|
-
tf = TableFactory()
|
|
31
|
-
|
|
32
|
-
# Define a table
|
|
33
|
-
class Author:
|
|
34
|
-
|
|
35
|
-
id = tf.auto_id()
|
|
36
|
-
name = tf.string("name")
|
|
37
|
-
created_at = tf.created_at()
|
|
38
|
-
updated_at = tf.updated_at()
|
|
39
|
-
|
|
40
|
-
Table = tf("author", metadata)
|
|
41
|
-
|
|
42
|
-
# Define a table
|
|
43
|
-
class Book:
|
|
44
|
-
|
|
45
|
-
id = tf.auto_id()
|
|
46
|
-
title = tf.string("title")
|
|
47
|
-
author_id = tf.foreign_key("author_id", Author.id)
|
|
48
|
-
created_at = tf.created_at()
|
|
49
|
-
updated_at = tf.updated_at()
|
|
50
|
-
|
|
51
|
-
Table = tf("book", metadata)
|
|
52
|
-
|
|
53
|
-
# Create the tables
|
|
54
|
-
engine = sa.create_engine("sqlite:///:memory:")
|
|
55
|
-
metadata.create_all(engine)
|
|
56
|
-
|
|
57
|
-
with engine.connect() as conn:
|
|
58
|
-
# Insert author
|
|
59
|
-
qry = (
|
|
60
|
-
sa.insert(Author.Table)
|
|
61
|
-
.values({Author.name: "John Doe"})
|
|
62
|
-
.returning(Author.id)
|
|
63
|
-
)
|
|
64
|
-
author = next(conn.execute(qry))
|
|
65
|
-
(author_id,) = author
|
|
66
|
-
assert author_id == 1
|
|
67
|
-
|
|
68
|
-
# Insert book
|
|
69
|
-
qry = (
|
|
70
|
-
sa.insert(Book.Table)
|
|
71
|
-
.values({Book.title: "My Book", Book.author_id: author_id})
|
|
72
|
-
.returning(Book.id)
|
|
73
|
-
)
|
|
74
|
-
book = next(conn.execute(qry))
|
|
75
|
-
(book_id,) = book
|
|
76
|
-
assert book_id == 1
|
|
77
|
-
|
|
78
|
-
# Query the data
|
|
79
|
-
qry = sa.select(Author.name, Book.title).join(
|
|
80
|
-
Book.Table,
|
|
81
|
-
Book.author_id == Author.id,
|
|
82
|
-
)
|
|
83
|
-
result = conn.execute(qry).fetchall()
|
|
84
|
-
assert result == [("John Doe", "My Book")], result
|
|
85
|
-
```
|
|
86
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
[tool.poetry]
|
|
2
|
-
name = "sqla-fancy-core"
|
|
3
|
-
version = "0.2.0"
|
|
4
|
-
description = "SQLAlchemy core, but fancier"
|
|
5
|
-
authors = ["Arijit Basu <sayanarijit@gmail.com>"]
|
|
6
|
-
readme = "README.md"
|
|
7
|
-
license = "MIT"
|
|
8
|
-
keywords = ["sql", "sqlalchemy", "sqlalchemy-core"]
|
|
9
|
-
packages = [{ include = "sqla_fancy_core" }]
|
|
10
|
-
|
|
11
|
-
[tool.poetry.dependencies]
|
|
12
|
-
python = "^3.7"
|
|
13
|
-
sqlalchemy = "*"
|
|
14
|
-
|
|
15
|
-
[tool.poetry.dev-dependencies]
|
|
16
|
-
pytest = "*"
|
|
17
|
-
|
|
18
|
-
[build-system]
|
|
19
|
-
requires = ["poetry-core"]
|
|
20
|
-
build-backend = "poetry.core.masonry.api"
|
sqla_fancy_core-0.2.0/setup.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['sqla_fancy_core']
|
|
6
|
-
|
|
7
|
-
package_data = \
|
|
8
|
-
{'': ['*']}
|
|
9
|
-
|
|
10
|
-
install_requires = \
|
|
11
|
-
['sqlalchemy']
|
|
12
|
-
|
|
13
|
-
setup_kwargs = {
|
|
14
|
-
'name': 'sqla-fancy-core',
|
|
15
|
-
'version': '0.2.0',
|
|
16
|
-
'description': 'SQLAlchemy core, but fancier',
|
|
17
|
-
'long_description': '# sqla-fancy-core\n\nSQLAlchemy core, but fancier.\n\n```python\nimport sqlalchemy as sa\n\nfrom sqla_fancy_core import TableFactory\n\nmetadata = sa.MetaData()\ntf = TableFactory()\n\n# Define a table\nclass Author:\n\n id = tf.auto_id()\n name = tf.string("name")\n created_at = tf.created_at()\n updated_at = tf.updated_at()\n\n Table = tf("author", metadata)\n\n# Define a table\nclass Book:\n\n id = tf.auto_id()\n title = tf.string("title")\n author_id = tf.foreign_key("author_id", Author.id)\n created_at = tf.created_at()\n updated_at = tf.updated_at()\n\n Table = tf("book", metadata)\n\n# Create the tables\nengine = sa.create_engine("sqlite:///:memory:")\nmetadata.create_all(engine)\n\nwith engine.connect() as conn:\n # Insert author\n qry = (\n sa.insert(Author.Table)\n .values({Author.name: "John Doe"})\n .returning(Author.id)\n )\n author = next(conn.execute(qry))\n (author_id,) = author\n assert author_id == 1\n\n # Insert book\n qry = (\n sa.insert(Book.Table)\n .values({Book.title: "My Book", Book.author_id: author_id})\n .returning(Book.id)\n )\n book = next(conn.execute(qry))\n (book_id,) = book\n assert book_id == 1\n\n # Query the data\n qry = sa.select(Author.name, Book.title).join(\n Book.Table,\n Book.author_id == Author.id,\n )\n result = conn.execute(qry).fetchall()\n assert result == [("John Doe", "My Book")], result\n```\n',
|
|
18
|
-
'author': 'Arijit Basu',
|
|
19
|
-
'author_email': 'sayanarijit@gmail.com',
|
|
20
|
-
'maintainer': 'None',
|
|
21
|
-
'maintainer_email': 'None',
|
|
22
|
-
'url': 'None',
|
|
23
|
-
'packages': packages,
|
|
24
|
-
'package_data': package_data,
|
|
25
|
-
'install_requires': install_requires,
|
|
26
|
-
'python_requires': '>=3.7,<4.0',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setup(**setup_kwargs)
|
|
File without changes
|