• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python database.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mongotor.database.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: update

    def update(self, document=None, safe=True, callback=None):
        """Update a document

        :Parameters:
        - `safe` (optional): safe update operation
        - `callback` : method which will be called when update is finished
        """
        pre_update.send(instance=self)

        if not document:
            document = self.as_dict()

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)
        spec = {'_id': self._id}

        message_update = message.update(collection_name, False,
                False, spec, document, safe, {})

        response, error = yield gen.Task(database.send_message, message_update)

        post_update.send(instance=self)

        if callback:
            callback((response, error))
开发者ID:pauloalem,项目名称:mongotor,代码行数:25,代码来源:collection.py


示例2: test_not_raise_when_database_was_initiated

    def test_not_raise_when_database_was_initiated(self):
        """[DatabaseTestCase] - Not raises ValueError when connect to inititated database"""

        database1 = Database.connect("localhost:27027", dbname="test")
        database2 = Database.connect("localhost:27027", dbname="test")

        database1.should.be.equal(database2)
开发者ID:robert-zaremba,项目名称:mongotor,代码行数:7,代码来源:test_database.py


示例3: tearDown

    def tearDown(self):
        super(SignalTestCase, self).tearDown()

        class CollectionTest(Collection):
            __collection__ = "collection_test"

        CollectionTest.objects.truncate(callback=self.stop)
        self.wait()
        Database.disconnect()
开发者ID:sansa1839,项目名称:mongotor,代码行数:9,代码来源:test_signal.py


示例4: _insert_document

    def _insert_document(self, document):
        message_insert = message.insert('mongotor_test.cursor_test', [document],
            True, True, {})

        node = Database().get_node(ReadPreference.PRIMARY)
        node.connection(self.stop)
        connection = self.wait()

        connection.send_message(message_insert, with_last_error=True, callback=self.stop)
        self.wait()
开发者ID:abdelouahabb,项目名称:mongotor,代码行数:10,代码来源:test_cursor.py


示例5: tearDown

    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test',
            {}, True, {})
        Database().send_message(message_delete, callback=self.stop)
        self.wait()

        Database.disconnect()
开发者ID:sansa1839,项目名称:mongotor,代码行数:10,代码来源:test_cursor.py


示例6: test_raises_erro_when_use_collection_with_not_initialized_database

    def test_raises_erro_when_use_collection_with_not_initialized_database(self):
        """[CollectionTestCase] - Raises DatabaseError when use collection with a not initialized database"""

        class CollectionTest(Collection):
            __collection__ = 'collection_test'

        Database.disconnect()
        CollectionTest().save.when.called_with(callback=None) \
            .throw(DatabaseError, 'you must be initialize database before perform this action')

        Database.init(["localhost:27027", "localhost:27028"], dbname='test')
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:11,代码来源:test_collection.py


示例7: test_raises_error_when_mode_is_secondary_and_secondary_is_down

    def test_raises_error_when_mode_is_secondary_and_secondary_is_down(self):
        """[ReplicaSetTestCase] - Raise error when mode is secondary and secondary is down"""
        os.system('make mongo-kill > /dev/null 2>&1')
        os.system('make mongo-start-node1')
        os.system('make mongo-start-arbiter')

        time.sleep(2)

        Database.connect(["localhost:27027", "localhost:27028"], dbname='test')
        Database().send_message.when.called_with('',
            read_preference=ReadPreference.SECONDARY)\
            .throw(DatabaseError)

        os.system('make mongo-start-node2')
        time.sleep(10)
开发者ID:sansa1839,项目名称:mongotor,代码行数:15,代码来源:test_replicaset.py


示例8: tearDown

    def tearDown(self):
        super(CursorTestCase, self).tearDown()

        # delete all documents
        message_delete = message.delete('mongotor_test.cursor_test',
            {}, True, {})

        node = Database().get_node(ReadPreference.PRIMARY)
        node.connection(self.stop)
        connection = self.wait()

        connection.send_message(message_delete, with_last_error=True, callback=self.stop)
        self.wait()

        Database.disconnect()
开发者ID:abdelouahabb,项目名称:mongotor,代码行数:15,代码来源:test_cursor.py


示例9: test_send_test_message

    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.connect(["localhost:27027", "localhost:27028"], dbname="test")

        object_id = ObjectId()
        message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})

        Database().send_message(message_test, callback=self.stop)
        response, error = self.wait()

        result = response["data"][0]

        result["oid"].should.be(object_id)
        result["ok"].should.be(1.0)
        result["str"].should.be(str(object_id))
开发者ID:sansa1839,项目名称:mongotor,代码行数:16,代码来源:test_database.py


示例10: test_raises_error_when_could_not_find_node

    def test_raises_error_when_could_not_find_node(self):
        """[DatabaseTestCase] - Raises DatabaseError when could not find valid nodes"""

        database = Database.connect(["localhost:27030"], dbname="test")
        database.send_message.when.called_with("", callback=None).throw(
            DatabaseError, "could not find an available node"
        )
开发者ID:robert-zaremba,项目名称:mongotor,代码行数:7,代码来源:test_database.py


示例11: test_configure_nodes

    def test_configure_nodes(self):
        """[ReplicaSetTestCase] - Configure nodes"""

        Database.connect(["localhost:27027", "localhost:27028"], dbname='test')

        master_node = ReadPreference.select_primary_node(Database()._nodes)
        secondary_node = ReadPreference.select_node(Database()._nodes, mode=ReadPreference.SECONDARY)

        master_node.host.should.be('localhost')
        master_node.port.should.be(27027)

        secondary_node.host.should.be('localhost')
        secondary_node.port.should.be(27028)

        nodes = Database()._nodes
        nodes.should.have.length_of(2)
开发者ID:sansa1839,项目名称:mongotor,代码行数:16,代码来源:test_replicaset.py


示例12: test_insert_and_find_with_elemmatch

    def test_insert_and_find_with_elemmatch(self):
        documents = [{
            '_id': ObjectId(),
            'name': 'should be name 1',
            'comment': [{'author': 'joe'}, {'author': 'ana'}]
        }, {
            '_id': ObjectId(),
            'name': 'should be name 2',
            'comment': [{'author': 'ana'}]
        }]

        db = Database.init(["localhost:27027", "localhost:27028"],
            dbname='test')
        db.articles.insert(documents, callback=self.stop)
        self.wait()

        db.articles.find({'comment.author': 'joe'}, ('comment.$.author', ), limit=-1, callback=self.stop)

        result, _ = self.wait()

        keys = result.keys()
        keys.sort()

        keys.should.be.equal(['_id', 'comment'])

        str(result['_id']).should.be.equal(str(documents[0]['_id']))
        result['comment'].should.have.length_of(1)
        result['comment'][0]['author'].should.be.equal('joe')
        _.should.be.none
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:29,代码来源:test_client.py


示例13: test_run_command

    def test_run_command(self):
        """[DatabaseTestCase] - Run a database command"""

        database = Database.connect(["localhost:27027"], dbname="test")
        database.command("ismaster", callback=self.stop)

        response, error = self.wait()
        response["ok"].should.be.ok
开发者ID:robert-zaremba,项目名称:mongotor,代码行数:8,代码来源:test_database.py


示例14: test_check_connections_when_use_cursors

    def test_check_connections_when_use_cursors(self):
        """[ConnectionPoolTestCase] - check connections when use cursors"""
        db = Database.init('localhost:27027', dbname='test', maxconnections=10, maxusage=29)

        try:
            for i in range(2):
                db.cards.insert({'_id': ObjectId(), 'range': i}, callback=self.stop)
                self.wait()

            db._nodes[0].pool._connections.should.be.equal(0)

            db.cards.find({}, callback=self.stop)
            self.wait()

            db._nodes[0].pool._connections.should.be.equal(0)
        finally:
            Database.disconnect()
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:17,代码来源:test_pool.py


示例15: test_send_test_message

    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.connect(["localhost:27017"], dbname='test')

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        Database().send_message(message_test, self.stop)
        response, error = self.wait()

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
开发者ID:pauloalem,项目名称:mongotor,代码行数:17,代码来源:test_database.py


示例16: test_run_command

    def test_run_command(self):
        """[DatabaseTestCase] - Run a database command"""

        database = Database.init(["localhost:27027"], dbname='test')
        database.command('ismaster', callback=self.stop)

        response, error = self.wait()
        response['ok'].should.be.ok
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:8,代码来源:test_database.py


示例17: test_send_test_message

    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.init(["localhost:27027", "localhost:27028"], dbname='test')

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        Database().send_message(message_test, callback=self.stop)
        response, _ = self.wait()
        response = helpers._unpack_response(response)

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:18,代码来源:test_database.py


示例18: test_raises_error_when_could_not_find_node

    def test_raises_error_when_could_not_find_node(self):
        """[DatabaseTestCase] - Raises DatabaseError when could not find valid nodes"""

        database = Database.init(["localhost:27030"], dbname='test')

        def send_message():
            database.send_message('', callback=self.stop)
            self.wait()

        send_message.when.called.throw(DatabaseError, 'could not find an available node')
开发者ID:Arion-Dsh,项目名称:mongotor,代码行数:10,代码来源:test_database.py


示例19: save

    def save(self, safe=True, callback=None):
        """Save a document

        :Parameters:
        - `safe` (optional): safe insert operation 
        - `callback` : method which will be called when save is finished
        """
        pre_save.send(instance=self)

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)

        message_insert = message.insert(collection_name, [self.as_dict()],
            True, safe, {})

        response, error = yield gen.Task(database.send_message, message_insert)

        post_save.send(instance=self)

        if callback:
            callback((response, error))
开发者ID:pauloalem,项目名称:mongotor,代码行数:21,代码来源:collection.py


示例20: remove

    def remove(self, safe=True, callback=None):
        """Remove a document

        :Parameters:
        - `safe` (optional): safe remove operation
        - `callback` : method which will be called when remove is finished
        """
        pre_remove.send(instance=self)

        database = Database()
        collection_name = database.get_collection_name(self.__collection__)

        message_delete = message.delete(collection_name, {'_id': self._id},
            safe, {})

        response, error = yield gen.Task(database.send_message, message_delete)

        post_remove.send(instance=self)

        if callback:
            callback((response, error))
开发者ID:pauloalem,项目名称:mongotor,代码行数:21,代码来源:collection.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
下一篇:
Python mongokit.Connection类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap