当前位置: 首页>>代码示例>>Python>>正文


Python SqliteDatabase.get_conn方法代码示例

本文整理汇总了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)
开发者ID:JelleZijlstra,项目名称:taxonomy,代码行数:32,代码来源:base.py

示例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()
开发者ID:hyakugei,项目名称:lifelogger,代码行数:33,代码来源:database.py


注:本文中的peewee.SqliteDatabase.get_conn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。