本文整理匯總了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)