pythonjsonbool_Python types.JSON属性代码示例

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

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

示例1: load_dialect_impl

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def load_dialect_impl(self, dialect):

if dialect.name == 'postgresql':

return dialect.type_descriptor(JSONB())

elif dialect.name == 'mysql':

return dialect.type_descriptor(types.JSON())

elif dialect.name == 'oracle':

return dialect.type_descriptor(CLOB())

else:

return dialect.type_descriptor(String())

开发者ID:rucio,项目名称:rucio,代码行数:11,

示例2: _json_deserializer

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def _json_deserializer(self, row):

"""JSON deserializer for RECORD types.

The DB-API layer already deserializes JSON to a dictionary, so this

just returns the input.

"""

return row

开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:9,

示例3: set_custom_properties

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def set_custom_properties(self, table):

model = table.__tablename__

for property, values in properties["custom"].get(model, {}).items():

if values.get("private", False):

kwargs = {}

else:

kwargs = {

"default": values["default"],

"info": {"log_change": values.get("log_change", True)},

}

column = self.Column(

{

"boolean": Boolean,

"dict": self.Dict,

"float": Float,

"integer": Integer,

"json": JSON,

"string": self.LargeString,

"select": self.SmallString,

"multiselect": self.List,

}[values.get("type", "string")],

**kwargs,

)

if not values.get("serialize", True):

self.dont_serialize[model].append(property)

if not values.get("migrate", True):

self.dont_migrate[model].append(property)

setattr(table, property, column)

return table

开发者ID:eNMS-automation,项目名称:eNMS,代码行数:31,

示例4: string_json_attribute_person_model

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def string_json_attribute_person_model(base):

"""

This approach to faking JSON support for testing with sqlite is borrowed from:

https://avacariu.me/articles/2016/compiling-json-as-text-for-sqlite-with-sqlalchemy

"""

import sqlalchemy.types as types

import json

class StringyJSON(types.TypeDecorator):

"""Stores and retrieves JSON as TEXT."""

impl = types.TEXT

def process_bind_param(self, value, dialect):

if value is not None:

value = json.dumps(value)

return value

def process_result_value(self, value, dialect):

if value is not None:

value = json.loads(value)

return value

# TypeEngine.with_variant says "use StringyJSON instead when

# connecting to 'sqlite'"

MagicJSON = types.JSON().with_variant(StringyJSON, 'sqlite')

class StringJsonAttributePerson(base):

__tablename__ = 'string_json_attribute_person'

person_id = Column(Integer, primary_key=True)

name = Column(String, nullable=False)

birth_date = Column(DateTime)

# This model uses a String type for "json_tags" to avoid dependency on a nonstandard SQL type in testing, \

# while still demonstrating support

address = Column(MagicJSON)

yield StringJsonAttributePerson

开发者ID:miLibris,项目名称:flask-rest-jsonapi,代码行数:40,

示例5: test_json

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_json(self):

for t in ['json', 'jsonb']:

self._test(t, sqltypes.JSON)

开发者ID:cockroachdb,项目名称:sqlalchemy-cockroachdb,代码行数:5,

示例6: test_reflection

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_reflection(self):

Table("json_test", self.metadata, Column("foo", sqlite.JSON))

self.metadata.create_all()

reflected = Table("json_test", MetaData(), autoload_with=testing.db)

is_(reflected.c.foo.type._type_affinity, sqltypes.JSON)

assert isinstance(reflected.c.foo.type, sqlite.JSON)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,

示例7: test_rudimentary_roundtrip

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_rudimentary_roundtrip(self):

sqlite_json = Table(

"json_test", self.metadata, Column("foo", sqlite.JSON)

)

self.metadata.create_all()

value = {"json": {"foo": "bar"}, "recs": ["one", "two"]}

with testing.db.connect() as conn:

conn.execute(sqlite_json.insert(), foo=value)

eq_(conn.scalar(select([sqlite_json.c.foo])), value)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,

示例8: test_extract_subobject

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_extract_subobject(self):

sqlite_json = Table(

"json_test", self.metadata, Column("foo", sqlite.JSON)

)

self.metadata.create_all()

value = {"json": {"foo": "bar"}}

with testing.db.connect() as conn:

conn.execute(sqlite_json.insert(), foo=value)

eq_(

conn.scalar(select([sqlite_json.c.foo["json"]])), value["json"]

)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:17,

示例9: test_deprecated_serializer_args

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_deprecated_serializer_args(self):

sqlite_json = Table(

"json_test", self.metadata, Column("foo", sqlite.JSON)

)

data_element = {"foo": "bar"}

js = mock.Mock(side_effect=json.dumps)

jd = mock.Mock(side_effect=json.loads)

with testing.expect_deprecated(

"The _json_deserializer argument to the SQLite "

"dialect has been renamed",

"The _json_serializer argument to the SQLite "

"dialect has been renamed",

):

engine = engines.testing_engine(

options=dict(_json_serializer=js, _json_deserializer=jd)

)

self.metadata.create_all(engine)

with engine.begin() as conn:

conn.execute(sqlite_json.insert(), {"foo": data_element})

row = conn.execute(select([sqlite_json.c.foo])).first()

eq_(row, (data_element,))

eq_(js.mock_calls, [mock.call(data_element)])

eq_(jd.mock_calls, [mock.call(json.dumps(data_element))])

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:30,

示例10: setup

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def setup(self):

metadata = MetaData()

self.test_table = Table(

"test_table",

metadata,

Column("id", Integer, primary_key=True),

Column("test_column", JSON),

)

self.jsoncol = self.test_table.c.test_column

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:11,

示例11: test_custom_astext_type

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_custom_astext_type(self):

class MyType(types.UserDefinedType):

pass

col = column("x", JSON(astext_type=MyType))

is_(col["q"].astext.type.__class__, MyType)

is_(col[("q", "p")].astext.type.__class__, MyType)

is_(col["q"]["p"].astext.type.__class__, MyType)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:13,

示例12: _test_insert_nulljson_into_none_as_null

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def _test_insert_nulljson_into_none_as_null(self, engine):

with engine.connect() as conn:

conn.execute(

self.tables.data_table.insert(),

{"name": "r1", "nulldata": JSON.NULL},

)

self._assert_column_is_JSON_NULL(conn, column="nulldata")

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,

示例13: test_reflection

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_reflection(self):

Table("mysql_json", self.metadata, Column("foo", mysql.JSON))

self.metadata.create_all()

reflected = Table("mysql_json", MetaData(), autoload_with=testing.db)

is_(reflected.c.foo.type._type_affinity, sqltypes.JSON)

assert isinstance(reflected.c.foo.type, mysql.JSON)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:10,

示例14: test_rudimental_round_trip

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def test_rudimental_round_trip(self):

# note that test_suite has many more JSON round trip tests

# using the backend-agnostic JSON type

mysql_json = Table(

"mysql_json", self.metadata, Column("foo", mysql.JSON)

)

self.metadata.create_all()

value = {"json": {"foo": "bar"}, "recs": ["one", "two"]}

with testing.db.connect() as conn:

conn.execute(mysql_json.insert(), foo=value)

eq_(conn.scalar(select([mysql_json.c.foo])), value)

开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:17,

示例15: mutable_json_type

​点赞 5

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def mutable_json_type(dbtype=JSON, nested=False):

"""Type creator for (optionally nested) mutable JSON column types.

The default backend data type is sqlalchemy.types.JSON, but can be set to

any other type by providing the `dbtype` parameter.

"""

mutable_type = NestedMutable if nested else MutableDict

return mutable_type.as_mutable(dbtype)

# Base mutable JSON types

开发者ID:edelooff,项目名称:sqlalchemy-json,代码行数:13,

示例16: configure_events

​点赞 4

# 需要导入模块: from sqlalchemy import types [as 别名]

# 或者: from sqlalchemy.types import JSON [as 别名]

def configure_events(self):

@event.listens_for(self.base, "mapper_configured", propagate=True)

def model_inspection(mapper, model):

name = model.__tablename__

for col in inspect(model).columns:

if not col.info.get("model_properties", True):

continue

model_properties[name].append(col.key)

if col.type == PickleType and isinstance(col.default.arg, list):

property_types[col.key] = "list"

else:

column_type = {

Boolean: "bool",

Integer: "int",

Float: "float",

JSON: "dict",

PickleType: "dict",

}.get(type(col.type), "str")

if col.key not in property_types:

property_types[col.key] = column_type

for descriptor in inspect(model).all_orm_descriptors:

if descriptor.extension_type is ASSOCIATION_PROXY:

property = (

descriptor.info.get("name")

or f"{descriptor.target_collection}_{descriptor.value_attr}"

)

model_properties[name].append(property)

if hasattr(model, "parent_type"):

model_properties[name].extend(model_properties[model.parent_type])

if "service" in name and name != "service":

model_properties[name].extend(model_properties["service"])

models.update({name: model, name.lower(): model})

model_properties[name].extend(model.model_properties)

model_properties[name] = list(set(model_properties[name]))

for relation in mapper.relationships:

if getattr(relation.mapper.class_, "private", False):

continue

property = str(relation).split(".")[1]

relationships[name][property] = {

"model": relation.mapper.class_.__tablename__,

"list": relation.uselist,

}

开发者ID:eNMS-automation,项目名称:eNMS,代码行数:44,

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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部