You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
700 B
35 lines
700 B
2 years ago
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
# @Time : 2023/6/22 21:37
|
||
|
# @Author : old tom
|
||
|
# @File : connect_transaction.py
|
||
|
# @Project : futool-db-lite
|
||
|
# @Desc :
|
||
|
from sqlalchemy import Connection
|
||
|
|
||
|
|
||
|
class TransactionFactory(object):
|
||
|
|
||
|
def __init__(self, conn: Connection):
|
||
|
self.conn = conn
|
||
|
|
||
|
def create_transaction(self):
|
||
|
return Transaction(self.conn)
|
||
|
|
||
|
|
||
|
class Transaction(object):
|
||
|
def __init__(self, conn: Connection):
|
||
|
self.conn = conn
|
||
|
|
||
|
def begin_transaction(self):
|
||
|
self.conn.begin()
|
||
|
|
||
|
def commit(self):
|
||
|
self.conn.commit()
|
||
|
|
||
|
def rollback(self):
|
||
|
self.conn.rollback()
|
||
|
|
||
|
def get_connection(self):
|
||
|
return self.conn
|