コード例 #1
0
    def db(self, database: str) -> None:
        """
        A property that returns the new using database being queried.

        :param database: the name of the AsyncIOMotorDatabase we want to use.
        """
        self._db: AsyncIOMotorDatabase = AsyncIOMotorDatabase(self._client, database)
        self._db.with_options(**vars(self._use_consistency))
コード例 #2
0
    def test_database(self):
        # Test that we can create a db directly, not just get on from
        # AsyncIOMotorClient.
        db = AsyncIOMotorDatabase(self.cx, 'motor_test')

        # Make sure we got the right DB and it can do an operation.
        self.assertEqual('motor_test', db.name)
        yield from db.test_collection.remove()
        yield from db.test_collection.insert({'_id': 1})
        doc = yield from db.test_collection.find_one({'_id': 1})
        self.assertEqual(1, doc['_id'])
コード例 #3
0
    async def test_database(self):
        # Test that we can create a db directly, not just get on from
        # AsyncIOMotorClient.
        db = AsyncIOMotorDatabase(self.cx, "motor_test")

        # Make sure we got the right DB and it can do an operation.
        self.assertEqual("motor_test", db.name)
        await db.test_collection.delete_many({})
        await db.test_collection.insert_one({"_id": 1})
        doc = await db.test_collection.find_one({"_id": 1})
        self.assertEqual(1, doc["_id"])