本文整理汇总了Python中sqlalchemy.types.BINARY属性的典型用法代码示例。如果您正苦于以下问题:Python types.BINARY属性的具体用法?Python types.BINARY怎么用?Python types.BINARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.types
的用法示例。
在下文中一共展示了types.BINARY属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reflect_select
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [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
示例2: test_binary
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def test_binary(self):
"Exercise type specification for binary types."
columns = [
# column type, args, kwargs, expected ddl
(mssql.MSBinary, [], {}, "BINARY"),
(mssql.MSBinary, [10], {}, "BINARY(10)"),
(types.BINARY, [], {}, "BINARY"),
(types.BINARY, [10], {}, "BINARY(10)"),
(mssql.MSVarBinary, [], {}, "VARBINARY(max)"),
(mssql.MSVarBinary, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [], {}, "VARBINARY(max)"),
(mssql.MSImage, [], {}, "IMAGE"),
(mssql.IMAGE, [], {}, "IMAGE"),
(types.LargeBinary, [], {}, "IMAGE"),
]
metadata = MetaData()
table_args = ["test_mssql_binary", metadata]
for index, spec in enumerate(columns):
type_, args, kw, res = spec
table_args.append(
Column("c%s" % index, type_(*args, **kw), nullable=None)
)
binary_table = Table(*table_args)
dialect = mssql.dialect()
gen = dialect.ddl_compiler(dialect, schema.CreateTable(binary_table))
for col in binary_table.c:
index = int(col.name[1:])
testing.eq_(
gen.get_column_specification(col),
"%s %s" % (col.name, columns[index][3]),
)
self.assert_(repr(col))
示例3: test_binary_slice
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def test_binary_slice(self):
self._test_var_slice(types.BINARY)
示例4: test_binary_slice_zeropadding
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def test_binary_slice_zeropadding(self):
self._test_var_slice_zeropadding(types.BINARY, True)
示例5: test_create_table
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def test_create_table(engine):
meta = MetaData()
table = Table(
'test_pybigquery.test_table_create', meta,
Column('integer_c', sqlalchemy.Integer, doc="column description"),
Column('float_c', sqlalchemy.Float),
Column('decimal_c', sqlalchemy.DECIMAL),
Column('string_c', sqlalchemy.String),
Column('text_c', sqlalchemy.Text),
Column('boolean_c', sqlalchemy.Boolean),
Column('timestamp_c', sqlalchemy.TIMESTAMP),
Column('datetime_c', sqlalchemy.DATETIME),
Column('date_c', sqlalchemy.DATE),
Column('time_c', sqlalchemy.TIME),
Column('binary_c', sqlalchemy.BINARY),
bigquery_description="test table description",
bigquery_friendly_name="test table name"
)
meta.create_all(engine)
meta.drop_all(engine)
# Test creating tables with declarative_base
Base = declarative_base()
class TableTest(Base):
__tablename__ = 'test_pybigquery.test_table_create2'
integer_c = Column(sqlalchemy.Integer, primary_key=True)
float_c = Column(sqlalchemy.Float)
Base.metadata.create_all(engine)
Base.metadata.drop_all(engine)
示例6: _test_binary_reflection
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def _test_binary_reflection(self, deprecate_large_types):
"Exercise type specification for binary types."
columns = [
# column type, args, kwargs, expected ddl from reflected
(mssql.MSBinary, [], {}, "BINARY(1)"),
(mssql.MSBinary, [10], {}, "BINARY(10)"),
(types.BINARY, [], {}, "BINARY(1)"),
(types.BINARY, [10], {}, "BINARY(10)"),
(mssql.MSVarBinary, [], {}, "VARBINARY(max)"),
(mssql.MSVarBinary, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [10], {}, "VARBINARY(10)"),
(types.VARBINARY, [], {}, "VARBINARY(max)"),
(mssql.MSImage, [], {}, "IMAGE"),
(mssql.IMAGE, [], {}, "IMAGE"),
(
types.LargeBinary,
[],
{},
"IMAGE" if not deprecate_large_types else "VARBINARY(max)",
),
]
metadata = self.metadata
metadata.bind = engines.testing_engine(
options={"deprecate_large_types": deprecate_large_types}
)
table_args = ["test_mssql_binary", metadata]
for index, spec in enumerate(columns):
type_, args, kw, res = spec
table_args.append(
Column("c%s" % index, type_(*args, **kw), nullable=None)
)
binary_table = Table(*table_args)
metadata.create_all()
reflected_binary = Table(
"test_mssql_binary", MetaData(testing.db), autoload=True
)
for col, spec in zip(reflected_binary.c, columns):
eq_(
str(col.type),
spec[3],
"column %s %s != %s" % (col.key, str(col.type), spec[3]),
)
c1 = testing.db.dialect.type_descriptor(col.type).__class__
c2 = testing.db.dialect.type_descriptor(
binary_table.c[col.name].type
).__class__
assert issubclass(
c1, c2
), "column %s: %r is not a subclass of %r" % (col.key, c1, c2)
if binary_table.c[col.name].type.length:
testing.eq_(
col.type.length, binary_table.c[col.name].type.length
)
示例7: test_basic_reflection
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import BINARY [as 别名]
def test_basic_reflection(self):
meta = self.metadata
users = Table(
"engine_users",
meta,
Column("user_id", types.INT, primary_key=True),
Column("user_name", types.VARCHAR(20), nullable=False),
Column("test1", types.CHAR(5), nullable=False),
Column("test2", types.Float(5), nullable=False),
Column("test2.5", types.Float(), nullable=False),
Column("test3", types.Text()),
Column("test4", types.Numeric, nullable=False),
Column("test4.5", types.Numeric(10, 2), nullable=False),
Column("test5", types.DateTime),
Column(
"parent_user_id",
types.Integer,
ForeignKey("engine_users.user_id"),
),
Column("test6", types.DateTime, nullable=False),
Column("test7", types.Text()),
Column("test8", types.LargeBinary()),
Column("test_passivedefault2", types.Integer, server_default="5"),
Column("test9", types.BINARY(100)),
Column("test_numeric", types.Numeric()),
)
addresses = Table(
"engine_email_addresses",
meta,
Column("address_id", types.Integer, primary_key=True),
Column(
"remote_user_id", types.Integer, ForeignKey(users.c.user_id)
),
Column("email_address", types.String(20)),
)
meta.create_all()
meta2 = MetaData()
reflected_users = Table(
"engine_users", meta2, autoload=True, autoload_with=testing.db
)
reflected_addresses = Table(
"engine_email_addresses",
meta2,
autoload=True,
autoload_with=testing.db,
)
self.assert_tables_equal(users, reflected_users)
self.assert_tables_equal(addresses, reflected_addresses)