Skip to main content
Version: 3.3.0

Data Querying

Querying data from the database is well supported by JSONClasses ORM integrations. Query can be a expensive operation. Data query in JSONClasses supports async syntax and normal syntax.

# async syntaxawait User.find().order('created_at', -1)# normal syntaxUser.find().order('created_at', -1).exec()


There are mainly 3 kinds of query. ID query, single query and batch query. Use id, one and find to perform corresponding query.

await # a result with idawait'His/Her Name') # single result which matchesawait'His/Her Name').optional # can return Noneawait User.find(age=20) # a list of results


Batch results can be sorted and ordered.

await Analysis.find().order('created_at', 1) # ASC, old firstawait Analysis.find().order('created_at', -1) # DESC, new first

Multiple sorting descriptors can be chained together.


Page size and page number can be used to calculate the value of skip and limit.

await Analysis.find().skip((page_number - 1) * page_size).limit(page_size)


Querying an object without it's relationships is not handy and useful some of the times. JSONClasses supports querying object with it's linked objects included.

await'profile')await Author.find().include('posts', Post.find(title={'$regex': 'Python'}))

Including can be chained and nested unlimited levels.