本文整理汇总了Python中peewee.SqliteDatabase.get_conn方法的典型用法代码示例。如果您正苦于以下问题:Python SqliteDatabase.get_conn方法的具体用法?Python SqliteDatabase.get_conn怎么用?Python SqliteDatabase.get_conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee.SqliteDatabase
的用法示例。
在下文中一共展示了SqliteDatabase.get_conn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SqliteDatabase
# 需要导入模块: from peewee import SqliteDatabase [as 别名]
# 或者: from peewee.SqliteDatabase import get_conn [as 别名]
)
from ... import adt, config, events, getinput
settings = config.get_options()
if settings.use_sqlite:
database = SqliteDatabase(str(settings.db_filename))
else:
database = MySQLDatabase(
settings.db_name,
user=settings.db_username,
passwd=settings.db_password,
charset="utf8",
)
database.get_conn().ping(True)
ModelT = TypeVar("ModelT", bound="BaseModel")
_getters: Dict[Tuple[Type[Model], str], "_NameGetter[Any]"] = {}
class _FieldEditor(object):
"""For easily editing fields. This is exposed as object.e."""
def __init__(self, instance: Any = None) -> None:
self.instance = instance
def __get__(self, instance: Any, instance_type: Any) -> "_FieldEditor":
return self.__class__(instance)
示例2: regexp
# 需要导入模块: from peewee import SqliteDatabase [as 别名]
# 或者: from peewee.SqliteDatabase import get_conn [as 别名]
# Add regex function to SqliteDatabase
OP_REGEXP = 'regexp'
def regexp(lhs, rhs):
return Expression(lhs, 'regexp', rhs)
SqliteDatabase.register_ops({OP_REGEXP: 'REGEXP'})
# Create database reference
db = SqliteDatabase(DB_PATH)
# Define REGEXP function in sqlite database connection
conn = db.get_conn()
def regex_matches(regex, string):
return bool(re.search(regex, string, flags=re.IGNORECASE))
conn.create_function('REGEXP', 2, regex_matches)
# Models
class Event(Model):
summary = CharField()
start = DateTimeField()
end = DateTimeField()
description = CharField()