sqla-fancy-core 1.0.0__py3-none-any.whl → 1.0.2__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.
- sqla_fancy_core/__init__.py +4 -4
- {sqla_fancy_core-1.0.0.dist-info → sqla_fancy_core-1.0.2.dist-info}/METADATA +5 -37
- sqla_fancy_core-1.0.2.dist-info/RECORD +5 -0
- sqla_fancy_core-1.0.0.dist-info/RECORD +0 -5
- {sqla_fancy_core-1.0.0.dist-info → sqla_fancy_core-1.0.2.dist-info}/WHEEL +0 -0
- {sqla_fancy_core-1.0.0.dist-info → sqla_fancy_core-1.0.2.dist-info}/licenses/LICENSE +0 -0
sqla_fancy_core/__init__.py
CHANGED
|
@@ -11,14 +11,14 @@ class TableFactory:
|
|
|
11
11
|
def __init__(self, metadata: Optional[sa.MetaData] = None):
|
|
12
12
|
"""Initialize the factory with default values."""
|
|
13
13
|
if metadata is None:
|
|
14
|
-
metadata = sa.MetaData()
|
|
15
|
-
|
|
14
|
+
self.metadata = sa.MetaData()
|
|
15
|
+
else:
|
|
16
|
+
self.metadata = metadata
|
|
16
17
|
self.c = []
|
|
17
18
|
|
|
18
19
|
def col(self, *args, **kwargs) -> sa.Column:
|
|
19
20
|
col = sa.Column(*args, **kwargs)
|
|
20
|
-
self
|
|
21
|
-
return col
|
|
21
|
+
return self(col)
|
|
22
22
|
|
|
23
23
|
def integer(self, name: str, *args, **kwargs) -> sa.Column:
|
|
24
24
|
return self.col(name, sa.Integer, *args, **kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqla-fancy-core
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: SQLAlchemy core, but fancier
|
|
5
5
|
Project-URL: Homepage, https://github.com/sayanarijit/sqla-fancy-core
|
|
6
6
|
Author-email: Arijit Basu <sayanarijit@gmail.com>
|
|
@@ -47,13 +47,13 @@ SQLAlchemy core, but fancier.
|
|
|
47
47
|
|
|
48
48
|
```python
|
|
49
49
|
import sqlalchemy as sa
|
|
50
|
+
|
|
50
51
|
from sqla_fancy_core import TableFactory
|
|
51
52
|
|
|
52
53
|
tf = TableFactory()
|
|
53
54
|
|
|
54
55
|
# Define a table
|
|
55
56
|
class Author:
|
|
56
|
-
|
|
57
57
|
id = tf.auto_id()
|
|
58
58
|
name = tf.string("name")
|
|
59
59
|
created_at = tf.created_at()
|
|
@@ -97,39 +97,7 @@ with engine.connect() as conn:
|
|
|
97
97
|
.values({Author.name: "John Doe"})
|
|
98
98
|
.returning(Author.id)
|
|
99
99
|
)
|
|
100
|
-
author =
|
|
101
|
-
author_id = author[Author.id]
|
|
102
|
-
assert author_id == 1
|
|
103
|
-
|
|
104
|
-
# Insert book
|
|
105
|
-
qry = (
|
|
106
|
-
sa.insert(Book.Table)
|
|
107
|
-
.values({Book.title: "My Book", Book.author_id: author_id})
|
|
108
|
-
.returning(Book.id)
|
|
109
|
-
)
|
|
110
|
-
book = next(conn.execute(qry).mappings())
|
|
111
|
-
assert book[Book.id] == 1
|
|
112
|
-
|
|
113
|
-
# Query the data
|
|
114
|
-
qry = sa.select(Author.name, Book.title).join(
|
|
115
|
-
Book.Table,
|
|
116
|
-
Book.author_id == Author.id,
|
|
117
|
-
)
|
|
118
|
-
result = conn.execute(qry).fetchall()
|
|
119
|
-
assert result == [("John Doe", "My Book")], result
|
|
120
|
-
|
|
121
|
-
# Create the tables
|
|
122
|
-
engine = sa.create_engine("sqlite:///:memory:")
|
|
123
|
-
tf.metadata.create_all(engine)
|
|
124
|
-
|
|
125
|
-
with engine.connect() as conn:
|
|
126
|
-
# Insert author
|
|
127
|
-
qry = (
|
|
128
|
-
sa.insert(Author.Table)
|
|
129
|
-
.values({Author.name: "John Doe"})
|
|
130
|
-
.returning(Author.id)
|
|
131
|
-
)
|
|
132
|
-
author = next(conn.execute(qry).mappings())
|
|
100
|
+
author = conn.execute(qry).mappings().first()
|
|
133
101
|
author_id = author[Author.id]
|
|
134
102
|
assert author_id == 1
|
|
135
103
|
|
|
@@ -139,7 +107,7 @@ with engine.connect() as conn:
|
|
|
139
107
|
.values({Book.title: "My Book", Book.author_id: author_id})
|
|
140
108
|
.returning(Book.id)
|
|
141
109
|
)
|
|
142
|
-
book =
|
|
110
|
+
book = conn.execute(qry).mappings().first()
|
|
143
111
|
assert book[Book.id] == 1
|
|
144
112
|
|
|
145
113
|
# Query the data
|
|
@@ -147,7 +115,7 @@ with engine.connect() as conn:
|
|
|
147
115
|
Book.Table,
|
|
148
116
|
Book.author_id == Author.id,
|
|
149
117
|
)
|
|
150
|
-
result = conn.execute(qry).
|
|
118
|
+
result = conn.execute(qry).all()
|
|
151
119
|
assert result == [("John Doe", "My Book")], result
|
|
152
120
|
```
|
|
153
121
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
sqla_fancy_core/__init__.py,sha256=BbhW9HwA-YvLUh_r9AIigqN4vAkdDBLf0b9rO5VnuhA,6378
|
|
2
|
+
sqla_fancy_core-1.0.2.dist-info/METADATA,sha256=qkwA6GOVIS0rr0zeelQkV6AMV6AjPOSxsz7M9yQdFUY,4815
|
|
3
|
+
sqla_fancy_core-1.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
sqla_fancy_core-1.0.2.dist-info/licenses/LICENSE,sha256=XcYXJ0ipvwOn-nzko6p_xoCCbke8tAhmlIN04rUZDLk,1068
|
|
5
|
+
sqla_fancy_core-1.0.2.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
sqla_fancy_core/__init__.py,sha256=GwPbjEPhM-mxFcsjZizCQ9dnUNgqBswCfwrI_u-JVfc,6376
|
|
2
|
-
sqla_fancy_core-1.0.0.dist-info/METADATA,sha256=1UBn6tJ7EK6TXKBdq6gUWtzStIqeHS3lsKDb9pkZBCE,5671
|
|
3
|
-
sqla_fancy_core-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
-
sqla_fancy_core-1.0.0.dist-info/licenses/LICENSE,sha256=XcYXJ0ipvwOn-nzko6p_xoCCbke8tAhmlIN04rUZDLk,1068
|
|
5
|
-
sqla_fancy_core-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|