primer commit
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
import mysql.connector
|
||||
|
||||
class ConnMysql:
|
||||
def __init__(self, ret="conn", **kwargs):
|
||||
self.ret = ret
|
||||
self.conn = mysql.connector.connect(**kwargs, autocommit=False)
|
||||
if ret == "cursor":
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def __enter__(self):
|
||||
return self.cursor if self.ret == "cursor" else self.conn
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if self.ret == "cursor":
|
||||
self.cursor.close()
|
||||
self.conn.__exit__(exc_type, exc_val, exc_tb)
|
||||
Reference in New Issue
Block a user