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


Python postgres_ext.BinaryJSONField方法代码示例

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


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

示例1: field_class_to_schematics_field

# 需要导入模块: from playhouse import postgres_ext [as 别名]
# 或者: from playhouse.postgres_ext import BinaryJSONField [as 别名]
def field_class_to_schematics_field(field: peewee.Field) -> BaseType:
    if isinstance(field, peewee.ForeignKeyField):
        field = field.rel_field

    kwargs = {}

    # 检查是否 require
    if not ((field.default is not None) or field.null or field.sequence or isinstance(field, peewee.AutoField)):
        kwargs['required'] = True

    if field.help_text:
        kwargs['metadata'] = {'description': field.help_text}

    if isinstance(field, peewee.IntegerField):
        return IntType(**kwargs)
    elif isinstance(field, peewee.FloatField):
        return FloatType(**kwargs)
    elif isinstance(field, (PG_JSONField, PG_BinaryJSONField, SQLITE_JSONField)):
        # 注意 SQLITE_JSONField 是一个 _StringField 所以要提前
        return JSONType(**kwargs)
        # HStore 貌似才应该对应 dict,json可以对应任意类型
        # return JSONDictType(StringType, **kwargs)
    elif isinstance(field, peewee.DateTimeField):
        return DateTimeType(**kwargs)
    elif isinstance(field, peewee.DateField):
        return DateType(**kwargs)
    elif isinstance(field, peewee._StringField):
        return StringType(**kwargs)
    elif isinstance(field, peewee.BooleanField):
        return BooleanType(**kwargs)
    elif isinstance(field, peewee.BlobField):
        return BlobType(**kwargs)
    elif isinstance(field, PG_ArrayField):
        field: PG_ArrayField
        return JSONListType(field_class_to_schematics_field(field._ArrayField__field), **kwargs)


# noinspection PyProtectedMember 
开发者ID:fy0,项目名称:slim,代码行数:40,代码来源:validate.py

示例2: run_migrate

# 需要导入模块: from playhouse import postgres_ext [as 别名]
# 或者: from playhouse.postgres_ext import BinaryJSONField [as 别名]
def run_migrate(*args):
    '''
    running some migration.
    '''

    print('Begin migrate ...')

    torcms_migrator = migrate.PostgresqlMigrator(config.DB_CON)

    memo_field = migrate.TextField(null=False, default='', help_text='Memo', )
    try:
        migrate.migrate(torcms_migrator.add_column('tabpost', 'memo', memo_field))
    except:
        pass

    desc_field = migrate.CharField(null=False, default='', max_length=255, help_text='')
    try:
        migrate.migrate(torcms_migrator.add_column('tabentity', 'desc', desc_field))
    except:
        pass

    extinfo_field = BinaryJSONField(null=False, default={}, help_text='Extra data in JSON.')
    try:
        migrate.migrate(torcms_migrator.add_column('tabmember', 'extinfo', extinfo_field))
    except:
        pass

    par_id_field = migrate.CharField(null=False, default='', max_length=4,
                                     help_text='父类id,对于label,top_id为""')
    try:
        migrate.migrate(torcms_migrator.add_column('tabpost2tag', 'par_id', par_id_field))
    except:
        pass

    category_field = migrate.CharField(null=False, default='0', max_length=1,
                                       help_text='0为评论,1为回复')
    try:
        migrate.migrate(torcms_migrator.add_column('tabreply', 'category', category_field))
    except:
        pass

    try:
        migrate.migrate(torcms_migrator.drop_column('tabentity2user', 'count'))
        # print('删除字段成功:count.')
    except:
        pass

    user_ip_field = migrate.CharField(null=False, default='0', help_text='User IP Address', )
    try:
        migrate.migrate(torcms_migrator.add_column('tabentity2user', 'user_ip', user_ip_field))
        # print('添加字段成功:user_ip.')
    except:
        pass

    print('Migration finished.') 
开发者ID:bukun,项目名称:TorCMS,代码行数:57,代码来源:script_migrate.py


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