python SQLAlchemy query and the query ()

Want to join queries when the query field, need to use the query (*****), query, query () two kinds of unreasonable usage

Premise: db, class TableName are configured, reference  https://www.cnblogs.com/whycai/p/11963443.html

 

1.query

. 1  from xxxx.models Import   the TableName
 2  
. 3 tableName = the TableName ()
 . 4 Result = tableName.query.filter ( ' condition ' ) .order ( ' field name ' ) .all ()
 . 5  
. 6 Data = [i.to_json () for I in RES]
 . 7  Print ( ' Data ' , Data)
 . 8  # results show list

 

2.query()

. 1  from XXXX Import DB
 2  
. 3 Result = db.session.query (TableName.colum1, func.count (TableName.colum1)). Filter ( ' condition ' ) .group_by ( ' field name ' ) .all ()
 . 4  
. 5  Print ( ' the result ' , the result)
 6  # results show list

Guess you like

Origin www.cnblogs.com/whycai/p/12167917.html