本文整理匯總了Python中sqlalchemy.types.Boolean方法的典型用法代碼示例。如果您正苦於以下問題:Python types.Boolean方法的具體用法?Python types.Boolean怎麽用?Python types.Boolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.types
的用法示例。
在下文中一共展示了types.Boolean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_type
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def get_type(data_type):
type_map = {
"bytes": types.LargeBinary,
"boolean": types.Boolean,
"date": types.Date,
"datetime": types.DateTime,
"double": types.Numeric,
"text": types.String,
"keyword": types.String,
"integer": types.Integer,
"half_float": types.Float,
"geo_point": types.String,
# TODO get a solution for nested type
"nested": types.String,
# TODO get a solution for object
"object": types.BLOB,
"long": types.BigInteger,
"float": types.Float,
"ip": types.String,
}
type_ = type_map.get(data_type)
if not type_:
logger.warning(f"Unknown type found {data_type} reverting to string")
type_ = types.String
return type_
示例2: fields_map
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def fields_map(self, field_type):
if field_type == "primary":
return ID(stored=True, unique=True)
type_map = {
'date': types.Date,
'datetime': types.DateTime,
'boolean': types.Boolean,
'integer': types.Integer,
'float': types.Float
}
if isinstance(field_type, str):
field_type = type_map.get(field_type, types.Text)
if not isinstance(field_type, type):
field_type = field_type.__class__
if issubclass(field_type, (types.DateTime, types.Date)):
return DATETIME(stored=True, sortable=True)
elif issubclass(field_type, types.Integer):
return NUMERIC(stored=True, numtype=int)
elif issubclass(field_type, types.Float):
return NUMERIC(stored=True, numtype=float)
elif issubclass(field_type, types.Boolean):
return BOOLEAN(stored=True)
return TEXT(stored=True, analyzer=self.analyzer, sortable=False)
示例3: _add_annotation_docs_to_sqlite
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def _add_annotation_docs_to_sqlite(dbcon, annotation_docs, item):
# add full item path for convenience
annotation_docs.loc[:, "item_name"] = item['name']
# save tables to sqlite
annotation_docs.to_sql(
name='annotation_docs', con=dbcon, if_exists='append',
dtype={
'annotation_girder_id': String(),
'_modelType': String(),
'_version': Integer(),
'itemId': String(),
'item_name': String(),
'created': String(),
'creatorId': String(),
'public': Boolean(),
'updated': String(),
'updatedId': String(),
'groups': String(),
'element_count': Integer(),
'element_details': Integer(), },
index=False,
)
示例4: test_implicitly_boolean
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def test_implicitly_boolean(self):
# test for expressions that the database always considers as boolean
# even if there is no boolean datatype.
assert not self.table1.c.myid._is_implicitly_boolean
assert (self.table1.c.myid == 5)._is_implicitly_boolean
assert (self.table1.c.myid == 5).self_group()._is_implicitly_boolean
assert (self.table1.c.myid == 5).label("x")._is_implicitly_boolean
assert not_(self.table1.c.myid == 5)._is_implicitly_boolean
assert or_(
self.table1.c.myid == 5, self.table1.c.myid == 7
)._is_implicitly_boolean
assert not column("x", Boolean)._is_implicitly_boolean
assert not (self.table1.c.myid + 5)._is_implicitly_boolean
assert not not_(column("x", Boolean))._is_implicitly_boolean
assert (
not select([self.table1.c.myid])
.scalar_subquery()
._is_implicitly_boolean
)
assert not text("x = y")._is_implicitly_boolean
assert not literal_column("x = y")._is_implicitly_boolean
示例5: get_columns
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [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
示例6: test_reflect_select
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [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
示例7: fields_map
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def fields_map(self, field_type):
if field_type == "primary":
return {'type': 'keyword'}
type_map = {
'date': types.Date,
'datetime': types.DateTime,
'boolean': types.Boolean,
'integer': types.Integer,
'float': types.Float,
'binary': types.Binary
}
if isinstance(field_type, str):
field_type = type_map.get(field_type, types.Text)
if not isinstance(field_type, type):
field_type = field_type.__class__
if issubclass(field_type, (types.DateTime, types.Date)):
return {'type': 'date'}
elif issubclass(field_type, types.Integer):
return {'type': 'long'}
elif issubclass(field_type, types.Float):
return {'type': 'float'}
elif issubclass(field_type, types.Boolean):
return {'type': 'boolean'}
elif issubclass(field_type, types.Binary):
return {'type': 'binary'}
return {'type': 'string'}
# https://medium.com/@federicopanini/elasticsearch-6-0-removal-of-mapping-types-526a67ff772
示例8: test_should_boolean_convert_boolean
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def test_should_boolean_convert_boolean():
assert get_field(types.Boolean()).type == graphene.Boolean
示例9: get_columns
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def get_columns(self, connection, table_name, schema=None, **kw):
SQL_COLS = """
SELECT CAST(a.attname AS VARCHAR(128)) as name,
a.atttypid as typeid,
not a.attnotnull as nullable,
a.attcolleng as length,
a.format_type
FROM _v_relation_column a
WHERE a.name = :tablename
ORDER BY a.attnum
"""
s = text(SQL_COLS,
bindparams=[bindparam('tablename', type_=sqltypes.String)],
typemap={'name': NAME,
'typeid': sqltypes.Integer,
'nullable': sqltypes.Boolean,
'length': sqltypes.Integer,
'format_type': sqltypes.String,
})
c = connection.execute(s, tablename=table_name)
rows = c.fetchall()
# format columns
columns = []
for name, typeid, nullable, length, format_type in rows:
coltype_class, has_length = oid_datatype_map[typeid]
if coltype_class is sqltypes.Numeric:
precision, scale = re.match(
r'numeric\((\d+),(\d+)\)', format_type).groups()
coltype = coltype_class(int(precision), int(scale))
elif has_length:
coltype = coltype_class(length)
else:
coltype = coltype_class()
columns.append({
'name': name,
'type': coltype,
'nullable': nullable,
})
return columns
示例10: _add_folder_to_sqlite
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def _add_folder_to_sqlite(dbcon, folder_info):
# modify folder info to prep for appending to sqlite table
folder_info_dtypes = {
'_accessLevel': Integer(),
'_id': String(),
'_modelType': String(),
'baseParentId': String(),
'baseParentType': String(),
'created': String(),
'creatorId': String(),
'description': String(),
'name': String(),
'parentCollection': String(),
'parentId': String(),
'public': Boolean(),
'size': Integer(),
'updated': String(),
'folder_path': String(),
}
# in case anything is not in the schema, drop it
folder_info = {
k: v for k, v in folder_info.items()
if k in folder_info_dtypes.keys()}
# convert to df and add to items table
folder_info_df = DataFrame.from_dict(folder_info, orient='index').T
folder_info_df.to_sql(
name='folders', con=dbcon, if_exists='append',
dtype=folder_info_dtypes, index=False)
示例11: add_false_positive
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def add_false_positive(context, issue):
"""Add a finding into the database as a new finding
:param context: The Behave context
:param response: An issue data structure (see steps.py)
"""
dbconn = open_database(context)
if dbconn is None:
# There is no false positive db in use, and we cannot store the data,
# so we will assert a failure.
assert False, "Issues were found in scan, but no false positive database is in use."
# Add the finding into the database
db_insert = context.headlessscanner_issues.insert().values(
new_issue=True, # Boolean
# The result from Burp Extender does not include a timestamp,
# so we add the current time
timestamp=datetime.datetime.utcnow(), # DateTime
test_runner_host=socket.gethostbyname(socket.getfqdn()), # Text
scenario_id=issue['scenario_id'], # Text
url=issue['url'], # Text
severity=issue['severity'], # Text
issuetype=issue['issuetype'], # Text
issuename=issue['issuename'], # Text
issuedetail=issue['issuedetail'], # Text
confidence=issue['confidence'], # Text
host=issue['host'], # Text
port=issue['port'], # Text
protocol=issue['protocol'], # Text
messages=json.dumps(issue['messages'])) # Blob
dbconn.execute(db_insert)
dbconn.close()
示例12: compare_type
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def compare_type(self, ctxt, insp_col, meta_col, insp_type, meta_type):
"""Return True if types are different, False if not.
Return None to allow the default implementation to compare these types.
:param ctxt: alembic MigrationContext instance
:param insp_col: reflected column
:param meta_col: column from model
:param insp_type: reflected column type
:param meta_type: column type from model
"""
# some backends (e.g. mysql) don't provide native boolean type
BOOLEAN_METADATA = (types.BOOLEAN, types.Boolean)
BOOLEAN_SQL = BOOLEAN_METADATA + (types.INTEGER, types.Integer)
if issubclass(type(meta_type), BOOLEAN_METADATA):
return not issubclass(type(insp_type), BOOLEAN_SQL)
# Alembic <=0.8.4 do not contain logic of comparing Variant type with
# others.
if isinstance(meta_type, types.Variant):
orig_type = meta_col.type
impl_type = meta_type.load_dialect_impl(ctxt.dialect)
meta_col.type = impl_type
try:
return self.compare_type(ctxt, insp_col, meta_col, insp_type,
impl_type)
finally:
meta_col.type = orig_type
return ctxt.impl.compare_type(insp_col, meta_col)
示例13: _compare_server_default
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def _compare_server_default(bind, meta_col, insp_def, meta_def):
if isinstance(meta_col.type, sqlalchemy.Boolean):
if meta_def is None or insp_def is None:
return meta_def != insp_def
insp_def = insp_def.strip("'")
return not (
isinstance(meta_def.arg, expr.True_) and insp_def == "1" or
isinstance(meta_def.arg, expr.False_) and insp_def == "0"
)
示例14: test_default_reflection
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def test_default_reflection(self):
# (ask_for, roundtripped_as_if_different)
specs = [
(String(3), '"foo"'),
(sqltypes.NUMERIC(10, 2), "100.50"),
(Integer, "5"),
(Boolean, "False"),
]
columns = [
Column("c%i" % (i + 1), t[0], server_default=text(t[1]))
for (i, t) in enumerate(specs)
]
db = testing.db
m = MetaData(db)
Table("t_defaults", m, *columns)
try:
m.create_all()
m2 = MetaData(db)
rt = Table("t_defaults", m2, autoload=True)
expected = [c[1] for c in specs]
for i, reflected in enumerate(rt.c):
eq_(str(reflected.server_default.arg), expected[i])
finally:
m.drop_all()
示例15: test_boolean_default
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import Boolean [as 別名]
def test_boolean_default(self):
t = Table(
"t",
self.metadata,
Column("x", Boolean, server_default=sql.false()),
)
t.create(testing.db)
with testing.db.connect() as conn:
conn.execute(t.insert())
conn.execute(t.insert().values(x=True))
eq_(
conn.execute(t.select().order_by(t.c.x)).fetchall(),
[(False,), (True,)],
)