本文整理汇总了Python中sqlalchemy.dialects.postgresql.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Python postgresql.ARRAY属性的具体用法?Python postgresql.ARRAY怎么用?Python postgresql.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.dialects.postgresql
的用法示例。
在下文中一共展示了postgresql.ARRAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('domains',
sa.Column('allowed_docker_registries',
postgresql.ARRAY(sa.String()), nullable=True))
# ### end Alembic commands ###
print('\nSet default allowed_docker_registries.')
allowed_registries = os.environ.get('ALLOWED_DOCKER_REGISTRIES', None)
if allowed_registries:
allowed_registries = allowed_registries.replace(' ', '')
allowed_registries = '{index.docker.io,' + allowed_registries + '}'
else:
allowed_registries = '{index.docker.io}'
connection = op.get_bind()
query = ("UPDATE domains SET allowed_docker_registries = '{}';".format(allowed_registries))
connection.execute(query)
op.alter_column('domains', column_name='allowed_docker_registries',
nullable=False)
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:22,代码来源:22e52d03fc61_add_allowed_docker_registries_in_domains.py
示例2: upgrade
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('domains', sa.Column('allowed_vfolder_hosts',
postgresql.ARRAY(sa.String()), nullable=True))
op.add_column('groups', sa.Column('allowed_vfolder_hosts',
postgresql.ARRAY(sa.String()), nullable=True))
# ### end Alembic commands ###
print('\nSet domain and group\'s allowed_vfolder_hosts with empty array.')
connection = op.get_bind()
query = ("UPDATE domains SET allowed_vfolder_hosts = '{}';")
connection.execute(query)
query = ("UPDATE groups SET allowed_vfolder_hosts = '{}';")
connection.execute(query)
op.alter_column('domains', column_name='allowed_vfolder_hosts', nullable=False)
op.alter_column('groups', column_name='allowed_vfolder_hosts', nullable=False)
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:19,代码来源:c401d78cc7b9_add_allowed_vfolder_hosts_to_domain_and_.py
示例3: preprocess_column_and_value
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def preprocess_column_and_value(self):
""" Preprocess the column and the value
Certain operations will only work if the types are cast correctly.
This is where it happens.
"""
col, val = self.column, self.value
# Case 1. Both column and value are arrays
if self.is_column_array() and self.is_value_array():
# Cast the value to ARRAY[] with the same type that the column has
# Only in this case Postgres will be able to handles them both
val = cast(pg.array(val), pg.ARRAY(col.type.item_type))
# Case 2. JSON column
if self.is_column_json():
# This is the type to which JSON column is coerced: same as `value`
# Doc: "Suggest a type for a `coerced` Python value in an expression."
coerce_type = col.type.coerce_compared_value('=', val) # HACKY: use sqlalchemy type coercion
# Now, replace the `col` used in operations with this new coerced expression
col = cast(col, coerce_type)
# Done
self.column_expression = col
self.value_expression = val
示例4: languages_column
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def languages_column(column_name) -> sa.Column:
"""A TEXT[] column of length > 0.
Return an ARRAY(TEXT, as_tuple=True) column.
:param column_name: the name of the column
:returns: a SQLAlchemy Column for a non-null ARRAY(TEXT, as_tuple=True)
type.
"""
return sa.Column(
pg.ARRAY(pg.TEXT, as_tuple=True),
sa.CheckConstraint(
'COALESCE(ARRAY_LENGTH({}, 1), 0) > 0'.format(column_name)
),
nullable=False,
default=['English'],
)
示例5: test_arrays_pg
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def test_arrays_pg(self, connection):
metadata = self.metadata
t1 = Table(
"t",
metadata,
Column("x", postgresql.ARRAY(Float)),
Column("y", postgresql.ARRAY(REAL)),
Column("z", postgresql.ARRAY(postgresql.DOUBLE_PRECISION)),
Column("q", postgresql.ARRAY(Numeric)),
)
metadata.create_all()
connection.execute(
t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
)
row = connection.execute(t1.select()).first()
eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")]))
示例6: test_arrays_base
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def test_arrays_base(self, connection):
metadata = self.metadata
t1 = Table(
"t",
metadata,
Column("x", sqltypes.ARRAY(Float)),
Column("y", sqltypes.ARRAY(REAL)),
Column("z", sqltypes.ARRAY(postgresql.DOUBLE_PRECISION)),
Column("q", sqltypes.ARRAY(Numeric)),
)
metadata.create_all()
connection.execute(
t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
)
row = connection.execute(t1.select()).first()
eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")]))
示例7: test_array_literal_getitem_multidim
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def test_array_literal_getitem_multidim(self):
obj = postgresql.array(
[postgresql.array([1, 2]), postgresql.array([3, 4])]
)
self.assert_compile(
obj,
"ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
"ARRAY[%(param_3)s, %(param_4)s]]",
)
self.assert_compile(
obj[1],
"(ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
"ARRAY[%(param_3)s, %(param_4)s]])[%(param_5)s]",
)
self.assert_compile(
obj[1][0],
"(ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
"ARRAY[%(param_3)s, %(param_4)s]])[%(param_5)s][%(param_6)s]",
)
示例8: test_array_getitem_slice_type
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def test_array_getitem_slice_type(self):
m = MetaData()
arrtable = Table(
"arrtable",
m,
Column("intarr", postgresql.ARRAY(Integer)),
Column("strarr", postgresql.ARRAY(String)),
)
# type affinity is Array...
is_(arrtable.c.intarr[1:3].type._type_affinity, ARRAY)
is_(arrtable.c.strarr[1:3].type._type_affinity, ARRAY)
# but the slice returns the actual type
assert isinstance(arrtable.c.intarr[1:3].type, postgresql.ARRAY)
assert isinstance(arrtable.c.strarr[1:3].type, postgresql.ARRAY)
示例9: test_array_plus_native_enum_create
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def test_array_plus_native_enum_create(self):
m = MetaData()
t = Table(
"t",
m,
Column(
"data_1",
self.ARRAY(postgresql.ENUM("a", "b", "c", name="my_enum_1")),
),
Column(
"data_2",
self.ARRAY(types.Enum("a", "b", "c", name="my_enum_2")),
),
)
t.create(testing.db)
eq_(
set(e["name"] for e in inspect(testing.db).get_enums()),
set(["my_enum_1", "my_enum_2"]),
)
t.drop(testing.db)
eq_(inspect(testing.db).get_enums(), [])
示例10: SQLARRAY
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def SQLARRAY(item_type):
return postgresql.ARRAY(item_type)\
.with_variant(DefaultARRAY(item_type), "sqlite")
示例11: _lookup_operator
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def _lookup_operator(self, column_is_array, operator):
""" Lookup an operator in `self`, or extra operators
:param column_is_array: Is the column an ARRAY column?
Lookup will be limited to array operators
:param operator: Operator string
:return: lambda
:raises: KeyError
"""
if not column_is_array:
return self._operators_scalar.get(operator) or self._extra_scalar_ops[operator]
else:
return self._operators_array.get(operator) or self._extra_array_ops[operator]
示例12: is_column_array
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def is_column_array(self, name: str) -> bool:
""" Is the column an ARRAY column """
raise NotImplementedError
示例13: _is_column_array
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def _is_column_array(col: MapperProperty) -> bool:
""" Is the column a PostgreSql ARRAY column? """
return isinstance(_get_column_type(col), pg.ARRAY)
示例14: build_trafaret
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def build_trafaret(sa_type, **kwargs):
if isinstance(sa_type, sa.sql.sqltypes.Enum):
trafaret = t.Enum(*sa_type.enums, **kwargs)
# check for Text should be before String
elif isinstance(sa_type, sa.sql.sqltypes.Text):
trafaret = t.String(**kwargs)
elif isinstance(sa_type, sa.sql.sqltypes.String):
trafaret = t.String(max_length=sa_type.length, **kwargs)
elif isinstance(sa_type, sa.sql.sqltypes.Integer):
trafaret = t.ToInt(**kwargs)
elif isinstance(sa_type, sa.sql.sqltypes.Float):
trafaret = t.ToFloat(**kwargs)
elif isinstance(sa_type, sa.sql.sqltypes.DateTime):
trafaret = DateTime(**kwargs) # RFC3339
elif isinstance(sa_type, sa.sql.sqltypes.Date):
trafaret = DateTime(**kwargs) # RFC3339
elif isinstance(sa_type, sa.sql.sqltypes.Boolean):
trafaret = t.ToBool(**kwargs)
# Add PG related JSON and ARRAY
elif isinstance(sa_type, postgresql.JSON):
trafaret = AnyDict | t.List(AnyDict)
# Add PG related JSON and ARRAY
elif isinstance(sa_type, postgresql.ARRAY):
item_trafaret = build_trafaret(sa_type.item_type)
trafaret = t.List(item_trafaret)
else:
type_ = str(sa_type)
msg = 'Validator for type {} not implemented'.format(type_)
raise NotImplementedError(msg)
return trafaret
示例15: table
# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ARRAY [as 别名]
def table():
meta = sa.MetaData()
post = sa.Table(
'post', meta,
sa.Column('id', sa.Integer, nullable=False),
sa.Column('title', sa.String(200), nullable=False),
sa.Column('body', sa.Text, nullable=False),
sa.Column('views', sa.Integer, nullable=False),
sa.Column('average_note', sa.Float, nullable=False),
sa.Column('pictures', postgresql.JSON, server_default='{}'),
sa.Column('published_at', sa.Date, nullable=False),
sa.Column('tags', postgresql.ARRAY(sa.Integer), server_default='[]'),
# Indexes #
sa.PrimaryKeyConstraint('id', name='post_id_pkey'))
return post