-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (25 loc) · 871 Bytes
/
main.py
File metadata and controls
37 lines (25 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from ellar_sql import EllarSQLService, model
class User(model.Model):
id: model.Mapped[int] = model.mapped_column(model.Integer, primary_key=True)
username: model.Mapped[str] = model.mapped_column(
model.String, unique=True, nullable=False
)
email: model.Mapped[str] = model.mapped_column(model.String)
def main():
db_service = EllarSQLService(
databases="sqlite:///app.db",
echo=True,
)
db_service.create_all()
session = db_service.session_factory()
for i in range(50):
session.add(
User(username=f"username-{i + 1}", email=f"user{i + 1}doe@example.com")
)
session.commit()
rows = session.execute(model.select(User)).scalars()
all_users = [row.dict() for row in rows]
assert len(all_users) == 50
session.close()
if __name__ == "__main__":
main()