sqla-fancy-core 1.0.1__tar.gz → 1.0.2__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.

@@ -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
 
@@ -6,13 +6,13 @@ SQLAlchemy core, but fancier.
6
6
 
7
7
  ```python
8
8
  import sqlalchemy as sa
9
+
9
10
  from sqla_fancy_core import TableFactory
10
11
 
11
12
  tf = TableFactory()
12
13
 
13
14
  # Define a table
14
15
  class Author:
15
-
16
16
  id = tf.auto_id()
17
17
  name = tf.string("name")
18
18
  created_at = tf.created_at()
@@ -56,39 +56,7 @@ with engine.connect() as conn:
56
56
  .values({Author.name: "John Doe"})
57
57
  .returning(Author.id)
58
58
  )
59
- author = next(conn.execute(qry).mappings())
60
- author_id = author[Author.id]
61
- assert author_id == 1
62
-
63
- # Insert book
64
- qry = (
65
- sa.insert(Book.Table)
66
- .values({Book.title: "My Book", Book.author_id: author_id})
67
- .returning(Book.id)
68
- )
69
- book = next(conn.execute(qry).mappings())
70
- assert book[Book.id] == 1
71
-
72
- # Query the data
73
- qry = sa.select(Author.name, Book.title).join(
74
- Book.Table,
75
- Book.author_id == Author.id,
76
- )
77
- result = conn.execute(qry).fetchall()
78
- assert result == [("John Doe", "My Book")], result
79
-
80
- # Create the tables
81
- engine = sa.create_engine("sqlite:///:memory:")
82
- tf.metadata.create_all(engine)
83
-
84
- with engine.connect() as conn:
85
- # Insert author
86
- qry = (
87
- sa.insert(Author.Table)
88
- .values({Author.name: "John Doe"})
89
- .returning(Author.id)
90
- )
91
- author = next(conn.execute(qry).mappings())
59
+ author = conn.execute(qry).mappings().first()
92
60
  author_id = author[Author.id]
93
61
  assert author_id == 1
94
62
 
@@ -98,7 +66,7 @@ with engine.connect() as conn:
98
66
  .values({Book.title: "My Book", Book.author_id: author_id})
99
67
  .returning(Book.id)
100
68
  )
101
- book = next(conn.execute(qry).mappings())
69
+ book = conn.execute(qry).mappings().first()
102
70
  assert book[Book.id] == 1
103
71
 
104
72
  # Query the data
@@ -106,7 +74,7 @@ with engine.connect() as conn:
106
74
  Book.Table,
107
75
  Book.author_id == Author.id,
108
76
  )
109
- result = conn.execute(qry).fetchall()
77
+ result = conn.execute(qry).all()
110
78
  assert result == [("John Doe", "My Book")], result
111
79
  ```
112
80
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = 'sqla-fancy-core'
3
- version = '1.0.1'
3
+ version = '1.0.2'
4
4
  description = 'SQLAlchemy core, but fancier'
5
5
  readme = 'README.md'
6
6
  requires-python = ">=3.7"
@@ -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:
@@ -50,7 +50,7 @@ def test_table_factory():
50
50
  .values({Author.name: "John Doe"})
51
51
  .returning(Author.id)
52
52
  )
53
- author = next(conn.execute(qry).mappings())
53
+ author = conn.execute(qry).mappings().first()
54
54
  author_id = author[Author.id]
55
55
  assert author_id == 1
56
56
 
@@ -60,7 +60,7 @@ def test_table_factory():
60
60
  .values({Book.title: "My Book", Book.author_id: author_id})
61
61
  .returning(Book.id)
62
62
  )
63
- book = next(conn.execute(qry).mappings())
63
+ book = conn.execute(qry).mappings().first()
64
64
  assert book[Book.id] == 1
65
65
 
66
66
  # Query the data
@@ -68,5 +68,5 @@ def test_table_factory():
68
68
  Book.Table,
69
69
  Book.author_id == Author.id,
70
70
  )
71
- result = conn.execute(qry).fetchall()
71
+ result = conn.execute(qry).all()
72
72
  assert result == [("John Doe", "My Book")], result
File without changes
File without changes