sqla-fancy-core 1.0.1__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.
@@ -11,8 +11,9 @@ 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
- self.metadata = metadata
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqla-fancy-core
3
- Version: 1.0.1
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 = next(conn.execute(qry).mappings())
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 = next(conn.execute(qry).mappings())
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).fetchall()
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=SMvQdh8lkAPWe0D--9ysfVXe5AzJ7W4n7rEvsLyuqd4,6355
2
- sqla_fancy_core-1.0.1.dist-info/METADATA,sha256=X_wZBp-9KdZaECBzSGG5AC81qAn7wXV6nlKXKEcmBCI,5671
3
- sqla_fancy_core-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
- sqla_fancy_core-1.0.1.dist-info/licenses/LICENSE,sha256=XcYXJ0ipvwOn-nzko6p_xoCCbke8tAhmlIN04rUZDLk,1068
5
- sqla_fancy_core-1.0.1.dist-info/RECORD,,