deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

[Feature] New ORM Query Syntax (Syntactic Sugar)

Open Char2sGu opened this issue 2 years ago • 0 comments

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().

Char2sGu avatar Jun 14 '22 16:06 Char2sGu