目录
百战程序员,全站22050+开发课程+文档 ,学习精选优质好课快人一步!观看视频 快捷键ALT+N

Python全系列 教程

3567个小节阅读:5929.8k

收藏
全部开发者教程

鸿蒙应用开发

C语言快速入门

JAVA全系列 教程

面向对象的程序设计语言

Python全系列 教程

Python3.x版本,未来主流的版本

人工智能 教程

顺势而为,AI创新未来

大厂算法 教程

算法,程序员自我提升必经之路

C++ 教程

一门通用计算机编程语言

微服务 教程

目前业界流行的框架组合

web前端全系列 教程

通向WEB技术世界的钥匙

大数据全系列 教程

站在云端操控万千数据

AIGC全能工具班

A

A A

White Night

阅读(998)
赞(0)

ORM-peewee查询数据

image-20211229111837416

在开发的程序中,往往数据量比较多,数据类型也比较多。如果原样的展示给用户,会造成用户的体验感非常不友好。

因此这时为了提高用户的体验感,就需要对数据筛选与排序等操作。在peewee中提供了多种数据筛选方式:

peeweee支持的运算符

ComparisonMeaning
==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支持的方法

MethodMeaning
.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支持的逻辑运算符

OperatorMeaningExample
&AND(User.is_active == True) & (User.is_admin == True)
| (pipe)OR(User.is_admin) | (User.is_superuser)
~NOT (unary negation)~(User.username.contains('admin'))

代码案例

问题

运行代码,总是提示警告Warning: (3090, "Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.") result = self._query(query)

解决方案

在数据库中执行如下语句:

 

北京市昌平区回龙观镇南店村综合商业楼2楼226室

©2014-2023 百战卓越(北京)科技有限公司 All Rights Reserved.

京ICP备14032124号-2