首先创建模型,在数据库里面生成表,然后填入数据,如下

 # 定义orm,数据模型
class Test(db.Model):
__tablename__ = 'test'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(80), unique=True)
password = db.Column(db.String(80))
email = db.Column(db.String(120), unique=True) def __repr__(self):
return '<User %r>' % self.username db.create_all() @app.route('/')
def index():
# 1.增加
admin = Test(username='GUEST5', password='GUEST5', email='GUEST5@example.com')
db.session.add(admin) # 提交一条数据
guestes = [Test(username='guest1', password='guest1', email='guest1@example.com'),
Test(username='guest2', password='guest2', email='guest2@example.com'),
Test(username='guest3', password='guest3', email='guest3@example.com'),
Test(username='guest4', password='guest4', email='guest4@example.com')]
db.session.add_all(guestes) # 提交多条数据
db.session.commit() return 'hello world' if __name__ == '__main__':
app.run(debug=True, port='')

0x01:查询用户数目

 Test.query.count()

0x02:查询所有用户

 result = Test.query.all()

0x03:查找字段为指定值的用户

 result = Test.query.filter(Test.username == 'guest1').first()

0x04:查找指定字段以某个字符串开始的用户(根据开头查询)

 results = Test.query.filter(Test.username.startswith('g')).all()

0x05:查找指定字段以某个字符串结束的用户(根据结尾查询)

 results = Test.query.filter(Test.username.endswith('')).all()

0x06:查找指定字段包含某个字符串的用户(根据关键字查询)

 results = Test.query.filter(Test.username.contains('e')).all()

一位大佬的博文写的很详细,大家可以看一下:https://blog.csdn.net/jlb1024/article/details/81515155

最新文章

  1. iOS 常用的向上,向下取整, 四舍五入函数
  2. ubuntu 更改时区
  3. Appium移动自动化测试之安装Android SDK和JDK
  4. 利用网络流传的WebShell默认密码库寻找WebShell
  5. jQuery getJSON() 能给外部变量赋值
  6. underscorejs-toArray学习
  7. rabbitMQ 安装 could not set correct interactive mode
  8. 关于for循环的几种经典案例
  9. 原创科幻短篇《VR》
  10. 【转】repo介绍
  11. Color the ball HDU1556
  12. P1258 小车问题
  13. 翻唱 - shape of you - 个个版本
  14. 18.2 不同用户 不同颜色光标 redis
  15. Windows平台查看端口占用的程序
  16. 记录:js删除数组中某一项或几项的几种方法(转)
  17. fastjson 简单使用 及其JSONObject使用
  18. Uva1395 POJ3522 Slim Span (最小生成树)
  19. 第一章 Java工具类目录
  20. Android wifi无线调试App新玩法ADB WIFI

热门文章

  1. TestNG.xml 配置
  2. BootStrap、jQuery UI、bxSlider组件使用
  3. [转]numpy的getA()/getA1()/getH()/getI()函数
  4. windows端口转发工具(LCX)
  5. Flutter命令突然无响应、vscode突然无法连接到IOS模拟器
  6. 动手学深度学习11- 多层感知机pytorch简洁实现
  7. SEO-------- 了解
  8. 【redis】redis异常-MISCONF Redis is configured to save RDB snapshots
  9. preventDefault, stopPropagation, return false -JS事件处理中的坑
  10. jmeter入门操作 = 录制