Python全系列 教程
3567个小节阅读:5929.8k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在开发的程序中,往往数据量比较多,数据类型也比较多。如果原样的展示给用户,会造成用户的体验感非常不友好。
因此这时为了提高用户的体验感,就需要对数据筛选与排序等操作。在peewee中提供了多种数据筛选方式:
peeweee支持的运算符:
Comparison | Meaning |
---|---|
== | x equals y |
< | x is less than y |
<= | x is less than or equal to y |
> | x is greater than y |
>= | x is greater than or equal to y |
!= | x is not equal to y |
<< | x IN y, where y is a list or query |
>> | x IS y, where y is None/NULL |
% | x LIKE y where y may contain wildcards |
** | x ILIKE y where y may contain wildcards |
^ | x XOR y |
~ | Unary negation (e.g., NOT x) |
peeweee支持的方法:
Method | Meaning |
---|---|
.in_(value) | IN lookup (identical to << ). |
.not_in(value) | NOT IN lookup. |
.is_null(is_null) | IS NULL or IS NOT NULL. Accepts boolean param. |
.contains(substr) | Wild-card search for substring. |
.startswith(prefix) | Search for values beginning with prefix . |
.endswith(suffix) | Search for values ending with suffix . |
.between(low, high) | Search for values between low and high . |
.regexp(exp) | Regular expression match (case-sensitive). |
.iregexp(exp) | Regular expression match (case-insensitive). |
.bin_and(value) | Binary AND. |
.bin_or(value) | Binary OR. |
.concat(other) | Concatenate two strings or objects using || . |
.distinct() | Mark column for DISTINCT selection. |
.collate(collation) | Specify column with the given collation. |
.cast(type) | Cast the value of the column to the given type. |
peeweee支持的逻辑运算符:
Operator | Meaning | Example |
---|---|---|
& | AND | (User.is_active == True) & (User.is_admin == True) |
| (pipe) | OR | (User.is_admin) | (User.is_superuser) |
~ | NOT (unary negation) | ~(User.username.contains('admin')) |
代码案例:
xxxxxxxxxx
# Find the user whose username is "charlie".
User.select().where(User.username == 'charlie')
# Find the users whose username is in [charlie, huey, mickey]
User.select().where(User.username.in_(['charlie', 'huey', 'mickey']))
Employee.select().where(Employee.salary.between(50000, 60000))
Employee.select().where(Employee.name.startswith('C'))
Blog.select().where(Blog.title.contains(search_string))
问题
运行代码,总是提示警告
Warning: (3090, "Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.") result = self._query(query)
解决方案
在数据库中执行如下语句:
xxxxxxxxxx
set @@GLOBAL.sql_mode='';
set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';