Context-managed SQLite connection that commits on clean exit and always closes.
()
| 20 | |
| 21 | @contextmanager |
| 22 | def db_conn(): |
| 23 | """Context-managed SQLite connection that commits on clean exit and always closes.""" |
| 24 | conn = get_db() |
| 25 | try: |
| 26 | yield conn |
| 27 | conn.commit() |
| 28 | except Exception: |
| 29 | try: |
| 30 | conn.rollback() |
| 31 | except Exception: |
| 32 | pass |
| 33 | raise |
| 34 | finally: |
| 35 | conn.close() |
| 36 | |
| 37 | |
| 38 | _BASE_SCHEMA = """ |