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

5 statements  

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

1""" 

2ONLY USE IN COMBINATION WITH PY4WEB! 

3""" 

4 

5from typing import Any 

6 

7import json_fix # noqa: F401 

8import threadsafevariable 

9from py4web.core import ICECUBE, Fixture 

10 

11from .core import TypeDAL 

12 

13 

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

15 """ 

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

17 """ 

18 

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

20 """ 

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

22 """ 

23 self.get_connection_from_pool_or_new() 

24 threadsafevariable.ThreadSafeVariable.restore(ICECUBE) 

25 

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

27 """ 

28 Rollback db on error. 

29 """ 

30 self.recycle_connection_in_pool_or_close("rollback") 

31 

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

33 """ 

34 Commit db on success. 

35 """ 

36 self.recycle_connection_in_pool_or_close("commit")