本文整理汇总了Python中sqlalchemy.sql.func.lower方法的典型用法代码示例。如果您正苦于以下问题:Python func.lower方法的具体用法?Python func.lower怎么用?Python func.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.func
的用法示例。
在下文中一共展示了func.lower方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_unique_container_name
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def _validate_unique_container_name(self, context, name):
if not CONF.compute.unique_container_name_scope:
return
lowername = name.lower()
base_query = model_query(models.Container).\
filter(func.lower(models.Container.name) == lowername)
if CONF.compute.unique_container_name_scope == 'project':
container_with_same_name = base_query.\
filter_by(project_id=context.project_id).count()
elif CONF.compute.unique_container_name_scope == 'global':
container_with_same_name = base_query.count()
else:
return
if container_with_same_name > 0:
raise exception.ContainerAlreadyExists(field='name',
value=lowername)
示例2: add_foreign_key_constraint_if_not_exist
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def add_foreign_key_constraint_if_not_exist(
table_name, column_name, fk_table_name, fk_column_name, driver, metadata
):
table = Table(table_name, metadata, autoload=True, autoload_with=driver.engine)
foreign_key_name = "{}_{}_fkey".format(table_name.lower(), column_name)
if column_name in table.c:
foreign_keys = [fk.name for fk in getattr(table.c, column_name).foreign_keys]
if foreign_key_name not in foreign_keys:
with driver.session as session:
session.execute(
'ALTER TABLE "{}" ADD CONSTRAINT {} '
'FOREIGN KEY({}) REFERENCES "{}" ({});'.format(
table_name,
foreign_key_name,
column_name,
fk_table_name,
fk_column_name,
)
)
session.commit()
示例3: query_for_user
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def query_for_user(session, username):
return (
session.query(User)
.filter(func.lower(User.username) == username.lower())
.first()
)
示例4: set_foreign_key_constraint_on_delete
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def set_foreign_key_constraint_on_delete(
table_name,
column_name,
fk_table_name,
fk_column_name,
ondelete,
driver,
session,
metadata,
):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="Predicate of partial index \S+ ignored during reflection",
category=sa_exc.SAWarning,
)
table = Table(table_name, metadata, autoload=True, autoload_with=driver.engine)
foreign_key_name = "{}_{}_fkey".format(table_name.lower(), column_name)
if column_name in table.c:
session.execute(
'ALTER TABLE ONLY "{}" DROP CONSTRAINT IF EXISTS {}, '
'ADD CONSTRAINT {} FOREIGN KEY ({}) REFERENCES "{}" ({}) ON DELETE {};'.format(
table_name,
foreign_key_name,
foreign_key_name,
column_name,
fk_table_name,
fk_column_name,
ondelete,
)
)
示例5: drop_foreign_key_constraint_if_exist
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def drop_foreign_key_constraint_if_exist(table_name, column_name, driver, metadata):
table = Table(table_name, metadata, autoload=True, autoload_with=driver.engine)
foreign_key_name = "{}_{}_fkey".format(table_name.lower(), column_name)
if column_name in table.c:
foreign_keys = [fk.name for fk in getattr(table.c, column_name).foreign_keys]
if foreign_key_name in foreign_keys:
with driver.session as session:
session.execute(
'ALTER TABLE "{}" DROP CONSTRAINT {};'.format(
table_name, foreign_key_name
)
)
session.commit()
示例6: get_by_username
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import lower [as 别名]
def get_by_username(cls, username: str) -> Optional['Puppet']:
return cls._select_one_or_none(func.lower(cls.c.username) == username)