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


Python aiosqlite.connect方法代码示例

本文整理汇总了Python中aiosqlite.connect方法的典型用法代码示例。如果您正苦于以下问题:Python aiosqlite.connect方法的具体用法?Python aiosqlite.connect怎么用?Python aiosqlite.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiosqlite的用法示例。


在下文中一共展示了aiosqlite.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __aenter__

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def __aenter__(self) -> "BaseSourceContext":
        self.__db = aiosqlite.connect(self.config.filename)
        self.db = await self.__db.__aenter__()
        self.db.row_factory = aiosqlite.Row
        # Create table for feature data
        await self.db.execute(
            "CREATE TABLE IF NOT EXISTS features ("
            "key TEXT PRIMARY KEY NOT NULL, "
            + (" REAL, ".join(self.FEATURE_COLS))
            + " REAL"
            ")"
        )
        # Create table for predictions
        await self.db.execute(
            "CREATE TABLE IF NOT EXISTS prediction ("
            "key TEXT PRIMARY KEY, " + "value TEXT, "
            "confidence REAL"
            ")"
        )
        return self 
开发者ID:intel,项目名称:dffml,代码行数:22,代码来源:custom_sqlite.py

示例2: start

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def start(self):
        # create the store (db) and full node instance
        self.connection = await aiosqlite.connect(self.db_path)
        self.block_store = await BlockStore.create(self.connection)
        self.full_node_store = await FullNodeStore.create(self.connection)
        self.sync_store = await SyncStore.create()
        self.coin_store = await CoinStore.create(self.connection)

        self.log.info("Initializing blockchain from disk")
        self.blockchain = await Blockchain.create(
            self.coin_store, self.block_store, self.constants
        )
        self.log.info(
            f"Blockchain initialized to tips at {[t.height for t in self.blockchain.get_current_tips()]}"
        )

        self.mempool_manager = MempoolManager(self.coin_store, self.constants)
        await self.mempool_manager.new_tips(await self.blockchain.get_full_tips())
        self.state_changed_callback = None 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:21,代码来源:full_node.py

示例3: respond_peers

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def respond_peers(
        self, request: introducer_protocol.RespondPeers
    ) -> OutboundMessageGenerator:
        if self.server is None or self.global_connections is None:
            return
        conns = self.global_connections
        for peer in request.peer_list:
            conns.peers.add(peer)

        # Pseudo-message to close the connection
        yield OutboundMessage(NodeType.INTRODUCER, Message("", None), Delivery.CLOSE)

        unconnected = conns.get_unconnected_peers(
            recent_threshold=self.config["recent_peer_threshold"]
        )
        to_connect = unconnected[: self._num_needed_peers()]
        if not len(to_connect):
            return

        self.log.info(f"Trying to connect to peers: {to_connect}")
        for peer in to_connect:
            asyncio.create_task(self.server.start_client(peer, None)) 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:24,代码来源:full_node.py

示例4: test_basic_coin_store

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def test_basic_coin_store(self):
        blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")

        db_path = Path("fndb_test.db")
        if db_path.exists():
            db_path.unlink()
        connection = await aiosqlite.connect(db_path)
        db = await CoinStore.create(connection)

        # Save/get block
        for block in blocks:
            await db.new_lca(block)
            unspent = await db.get_coin_record(block.header.data.coinbase.name())
            unspent_fee = await db.get_coin_record(block.header.data.fees_coin.name())
            assert block.header.data.coinbase == unspent.coin
            assert block.header.data.fees_coin == unspent_fee.coin

        await connection.close()
        Path("fndb_test.db").unlink() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:21,代码来源:test_coin_store.py

示例5: test_deadlock

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def test_deadlock(self):
        blocks = bt.get_consecutive_blocks(test_constants, 10, [], 9, b"0")
        db_filename = Path("blockchain_test.db")

        if db_filename.exists():
            db_filename.unlink()

        connection = await aiosqlite.connect(db_filename)
        db = await BlockStore.create(connection)
        tasks = []

        for i in range(10000):
            rand_i = random.randint(0, 10)
            if random.random() < 0.5:
                tasks.append(asyncio.create_task(db.add_block(blocks[rand_i])))
            if random.random() < 0.5:
                tasks.append(
                    asyncio.create_task(db.get_block(blocks[rand_i].header_hash))
                )
        await asyncio.gather(*tasks)
        await connection.close()
        db_filename.unlink() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:24,代码来源:test_block_store.py

示例6: test_basic_blockchain

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def test_basic_blockchain(self):
        db_path = Path("blockchain_test.db")
        if db_path.exists():
            db_path.unlink()
        connection = await aiosqlite.connect(db_path)
        coin_store = await CoinStore.create(connection)
        store = await BlockStore.create(connection)
        bc1 = await Blockchain.create(coin_store, store, test_constants)
        assert len(bc1.get_current_tips()) == 1
        genesis_block = bc1.get_current_tips()[0]
        assert genesis_block.height == 0
        assert (bc1.get_next_difficulty(genesis_block)) == genesis_block.weight
        assert bc1.get_next_min_iters(bc1.genesis) > 0

        await connection.close()
        bc1.shut_down() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:18,代码来源:test_blockchain.py

示例7: initial_blockchain

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def initial_blockchain(self):
        """
        Provides a list of 10 valid blocks, as well as a blockchain with 9 blocks added to it.
        """
        blocks = bt.get_consecutive_blocks(test_constants, 10, [], 10)
        db_path = Path("blockchain_test.db")
        if db_path.exists():
            db_path.unlink()
        connection = await aiosqlite.connect(db_path)
        store = await BlockStore.create(connection)
        coin_store = await CoinStore.create(connection)
        b: Blockchain = await Blockchain.create(coin_store, store, test_constants)
        for i in range(1, 9):
            result, removed, error_code = await b.receive_block(blocks[i])
            assert result == ReceiveBlockResult.ADDED_TO_HEAD
        yield (blocks, b)

        await connection.close() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:20,代码来源:test_blockchain.py

示例8: test_get_header_hashes

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def test_get_header_hashes(self):
        blocks = bt.get_consecutive_blocks(test_constants, 5, [], 9, b"0")
        db_path = Path("blockchain_test.db")
        if db_path.exists():
            db_path.unlink()
        connection = await aiosqlite.connect(db_path)
        coin_store = await CoinStore.create(connection)
        store = await BlockStore.create(connection)
        b: Blockchain = await Blockchain.create(coin_store, store, test_constants)

        for i in range(1, len(blocks)):
            await b.receive_block(blocks[i])
        header_hashes = b.get_header_hashes(blocks[-1].header_hash)
        assert len(header_hashes) == 6
        assert header_hashes == [block.header_hash for block in blocks]

        await connection.close()
        b.shut_down() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:20,代码来源:test_blockchain.py

示例9: database_update

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def database_update(sql_code, values=()):
    """A function that updates/inserts value/s to the database."""

    try:
        async with aiosqlite.connect("faithful_fleas/bot.db") as db:

            logger.info("Database connection made successfully.")
            await db.execute(sql_code, values)
            await db.commit()
            logger.info(f"SQL code executed successfully"
                        f"SQL_CODE: {sql_code}"
                        f"Values: {values}")

            return True

    except Exception as e:

        logging.error(f"An error occured in DATABASE_QUERY method,"
                      f"ERROR :\n {str(e)}")
        return False 
开发者ID:python-discord,项目名称:code-jam-5,代码行数:22,代码来源:sql_func.py

示例10: database_query

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def database_query(sql_code, values=()):
    """A function which can be used to query the database."""

    try:
        async with aiosqlite.connect("faithful_fleas/bot.db") as db:

            logger.info("Database connection made successfully.")

            async with db.execute(sql_code, values) as cursor:
                data = await cursor.fetchall()
                logger.info(f"SQL code executed successfully"
                            f"SQL_CODE: {sql_code}"
                            f"Values: {values}")
            return data

    except Exception as e:

        logging.error(f"An error occured in DATABASE_QUERY method,"
                      f"ERROR :\n {str(e)}") 
开发者ID:python-discord,项目名称:code-jam-5,代码行数:21,代码来源:sql_func.py

示例11: try_make_db

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def try_make_db() -> None:
    sqlite_db = get_db_path()
    if sqlite_db.exists():
        return

    with sqlite3.connect(sqlite_db) as conn:
        cur = conn.cursor()
        cur.execute(
            """CREATE TABLE posts (
            id INTEGER PRIMARY KEY,
            title TEXT,
            text TEXT,
            owner TEXT,
            editor TEXT,
            image BLOB)
        """
        )
        conn.commit() 
开发者ID:asvetlov,项目名称:us-pycon-2019-tutorial,代码行数:20,代码来源:01-error-middleware.py

示例12: try_make_db

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def try_make_db(sqlite_db: Path) -> None:
    if sqlite_db.exists():
        return

    with sqlite3.connect(sqlite_db) as conn:
        cur = conn.cursor()
        cur.execute(
            """CREATE TABLE posts (
            id INTEGER PRIMARY KEY,
            title TEXT,
            text TEXT,
            owner TEXT,
            editor TEXT,
            image BLOB)
        """
        )
        conn.commit() 
开发者ID:asvetlov,项目名称:us-pycon-2019-tutorial,代码行数:19,代码来源:server.py

示例13: __call__

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def __call__(self, config: Config) -> Optional[str]:
        async with aiosqlite.connect('db.db') as db:
            self.msg_fmt = await get_today(db)
        return await super().__call__(config) 
开发者ID:anthonywritescode,项目名称:twitch-chat-bot,代码行数:6,代码来源:bot.py

示例14: _on_connect

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def _on_connect(self) -> OutboundMessageGenerator:
        """
        Whenever we connect to another node / wallet, send them our current heads. Also send heads to farmers
        and challenges to timelords.
        """
        tips: List[Header] = self.blockchain.get_current_tips()
        for t in tips:
            request = full_node_protocol.NewTip(t.height, t.weight, t.header_hash)
            yield OutboundMessage(
                NodeType.FULL_NODE, Message("new_tip", request), Delivery.RESPOND
            )
        # If connected to a wallet, send the LCA
        lca = self.blockchain.lca_block
        new_lca = wallet_protocol.NewLCA(lca.header_hash, lca.height, lca.weight)
        yield OutboundMessage(
            NodeType.WALLET, Message("new_lca", new_lca), Delivery.RESPOND
        )

        # Send filter to node and request mempool items that are not in it
        my_filter = self.mempool_manager.get_filter()
        mempool_request = full_node_protocol.RequestMempoolTransactions(my_filter)

        yield OutboundMessage(
            NodeType.FULL_NODE,
            Message("request_mempool_transactions", mempool_request),
            Delivery.RESPOND,
        )

        # Update farmers and timelord with most recent information
        async for msg in self._send_challenges_to_timelords(Delivery.RESPOND):
            yield msg
        async for msg in self._send_tips_to_farmers(Delivery.RESPOND):
            yield msg 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:35,代码来源:full_node.py

示例15: test_set_spent

# 需要导入模块: import aiosqlite [as 别名]
# 或者: from aiosqlite import connect [as 别名]
def test_set_spent(self):
        blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")

        db_path = Path("fndb_test.db")
        if db_path.exists():
            db_path.unlink()
        connection = await aiosqlite.connect(db_path)
        db = await CoinStore.create(connection)

        # Save/get block
        for block in blocks:
            await db.new_lca(block)
            unspent = await db.get_coin_record(block.header.data.coinbase.name())
            unspent_fee = await db.get_coin_record(block.header.data.fees_coin.name())
            assert block.header.data.coinbase == unspent.coin
            assert block.header.data.fees_coin == unspent_fee.coin

            await db.set_spent(unspent.coin.name(), block.height)
            await db.set_spent(unspent_fee.coin.name(), block.height)
            unspent = await db.get_coin_record(block.header.data.coinbase.name())
            unspent_fee = await db.get_coin_record(block.header.data.fees_coin.name())
            assert unspent.spent == 1
            assert unspent_fee.spent == 1

        await connection.close()
        Path("fndb_test.db").unlink() 
开发者ID:Chia-Network,项目名称:chia-blockchain,代码行数:28,代码来源:test_coin_store.py


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