当前位置:   article > 正文

flask ORM查询集(query)的处理方法:_flask model 对query.filter_by.all()结果处理

flask model 对query.filter_by.all()结果处理

filter,filter_by,order_by,group_by,having,union_all,union,distinct,limit,offset

   # filter: 过滤; 语法:session.query(MyClass).filter(MyClass.name == 'some name')
    result0 = db.session.query(Protocols.protocolName).filter(Protocols.parent_protocol == "tcp,udp").all()
    # filter: 过滤; session.query(MyClass).filter(MyClass.name == 'some name', MyClass.id > 5)
    result1 = db.session.query(Protocols.protocolName).filter(Protocols.parent_protocol == "tcp,udp",
                                                              Protocols.id > 18).all()
    # filter_by:过滤; session.query(MyClass).filter_by(name = 'some name')
    result2 = db.session.query(Protocols.protocolName).filter_by(parent_protocol="tcp,udp").all()
    # filter_by:过滤; session.query(MyClass).filter_by(name = 'some name', id = 5)
    result3 = db.session.query(Protocols.protocolName).filter_by(parent_protocol="tcp,udp", id=3).all()
    # order_by:排序; asc(),desc()
    result4 = db.session.query(Protocols.protocolName).order_by(Protocols.id.asc()).all()
    result5 = db.session.query(Protocols.protocolName).filter_by(parent_protocol="tcp").order_by(
        Protocols.id.desc()).all()
    # group_by:分组;
    result6 = db.session.query(Protocols.parent_protocol).group_by(Protocols.parent_protocol)
    # having:分组后的过滤
    result7 = db.session.query(Protocols.parent_protocol).group_by(Protocols.parent_protocol).having(
        Protocols.parent_protocol.like("%cp%"))
    # union_all:并集(重复部分保存)
    result8 = result6.union_all(result7).all()
    result9 = result7.union_all(result6).all()
    # union:并集(重复部分剔除)
    result10 = result6.union(result7).all()
    # distinct:去重
    result11 = db.session.query(Protocols.parent_protocol).distinct().all()
    # limit:
    result12 = db.session.query(Protocols.protocolName).filter(Protocols.parent_protocol == "tcp").limit(6).all()
    # offset:跳过
    result13 = db.session.query(Protocols.protocolName).filter(Protocols.parent_protocol == "tcp").limit(6).offset(
        3).all()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
0 [('browser',), ('atsvc',), ('rtsp',), ('dns',)]
1 [('rtsp',), ('dns',)]
2 [('browser',), ('atsvc',), ('rtsp',), ('dns',)]
3 []
4 [('ssh',), ('https',), ('telent',), ('rdp',), ('ntp',), ('http',), ('ftp',), ('vnc',), ('smb',), ('smtp',), ('pop3',), ('imap',), ('netstat',), ('netbios-ns',), ('netbios-dgm',), ('netbios-ssn',), ('browser',), ('atsvc',), ('rtsp',), ('dns',), ('bootpc',), ('snmp',), ('snmp trap',), ('bootps',), ('tftp',), ('dhcp',), ('icmp',), ('tcp',), ('udp',), ('esp',), ('ah',), ('sctp',)]
5 [('netbios-ssn',), ('netbios-dgm',), ('netbios-ns',), ('netstat',), ('imap',), ('pop3',), ('smtp',), ('smb',), ('vnc',), ('ftp',), ('http',), ('ntp',), ('rdp',), ('telent',), ('https',), ('ssh',)]
6 [('ip',), ('tcp',), ('tcp,udp',), ('udp',)]
7 [('tcp',), ('tcp,udp',)]
8 [('ip',), ('tcp',), ('tcp,udp',), ('udp',), ('tcp',), ('tcp,udp',)]
9 [('tcp',), ('tcp,udp',), ('ip',), ('tcp',), ('tcp,udp',), ('udp',)]
10 [('ip',), ('tcp',), ('tcp,udp',), ('udp',)]
11 [('tcp',), ('tcp,udp',), ('udp',), ('ip',)]
12 [('ssh',), ('https',), ('telent',), ('rdp',), ('ntp',), ('http',)]
13 [('rdp',), ('ntp',), ('http',), ('ftp',), ('vnc',), ('smb',)]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/521947
推荐阅读
相关标签
  

闽ICP备14008679号