本文整理汇总了Python中sqlalchemy.func.lower方法的典型用法代码示例。如果您正苦于以下问题:Python func.lower方法的具体用法?Python func.lower怎么用?Python func.lower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.func
的用法示例。
在下文中一共展示了func.lower方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: count
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def count(column, value, glob=False):
"""Counts number of rows with value in a column. This function is case-insensitive.
Positional arguments:
column -- the SQLAlchemy column object to search in (e.g. Table.a_column).
value -- the value to search for, any string.
Keyword arguments:
glob -- enable %globbing% search (default False).
Returns:
Number of rows that match. Equivalent of SELECT count(*) FROM.
"""
query = db.session.query(func.count('*'))
if glob:
query = query.filter(column.ilike(value))
else:
query = query.filter(func.lower(column) == value.lower())
return query.one()[0]
示例2: get
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def get(self):
symbols = get_parsed_arg_list('symbols', to_lower=True)
exchange_pairs = get_parsed_arg_list('exchange_pairs', to_lower=True)
if len(symbols) > 0:
tokens = Token.query.filter(func.lower(Token.symbol).in_(symbols)).all()
else:
tokens = Token.query.all()
exchange_pair_tokens = Token.query.filter(func.lower(Token.symbol).in_(exchange_pairs)).all()
tokens_schema.context = {'exchange_pairs': exchange_pair_tokens}
response_object = {
'message': 'success',
'data': {
'tokens': tokens_schema.dump(tokens).data
}
}
return make_response(jsonify(response_object)), 200
示例3: find_user
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def find_user(self, case_insensitive=False, **kwargs):
from sqlalchemy import func as alchemyFn
query = self.user_model.query
if config_value("JOIN_USER_ROLES") and hasattr(self.user_model, "roles"):
from sqlalchemy.orm import joinedload
query = query.options(joinedload("roles"))
if case_insensitive:
# While it is of course possible to pass in multiple keys to filter on
# that isn't the normal use case. If caller asks for case_insensitive
# AND gives multiple keys - throw an error.
if len(kwargs) > 1:
raise ValueError("Case insensitive option only supports single key")
attr, identifier = kwargs.popitem()
subquery = alchemyFn.lower(
getattr(self.user_model, attr)
) == alchemyFn.lower(identifier)
return query.filter(subquery).first()
else:
return query.filter_by(**kwargs).first()
示例4: get_subscription
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def get_subscription(application=None):
"""
Return a list of subscriptions for a certain application
If application is omitted, all applications are returned.
:param application: Name of the application
:return: list of subscription dictionaries
"""
subscriptions = []
sql_query = Subscription.query
if application:
sql_query = sql_query.filter(func.lower(Subscription.application) ==
application.lower())
for sub in sql_query.all():
subscriptions.append(sub.get())
return subscriptions
示例5: get_user
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def get_user( session, broker_id, username=None, email=None, user_id=None ):
if username:
username = username.lower().strip()
if email:
email = email.lower().strip()
if user_id:
filter_obj = or_(User.id == user_id)
elif username and email:
filter_obj = or_( func.lower(User.username)==username, func.lower(User.email)==email )
elif username:
filter_obj = or_( func.lower(User.username)==username )
elif email:
filter_obj = or_( func.lower(User.email)==email )
else:
return None
user = session.query(User).filter(User.broker_id == broker_id).filter(filter_obj).first()
if user:
return user
return None
示例6: get_all_without_views
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def get_all_without_views(cls, formats=[]):
'''Returns all resources that have no resource views
:param formats: if given, returns only resources that have no resource
views and are in any of the received formats
:type formats: list
:rtype: list of ckan.model.Resource objects
'''
query = meta.Session.query(cls).outerjoin(ckan.model.ResourceView) \
.filter(ckan.model.ResourceView.id == None)
if formats:
lowercase_formats = [f.lower() for f in formats]
query = query.filter(func.lower(cls.format).in_(lowercase_formats))
return query.all()
示例7: players
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def players():
form = SearchPlayerForm()
player_query = Player.query
if form.validate_on_submit():
player_query = player_query.join(User)
if form.player_name.data:
player_query = player_query.filter(
func.lower(User.name).contains(form.player_name.data.lower()))
if form.aga_id.data:
player_query = player_query.filter(
User.aga_id == form.aga_id.data)
players = player_query.limit(100).all()
return render_template('players.html', players=players, form=form)
示例8: test_render_add_index_func
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def test_render_add_index_func(self):
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("code", String(255)),
)
idx = Index("test_lower_code_idx", func.lower(t.c.code))
op_obj = ops.CreateIndexOp.from_index(idx)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.create_index('test_lower_code_idx', 'test', "
"[sa.text(!U'lower(code)')], unique=False)",
)
示例9: get_user_from_google_member
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def get_user_from_google_member(member, db=None):
"""
Get User object for all members on a Google project by checking db.
Args:
member(cirrus.google_cloud.iam.GooglePolicyMember): Member on
the google project who are of type User
Return:
fence.models.User: User from our db for member on Google project
"""
session = get_db_session(db)
linked_google_account = (
session.query(UserGoogleAccount)
.filter(func.lower(UserGoogleAccount.email) == member.email_id.lower().strip())
.first()
)
if linked_google_account:
return (
session.query(User).filter(User.id == linked_google_account.user_id).first()
)
return None
示例10: add_foreign_key_constraint_if_not_exist
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.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()
示例11: _revoke_from_db
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def _revoke_from_db(self, sess, to_delete):
"""
Revoke user access to projects in the auth database
Args:
sess: sqlalchemy session
to_delete: a set of (username, project.auth_id) to be revoked from db
Return:
None
"""
for (username, project_auth_id) in to_delete:
q = (
sess.query(AccessPrivilege)
.filter(AccessPrivilege.project.has(auth_id=project_auth_id))
.join(AccessPrivilege.user)
.filter(func.lower(User.username) == username)
.all()
)
for access in q:
self.logger.info(
"revoke {} access to {} in db".format(username, project_auth_id)
)
sess.delete(access)
示例12: make_id
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def make_id(namespace, name):
"""
pass a language name or host in with a name, get a Package.id str
"""
namespace = namespace.lower()
if namespace in ["cran", "pypi"]:
return namespace + ":" + name
elif namespace == "python":
return "pypi:" + name
elif namespace == "r":
return "cran:" + name
else:
raise ValueError("Invalid namespace for package id")
示例13: registerCommon
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def registerCommon(request, form):
mails = request.db.query(models.User.email).all()
mails = [m.email.lower() for m in mails]
if form['email'].lower() in mails:
request.session.flash('Ein Benutzer mit dieser E-Mail-Adresse existiert bereits.', queue='messages')
return False
else:
user = models.User()
form.obj = user
form.saveValues()
request.db.add(user)
confirmation = models.Confirmation()
confirmation.source = 'user/register'
confirmation.user = user
request.db.add(confirmation)
request.db.commit()
send_confirmation_mail(request, user, confirmation)
return True
示例14: validateInput
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def validateInput(self):
'''
Validate user input.
'''
if self._dbmodel:
if callable(self._dbmodel):
modelObj = self._dbmodel()
#Then it is a class instance
else:
modelObj = self._dbmodel
self._dbmodel = self._dbmodel.__class__
objQueryProperty = getattr(self._dbmodel,self._attrName)
modelRecord = modelObj.queryObject().filter(func.lower(objQueryProperty) == func.lower(self.text())).first()
if modelRecord != None:
self.setStyleSheet(INVALIDATESTYLESHEET)
self._currInvalidMsg = self._invalidMsg.format("'" + self.text() + "'")
self._isValid = False
if self._notifBar:
self._notifBar.insertErrorNotification(self._currInvalidMsg)
示例15: grant
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import lower [as 别名]
def grant(self, sess, comment, grantee, badge):
"""
This is how admins can grant badges manually
"""
author = comment.author.name
badge = badge.lower().replace('\\', '')
grantee_unescaped = grantee.replace('\\', '')
if author in config.ADMIN_ACCOUNTS:
investor = sess.query(Investor).\
filter(Investor.name == grantee_unescaped).\
first()
if not investor:
return comment.reply_wrap(message.modify_grant_failure("no such investor"))
badge_list = json.loads(investor.badges)
if badge in badge_list:
return comment.reply_wrap(message.modify_grant_failure("already owned"))
badge_list.append(badge)
investor.badges = json.dumps(badge_list)
return comment.reply_wrap(message.modify_grant_success(grantee, badge))