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

Python serializer.dumps函数代码示例

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

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



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

示例1: test_query_one

    def test_query_one(self):
        q = Session.query(User).\
                filter(User.name == 'ed').\
                    options(joinedload(User.addresses))

        q2 = serializer.loads(
                    serializer.dumps(q, -1),
                            users.metadata, Session)
        def go():
            eq_(q2.all(), [
                    User(name='ed', addresses=[Address(id=2),
                    Address(id=3), Address(id=4)])])

        self.assert_sql_count(testing.db, go, 1)

        eq_(q2.join(User.addresses).filter(Address.email
            == '[email protected]').value(func.count('*')), 1)
        u1 = Session.query(User).get(8)
        q = Session.query(Address).filter(Address.user
                == u1).order_by(desc(Address.email))
        q2 = serializer.loads(serializer.dumps(q, -1), users.metadata,
                              Session)
        eq_(q2.all(), [Address(email='[email protected]'),
            Address(email='[email protected]'),
            Address(email='[email protected]')])
开发者ID:idella,项目名称:sqlalchemy,代码行数:25,代码来源:test_serializer.py


示例2: test_query

    def test_query(self):
        q = Session.query(User).filter(User.name == "ed").options(eagerload(User.addresses))
        eq_(q.all(), [User(name="ed", addresses=[Address(id=2), Address(id=3), Address(id=4)])])

        q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, Session)

        def go():
            eq_(q2.all(), [User(name="ed", addresses=[Address(id=2), Address(id=3), Address(id=4)])])

        self.assert_sql_count(testing.db, go, 1)

        eq_(q2.join(User.addresses).filter(Address.email == "[email protected]").value(func.count("*")), 1)

        u1 = Session.query(User).get(8)

        q = Session.query(Address).filter(Address.user == u1).order_by(desc(Address.email))
        q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, Session)

        eq_(q2.all(), [Address(email="[email protected]"), Address(email="[email protected]"), Address(email="[email protected]")])

        q = Session.query(User).join(User.addresses).filter(Address.email.like("%fred%"))
        q2 = serializer.loads(serializer.dumps(q, -1), users.metadata, Session)
        eq_(q2.all(), [User(name="fred")])

        eq_(list(q2.values(User.id, User.name)), [(9, u"fred")])
开发者ID:obeattie,项目名称:sqlalchemy,代码行数:25,代码来源:test_serializer.py


示例3: get_data

 def get_data(self):
     """Go through every mapped table and dumps the data"""
     data = dict()
     for model_class in self.get_mapped_classes():
         query = self.db_session.query(model_class)
         data[model_class.__name__] = dumps(query.all())
     return data
开发者ID:YukSeungChan,项目名称:alchemydumps,代码行数:7,代码来源:database.py


示例4: test_query_two

 def test_query_two(self):
     q = Session.query(User).join(User.addresses).\
         filter(Address.email.like('%fred%'))
     q2 = serializer.loads(serializer.dumps(q, -1), users.metadata,
                           Session)
     eq_(q2.all(), [User(name='fred')])
     eq_(list(q2.values(User.id, User.name)), [(9, 'fred')])
开发者ID:rlugojr,项目名称:sqlalchemy,代码行数:7,代码来源:test_serializer.py


示例5: test_expression

    def test_expression(self):

        expr = select([users]).select_from(users.join(addresses)).limit(5)
        re_expr = serializer.loads(serializer.dumps(expr, -1), users.metadata, None)
        eq_(str(expr), str(re_expr))

        assert re_expr.bind is testing.db
        eq_(re_expr.execute().fetchall(), [(7, u"jack"), (8, u"ed"), (8, u"ed"), (8, u"ed"), (9, u"fred")])
开发者ID:obeattie,项目名称:sqlalchemy,代码行数:8,代码来源:test_serializer.py


示例6: get_data

 def get_data(self):
     """Go through every mapped class and dumps the data"""
     db = self.db()
     data = dict()
     for model in self.get_mapped_classes():
         query = db.session.query(model)
         data[model.__name__] = dumps(query.all())
     return data
开发者ID:cuducos,项目名称:alchemydumps,代码行数:8,代码来源:database.py


示例7: _put_remote

 def _put_remote(self,otype,obj,oid,hid):
     remotehost = self.datacon.db.get(Host,hid)
     self.location[otype][oid] = remotehost
     res = self.send_request_owner(remotehost, otype.__name__, oid,"put", newobj=dumps(obj))
     logger.debug("[obm]: Inserting remotely at " + remotehost + " the object: " + str(obj))
     if res == "OK":
         return True
     else:
         logger.error(res)
开发者ID:Mondego,项目名称:rcat,代码行数:9,代码来源:obm.py


示例8: test_aliases

    def test_aliases(self):
        u7, u8, u9, u10 = Session.query(User).order_by(User.id).all()

        ualias = aliased(User)
        q = Session.query(User, ualias).join((ualias, User.id < ualias.id)).filter(User.id<9).order_by(User.id, ualias.id)

        q2 = serializer.loads(serializer.dumps(q), users.metadata, Session)
        
        eq_(list(q2.all()), [(u7, u8), (u7, u9), (u7, u10), (u8, u9), (u8, u10)])
开发者ID:jrus,项目名称:sqlalchemy,代码行数:9,代码来源:serializer.py


示例9: dump

def dump(destination):
    dump_models = []  # List of models you want to dump
    serialized = list()
    for model in dump_models:
        print('Dumping {}'.format(model))
        serialized.append(unicode(dumps(db.session.query(model).all()), errors='ignore'))
    with open(destination, 'w') as f:
        f.writelines(json.dumps(serialized))
    print('Done.')
开发者ID:itkpi,项目名称:events-admin,代码行数:9,代码来源:manage.py


示例10: test_orm_join

    def test_orm_join(self):
        from sqlalchemy.orm.util import join

        j = join(User, Address, User.addresses)

        j2 = serializer.loads(serializer.dumps(j, -1), users.metadata)
        assert j2.left is j.left
        assert j2.right is j.right
        assert j2._target_adapter._next
开发者ID:idella,项目名称:sqlalchemy,代码行数:9,代码来源:test_serializer.py


示例11: backup_everything

def backup_everything(session):
    meta = get_declarative_base().metadata
    backupdict = {}
    for table in reversed(meta.sorted_tables):
        query = session.query(table)
        queryresults = query.all()
        backupdict[table.name] = dumps(queryresults)

    return backupdict
开发者ID:Rouxion,项目名称:svaksvat,代码行数:9,代码来源:orm.py


示例12: main

def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    menu_items = DBSession.query(MenuItem)
    serialized_menu_items = dumps(menu_items.all())
    menus = DBSession.query(Menu)
    serialized_menus = dumps(menus.all()) 
    allergens = DBSession.query(Allergen)
    serialized_allergens = dumps(allergens.all())
    serialized_data = {"menus" : serialized_menus,
                       "menu_items" : serialized_menu_items,
                       "allergens" : serialized_allergens}
    file = open('./db_backup.txt', 'w+')
    pickle.dump(serialized_data, file)
开发者ID:tinawen,项目名称:menu,代码行数:18,代码来源:dumpdb.py


示例13: test_annotated_one

    def test_annotated_one(self):
        j = join(users, addresses)._annotate({"foo": "bar"})
        query = select([addresses]).select_from(
            j
        )

        str(query)
        for prot in pickle_protocols():
            pickled_failing = serializer.dumps(
                j, prot)
            serializer.loads(pickled_failing, users.metadata, None)
开发者ID:anti-social,项目名称:sqlalchemy,代码行数:11,代码来源:test_serializer.py


示例14: test_query_three

    def test_query_three(self):
        ua = aliased(User)
        q = \
            Session.query(ua).join(ua.addresses).\
               filter(Address.email.like('%fred%'))
        q2 = serializer.loads(serializer.dumps(q, -1), users.metadata,
                              Session)
        eq_(q2.all(), [User(name='fred')])

        # try to pull out the aliased entity here...
        ua_2 = q2._entities[0].entity_zero.entity
        eq_(list(q2.values(ua_2.id, ua_2.name)), [(9, 'fred')])
开发者ID:idella,项目名称:sqlalchemy,代码行数:12,代码来源:test_serializer.py


示例15: saveToAppLog

    def saveToAppLog(self):
        if self.action:
            if self.value:
                esito = " ERRATO"
                how = "E"
            else:
                esito = " CORRETTO"
                how = "I"
            message = self.action + esito
        else:
            if params["session"].dirty:
                message = "UPDATE " + self.dao.__class__.__name__
            elif params["session"].new:
                message = "INSERT " + self.dao.__class__.__name__
            elif params["session"].deleted:
                message = "DELETE " + self.dao.__class__.__name__
            else:
                message = "UNKNOWN ACTION"

        when = datetime.datetime.now()
        where = params["schema"]
        whoID = params["usernameLoggedList"][0]
        utentedb = params["usernameLoggedList"][3]
        utente = params["usernameLoggedList"][1]

        if self.action:
            whatstr = self.value
        else:
            salvo = self.commit()
            if salvo:
                how = "I"
            else:
                how = "E"
            mapper = object_mapper(self.dao)
            pk = mapper.primary_key_from_instance(self.dao)
            whatstr = str(pk)

        app = ApplicationLog()
        app.schema = where
        app.message = message
        app.level = how
        print dumps(whatstr)
        app.strvalue = dumps(whatstr)
        app.registrazion_date = when
        app.utentedb = utentedb
        app.id_utente = whoID
        app.pkid = dumps(whatstr)
        print dumps(self.dao)
        app.object = dumps(self.dao)
        params["session"].add(app)
        self.commit()
        print "[LOG] %s id: %s da %s in %s in data %s" % (message, whatstr, utente, where, when.strftime("%d/%m/%Y"))
开发者ID:Alwnikrotikz,项目名称:promogest,代码行数:52,代码来源:ApplicationLog.py


示例16: test_unicode

    def test_unicode(self):
        m = MetaData()
        t = Table(ue('\u6e2c\u8a66'), m,
                Column(ue('\u6e2c\u8a66_id'), Integer))

        expr = select([t]).where(t.c[ue('\u6e2c\u8a66_id')] == 5)

        expr2 = serializer.loads(serializer.dumps(expr, -1), m)

        self.assert_compile(
            expr2,
            ue('SELECT "\u6e2c\u8a66"."\u6e2c\u8a66_id" FROM "\u6e2c\u8a66" '
                'WHERE "\u6e2c\u8a66"."\u6e2c\u8a66_id" = :\u6e2c\u8a66_id_1'),
            dialect="default"
        )
开发者ID:Attsun1031,项目名称:sqlalchemy,代码行数:15,代码来源:test_serializer.py


示例17: _backup_database

def _backup_database(filepath):

    table_classes = Base._decl_class_registry.values()
    session = Session()

    for table_class in table_classes:
        if hasattr(table_class, '__tablename__'):
            query = session.query(table_class)
            serialized_data = dumps(query.all())

            new_filepath = filepath + 'database/' + table_class.__tablename__

            with open(new_filepath, 'w') as text_file:
                text_file.write(serialized_data)

    return
开发者ID:nstoik,项目名称:farm_device,代码行数:16,代码来源:backup.py


示例18: on_after_flush

    def on_after_flush(self, app, session):
        """broadcast models events into the data-models channel

        channel: data-models
        event: <model-identifier>.<event>
        data: JSON representation of model

        <event> is one of ``create``, ``update``, ``delete``
        """
        request = session.request
        if not app.channels or not request:
            return
        for instance, event in session.changes():
            app.channels.publish(
                app.config['CHANNEL_DATAMODEL'],
                '%s.%s' % (instance.__class__.__name__.lower(), event),
                dumps(instance)
            )
开发者ID:quantmind,项目名称:lux,代码行数:18,代码来源:__init__.py


示例19: __init__

 def __init__(self, expression=None, name=None):
     if expression is not None:
         self.expression = expression
         blob = dumps(expression)
         self.expr_blob = blob
     self.name = name
开发者ID:NSkelsey,项目名称:research,代码行数:6,代码来源:dbdb.py


示例20: items_to_cache

 def items_to_cache(self, query_id, items):
     if self.cache_enabled:
         self.cache.set(self.items_key(query_id), dumps(items),
                        time=self.cache_timeout)
开发者ID:SlivTime,项目名称:cms34,代码行数:4,代码来源:cached_db.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python serializer.loads函数代码示例发布时间:2022-05-27
下一篇:
Python orderinglist.ordering_list函数代码示例发布时间: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