Coverage for src/typedal/for_py4web.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-25 14:50 +0200

1""" 

2ONLY USE IN COMBINATION WITH PY4WEB! 

3""" 

4 

5from typing import Any 

6 

7import threadsafevariable 

8from py4web.core import ICECUBE, Fixture 

9 

10from .core import TypeDAL 

11 

12 

13class DAL(TypeDAL, Fixture): # pragma: no cover 

14 """ 

15 Fixture similar to the py4web pydal fixture, but for typedal. 

16 """ 

17 

18 def on_request(self, _: dict[str, Any]) -> None: 

19 """ 

20 Make sure there is a database connection when a request comes in. 

21 """ 

22 self.get_connection_from_pool_or_new() 

23 threadsafevariable.ThreadSafeVariable.restore(ICECUBE) 

24 

25 def on_error(self, _: dict[str, Any]) -> None: 

26 """ 

27 Rollback db on error. 

28 """ 

29 self.recycle_connection_in_pool_or_close("rollback") 

30 

31 def on_success(self, _: dict[str, Any]) -> None: 

32 """ 

33 Commit db on success. 

34 """ 

35 self.recycle_connection_in_pool_or_close("commit")