示例#1
0
文件: appdb.py 项目: Yoda-x/zigpy
def aiosqlite_connect(
    database: str, iter_chunk_size: int = 64, **kwargs
) -> aiosqlite.Connection:
    """
    Copy of the the `aiosqlite.connect` function that connects using either the built-in
    `sqlite3` module or the imported `pysqlite3` module.
    """

    return aiosqlite.Connection(
        connector=lambda: sqlite3.connect(str(database), **kwargs),
        iter_chunk_size=iter_chunk_size,
    )
示例#2
0
def connect(database: Union[str, Path],
            *,
            loop: asyncio.AbstractEventLoop = None,
            **kwargs: Any) -> aiosqlite.Connection:
    """Create and return a connection proxy to the sqlite database."""
    if loop is None:
        loop = asyncio.get_event_loop()

    def connector() -> sqlite3.Connection:
        conn = sqlite3.connect(str(database), **kwargs)
        conn.set_trace_callback(print)
        conn.row_factory = sqlite3.Row
        return conn

    return aiosqlite.Connection(connector, loop)