File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ def get_session(self):
25
25
return sqlmodel .Session (self .db_engine )
26
26
27
27
def clear_database (self ):
28
+ """
29
+ Delete the database and rebuild database model.
30
+ """
28
31
self .db_path .unlink ()
29
32
self .db_engine = sqlmodel .create_engine (f"sqlite:///{ self .db_path } " , echo = True )
30
33
sqlmodel .SQLModel .metadata .create_all (self .db_engine )
@@ -34,5 +37,27 @@ def get_user(self):
34
37
user = session .exec (sqlmodel .select (model .User )).one ()
35
38
return user
36
39
40
+ def store_all (self , entities ):
41
+ """Store a collection of entities in the database."""
42
+ with self .get_session () as session :
43
+ for entity in entities :
44
+ session .add (entity )
45
+ session .commit ()
46
+
47
+ def retrieve_all (self , entity_type ):
48
+ with self .get_session () as session :
49
+ entities = session .exec (
50
+ sqlmodel .select (entity_type ),
51
+ ).all ()
52
+ return entities
53
+
54
+ @property
55
+ def contracts (self ):
56
+ with self .get_session () as session :
57
+ contracts = session .exec (
58
+ sqlmodel .select (model .Contract ),
59
+ ).all ()
60
+ return contracts
61
+
37
62
38
63
the_app = App ()
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ class User(SQLModel, table=True):
108
108
bank_account_id : Optional [int ] = Field (default = None , foreign_key = "bankaccount.id" )
109
109
bank_account : Optional ["BankAccount" ] = Relationship (back_populates = "user" )
110
110
# TODO: path to logo image
111
- logo : str
111
+ logo : Optional [ str ]
112
112
113
113
114
114
class ICloudAccount (SQLModel , table = True ):
@@ -135,7 +135,7 @@ class BankAccount(SQLModel, table=True):
135
135
name : str
136
136
IBAN : str
137
137
BIC : str
138
- username : str # online banking user name
138
+ # username: str # online banking user name
139
139
user : User = Relationship (back_populates = "bank_account" )
140
140
141
141
@@ -192,7 +192,7 @@ class Contract(SQLModel, table=True):
192
192
)
193
193
currency : str # TODO: currency representation
194
194
unit : TimeUnit = Field (sa_column = sqlalchemy .Column (sqlalchemy .Enum (TimeUnit )))
195
- volume : int = Field (
195
+ volume : Optional [ int ] = Field (
196
196
description = "Number of units agreed on" ,
197
197
)
198
198
term_of_payment : Optional [int ] = Field (
You can’t perform that action at this time.
0 commit comments