#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time, threading, uuid, logging,functools
class Dict(dict):
def __init__(self, names=(), **kw):
super(Dict, self).__init__(**kw)
for k, v in zip(names, values):
self[k] = v
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError(r"'dict' object has no attribute'%s' " % key)
def __setattr__(self, key, value):
self[key] = value
def next_id(t=None):
if t is None:#
t = time.time()
return '%015d%s000' % (int(t * 1000), uuid.uuid4().hex)
def _profiling(start, sql =''):
t = time.time() - start
if t > 0.1:
logging.warning('[PROFILING] [DB] %s: %s' % (t,sql))
else:
logging.info('[PROFILING] [DB] %s: %s' %(t, sql))
class DEBrror(Exception):
pass
class MulticolumnsError(DBError):
pass
class _LasyConnection(object):
def __init__(self):
self.connection = None
def cursor(self):
if self.connection is None:
connection = engine.connect()
logging.info('open connection <%s>...' % hex(id(connection)))
self.connection = connection
return self.connection.cursor()
def commit(self):
self.connection.commit()
python之数据库db模块
最新推荐文章于 2024-08-17 21:29:39 发布
本文详细介绍了Python中用于数据库操作的db模块,包括如何连接数据库、执行SQL语句、处理查询结果以及关闭数据库连接。通过实例演示了基本的CRUD操作,适合初学者快速掌握Python数据库编程。
摘要由CSDN通过智能技术生成