本文整理汇总了Python中sqlalchemy.types.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Python types.ARRAY属性的具体用法?Python types.ARRAY怎么用?Python types.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.types
的用法示例。
在下文中一共展示了types.ARRAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_columns
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def get_columns(self, connection, table_name, schema=None, **kw):
table = self._get_table(connection, table_name, schema)
columns = self._get_columns_helper(table.schema, [])
result = []
for col in columns:
try:
coltype = _type_map[col.field_type]
except KeyError:
util.warn("Did not recognize type '%s' of column '%s'" % (col.field_type, col.name))
result.append({
'name': col.name,
'type': types.ARRAY(coltype) if col.mode == 'REPEATED' else coltype,
'nullable': col.mode == 'NULLABLE' or col.mode == 'REPEATED',
'default': None,
})
return result
示例2: test_arrays_pg
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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")]))
示例3: test_arrays_base
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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")]))
示例4: test_array_literal_getitem_multidim
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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]",
)
示例5: test_array_getitem_slice_type
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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)
示例6: test_array_plus_native_enum_create
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types 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(), [])
示例7: test_any_array_expression
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_any_array_expression(self, t_fixture):
t = t_fixture
self.assert_compile(
5 == any_(t.c.arrval[5:6] + postgresql.array([3, 4])),
"%(param_1)s = ANY (tab1.arrval[%(arrval_1)s:%(arrval_2)s] || "
"ARRAY[%(param_2)s, %(param_3)s])",
checkparams={
"arrval_2": 6,
"param_1": 5,
"param_3": 4,
"arrval_1": 5,
"param_2": 3,
},
dialect="postgresql",
)
示例8: test_all_array_expression
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_all_array_expression(self, t_fixture):
t = t_fixture
self.assert_compile(
5 == all_(t.c.arrval[5:6] + postgresql.array([3, 4])),
"%(param_1)s = ALL (tab1.arrval[%(arrval_1)s:%(arrval_2)s] || "
"ARRAY[%(param_2)s, %(param_3)s])",
checkparams={
"arrval_2": 6,
"param_1": 5,
"param_3": 4,
"arrval_1": 5,
"param_2": 3,
},
dialect="postgresql",
)
示例9: test_querying_table
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_querying_table(metadata):
"""
Create an object for test table.
"""
# When using pytest-xdist, we don't want concurrent table creations
# across test processes so we assign a unique name for table based on
# the current worker id.
worker_id = os.environ.get('PYTEST_XDIST_WORKER', 'master')
return Table(
'test_querying_table_' + worker_id, metadata,
Column('id', types.Integer, autoincrement=True, primary_key=True),
Column('serial', types.Integer, Sequence("serial_seq")),
Column('t_string', types.String(60), onupdate='updated'),
Column('t_list', types.ARRAY(types.String(60))),
Column('t_enum', types.Enum(MyEnum)),
Column('t_int_enum', types.Enum(MyIntEnum)),
Column('t_datetime', types.DateTime()),
Column('t_date', types.DateTime()),
Column('t_interval', types.Interval()),
Column('uniq_uuid', PG_UUID, nullable=False, unique=True, default=uuid4),
)
示例10: get_columns
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def get_columns(self, connection, table_name, schema=None, **kw):
# Extend types supported by PrestoDialect as defined in PyHive
type_map = {
'bigint': sql_types.BigInteger,
'integer': sql_types.Integer,
'boolean': sql_types.Boolean,
'double': sql_types.Float,
'varchar': sql_types.String,
'timestamp': sql_types.TIMESTAMP,
'date': sql_types.DATE,
'array<bigint>': sql_types.ARRAY(sql_types.Integer),
'array<varchar>': sql_types.ARRAY(sql_types.String)
}
rows = self._get_table_columns(connection, table_name, schema)
result = []
for row in rows:
try:
coltype = type_map[row.Type]
except KeyError:
logger.warn("Did not recognize type '%s' of column '%s'" % (row.Type, row.Column))
coltype = sql_types.NullType
result.append({
'name': row.Column,
'type': coltype,
# newer Presto no longer includes this column
'nullable': getattr(row, 'Null', True),
'default': None,
})
return result
示例11: test_reflect_select
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_reflect_select(table, table_using_test_dataset):
for table in [table, table_using_test_dataset]:
assert len(table.c) == 18
assert isinstance(table.c.integer, Column)
assert isinstance(table.c.integer.type, types.Integer)
assert isinstance(table.c.timestamp.type, types.TIMESTAMP)
assert isinstance(table.c.string.type, types.String)
assert isinstance(table.c.float.type, types.Float)
assert isinstance(table.c.boolean.type, types.Boolean)
assert isinstance(table.c.date.type, types.DATE)
assert isinstance(table.c.datetime.type, types.DATETIME)
assert isinstance(table.c.time.type, types.TIME)
assert isinstance(table.c.bytes.type, types.BINARY)
assert isinstance(table.c['record.age'].type, types.Integer)
assert isinstance(table.c['record.name'].type, types.String)
assert isinstance(table.c['nested_record.record.age'].type, types.Integer)
assert isinstance(table.c['nested_record.record.name'].type, types.String)
assert isinstance(table.c.array.type, types.ARRAY)
rows = table.select().execute().fetchall()
assert len(rows) == 1000
示例12: test_compare_array_of_integer_text
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_compare_array_of_integer_text(self):
self._compare_default_roundtrip(
ARRAY(Integer), text("(ARRAY[]::integer[])")
)
示例13: test_postgresql_array_type
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_postgresql_array_type(self):
eq_ignore_whitespace(
autogenerate.render._repr_type(
ARRAY(Integer), self.autogen_context
),
"postgresql.ARRAY(sa.Integer())",
)
eq_ignore_whitespace(
autogenerate.render._repr_type(
ARRAY(DateTime(timezone=True)), self.autogen_context
),
"postgresql.ARRAY(sa.DateTime(timezone=True))",
)
eq_ignore_whitespace(
autogenerate.render._repr_type(
ARRAY(BYTEA, as_tuple=True, dimensions=2), self.autogen_context
),
"postgresql.ARRAY(postgresql.BYTEA(), "
"as_tuple=True, dimensions=2)",
)
assert (
"from sqlalchemy.dialects import postgresql"
in self.autogen_context.imports
)
示例14: test_generic_array_type
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_generic_array_type(self):
eq_ignore_whitespace(
autogenerate.render._repr_type(
types.ARRAY(Integer), self.autogen_context
),
"sa.ARRAY(sa.Integer())",
)
eq_ignore_whitespace(
autogenerate.render._repr_type(
types.ARRAY(DateTime(timezone=True)), self.autogen_context
),
"sa.ARRAY(sa.DateTime(timezone=True))",
)
assert (
"from sqlalchemy.dialects import postgresql"
not in self.autogen_context.imports
)
eq_ignore_whitespace(
autogenerate.render._repr_type(
types.ARRAY(BYTEA, as_tuple=True, dimensions=2),
self.autogen_context,
),
"sa.ARRAY(postgresql.BYTEA(), as_tuple=True, dimensions=2)",
)
assert (
"from sqlalchemy.dialects import postgresql"
in self.autogen_context.imports
)
示例15: test_array_type_user_defined_inner
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import ARRAY [as 别名]
def test_array_type_user_defined_inner(self):
def repr_type(typestring, object_, autogen_context):
if typestring == "type" and isinstance(object_, String):
return "foobar.MYVARCHAR"
else:
return False
self.autogen_context.opts.update(render_item=repr_type)
eq_ignore_whitespace(
autogenerate.render._repr_type(
ARRAY(String), self.autogen_context
),
"postgresql.ARRAY(foobar.MYVARCHAR)",
)