我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.types.CHAR。
def load_dialect_impl(self, dialect: dialects) -> DialectType: """ SQLAlchemy wraps all database-specific features into dialects, which are then responsible for generating the SQL code for a specific DB type when loading in data. ``load_dialect_impl`` is called when CRUD (create, update, delete operations) needs to be done on the database. This method is responsible for telling SQLAlchemy how to configure the dialect to write this type :param dialect: The loaded dialect :return: The type descriptor for this type. """ if dialect.name == 'postgresql': return dialect.type_descriptor(postgresql.UUID()) else: return dialect.type_descriptor(CHAR(32))
def __init__(self, length=None, **kwargs): super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name): # Remove trailing spaces: FB uses a CHAR() type, # that is padded with spaces name = name and name.rstrip() if name is None: return None elif name.upper() == name and \ not self.identifier_preparer._requires_quotes(name.lower()): return name.lower() else: return name
def get_col_spec(self): return "CHAR(%(length)s)" % {'length' : self.length}
def load_dialect_impl(self, dialect): if dialect.name == 'postgresql': return dialect.type_descriptor(UUID()) else: return dialect.type_descriptor(CHAR(32))
def __init__(self, length=None, **kwargs): """Construct a CHAR. :param length: Maximum data length, in characters. :param binary: Optional, use the default binary collation for the national character set. This does not affect the type of data stored, use a BINARY type for binary data. :param collation: Optional, request a particular collation. Must be compatible with the national character set. """ super(CHAR, self).__init__(length=length, **kwargs)
def key_deal(): from_ = Column('from', CHAR(10)) #?????? #Column?????????????????????
def normalize_name(self, name): # Remove trailing spaces: FB uses a CHAR() type, # that is padded with spaces name = name and name.rstrip() if name is None: return None elif name.upper() == name and \ not self.identifier_preparer._requires_quotes(name.lower()): return name.lower() elif name.lower() == name: return quoted_name(name, quote=True) else: return name
def test_name_sqlite(self) -> None: """ Tests that if the name ``sqlite`` is given to the database, then a CHAR descriptor comes back out with 32 characters """ uuid_instance = DB_UUID() dialect_impl = uuid_instance.load_dialect_impl(self.sqlite_dialect) self.assertIsInstance( dialect_impl, self.sqlite_dialect.type_descriptor( CHAR(32) ).__class__ )
def test_bind_uuid_something_else(self, uuid: UUID) -> None: """ Tests that the UUID gets de-hyphenated if using the CHAR 32 type, same as always. :param uuid: A randomly-generated UUID to store """ db_uuid = DB_UUID() value_to_store = db_uuid.process_bind_param( uuid, self.sqlite_dialect ) self.assertEqual( value_to_store, "%.32x" % int(uuid) )
def load_dialect_impl(self, dialect): # IPv6 is 128 bits => 2^128 == 3.4e38 => 39 digits return dialect.type_descriptor(types.CHAR(39))
def load_dialect_impl(self, dialect): if dialect.name == 'sqlite': return dialect.type_descriptor(sqlite.CHAR) return dialect.type_descriptor(self.impl)
def sqltype_to_stdtype(sqltype): import sqlalchemy.types as sqltypes if isinstance(sqltype, (sqltypes.VARCHAR, sqltypes.CHAR, sqltypes.TEXT, sqltypes.Enum, sqltypes.String)): return _STRING_TYPE if isinstance(sqltype, (sqltypes.DATETIME, sqltypes.DATE, sqltypes.TIME, sqltypes.TIMESTAMP)): return _DATE_TYPE if isinstance(sqltype, (sqltypes.INTEGER, sqltypes.BIGINT, sqltypes.SMALLINT, sqltypes.Integer)): return _INTEGER_TYPE if isinstance(sqltype, (sqltypes.REAL, sqltypes.DECIMAL, sqltypes.NUMERIC, sqltypes.FLOAT)): return _DECIMAL_TYPE if isinstance(sqltype, sqltypes.BOOLEAN): return _BOOLEAN_TYPE
def load_dialect_impl(self, dialect): if dialect.name == 'postgresql': return dialect.type_descriptor(UUID()) elif dialect.name == 'oracle': return dialect.type_descriptor(RAW(16)) elif dialect.name == 'mysql': return dialect.type_descriptor(BINARY(16)) else: return dialect.type_descriptor(CHAR(32))
def __init__(self, binary=True, native=True): """ :param binary: Whether to use a BINARY(16) or CHAR(32) fallback. """ self.binary = binary self.native = native