1010 Notification ,
1111 ProcessRecorder ,
1212 StoredEvent ,
13+ Subscription ,
1314 Tracking ,
1415)
1516from sqlalchemy import Column , Table , text
@@ -173,7 +174,7 @@ def insert_events(
173174 notification_ids = self ._insert_events (session , stored_events , ** kwargs )
174175 return notification_ids
175176
176- def max_notification_id (self ) -> int :
177+ def max_notification_id (self ) -> int | None :
177178 try :
178179 with self .transaction (commit = False ) as session :
179180 # record_class = cast(Type[StoredEventRecord], self.events_record_cls)
@@ -183,20 +184,26 @@ def max_notification_id(self) -> int:
183184 records = q [0 :1 ]
184185 return records [0 ].id
185186 except (IndexError , AssertionError ):
186- return 0
187+ return None
187188
188189 def select_notifications (
189190 self ,
190- start : int ,
191+ start : int | None ,
191192 limit : int ,
192- stop : Optional [ int ] = None ,
193+ stop : int | None = None ,
193194 topics : Sequence [str ] = (),
194- ) -> List [Notification ]:
195+ * ,
196+ inclusive_of_start : bool = True ,
197+ ) -> list [Notification ]:
195198 with self .transaction (commit = False ) as session :
196199 # record_class = cast(Type[StoredEventRecord], self.events_record_cls)
197200 record_class = self .events_record_cls
198201 q = session .query (record_class )
199- q = q .filter (record_class .id >= start )
202+ if start is not None :
203+ if inclusive_of_start :
204+ q = q .filter (record_class .id >= start )
205+ else :
206+ q = q .filter (record_class .id > start )
200207 if stop is not None :
201208 q = q .filter (record_class .id <= stop )
202209 if topics :
@@ -218,6 +225,12 @@ def select_notifications(
218225 ]
219226 return notifications
220227
228+ def subscribe (
229+ self , gt : int | None = None , topics : Sequence [str ] = ()
230+ ) -> Subscription [ApplicationRecorder ]:
231+ msg = "SQLAlchemyApplicationRecorder.subscribe() is not implemented"
232+ raise NotImplementedError (msg )
233+
221234
222235class SQLAlchemyProcessRecorder (SQLAlchemyApplicationRecorder , ProcessRecorder ):
223236 def __init__ (
@@ -260,20 +273,27 @@ def _insert_events(
260273 session .add (record )
261274 return notification_ids
262275
263- def max_tracking_id (self , application_name : str ) -> int :
276+ def max_tracking_id (self , application_name : str ) -> int | None :
264277 with self .transaction (commit = False ) as session :
265278 q = session .query (self .tracking_record_cls )
266279 q = q .filter (self .tracking_record_cls .application_name == application_name )
267280 q = q .order_by (self .tracking_record_cls .notification_id .desc ())
268281 try :
269282 max_id = q [0 ].notification_id
270283 except IndexError :
271- max_id = 0
284+ max_id = None
272285 return max_id
273286
274- def has_tracking_id (self , application_name : str , notification_id : int ) -> bool :
287+ def has_tracking_id (
288+ self , application_name : str , notification_id : int | None
289+ ) -> bool :
290+ if notification_id is None :
291+ return True
275292 with self .transaction (commit = False ) as session :
276293 q = session .query (self .tracking_record_cls )
277294 q = q .filter (self .tracking_record_cls .application_name == application_name )
278295 q = q .filter (self .tracking_record_cls .notification_id == notification_id )
279296 return bool (q .count ())
297+
298+ def insert_tracking (self , tracking : Tracking ) -> None :
299+ raise NotImplementedError
0 commit comments