deepkit-framework
deepkit-framework copied to clipboard
[Feature] New ORM Query Syntax (Syntactic Sugar)
Currently in deepkit, the Query
object is more like a query builder.
While in the most popular ORM in Python, Django ORM, the QuerySet
objects can be directly considered as the query result, which I think is pretty pleasing to use:
query_set = User.objects.all()
query_set = query_set.filter(...).exclude(...).annotate(...);
print(query_set[100:200]) # console.log(await query.limit(100).skip(100).find())
print(query_set[0]) # console.log(await query.findONe())
print(query_set.first()) # same↑
print(query_set) # console.log(await query.find())
print(query_set.all()) # same↑
This example above uses a sync pattern, but this can be implemented in DeepKit using an async pattern too, without any breaking changes:
let result = database.query(User);
result = result.filter(...).filter(...).withAnootation(...);
console.log(await result.between(100, 200));
console.log(await result.at(0));
console.log(await result.first());
console.log(await result);
console.log(await result.all());
These API are all qutie easy to implement as they are just like syntactic sugar of the existing API. There are completely no breaking changes since #257 has updated the usage of query.filter()
.