sam-goodwin / eventual

Build scalable and durable micro-services with APIs, Messaging and Workflows
https://docs.eventual.ai
MIT License
174 stars 4 forks source link

feat: entity query conditions #385

Closed thantos closed 1 year ago

thantos commented 1 year ago

Adds the ability to provide query conditions in place of concrete key attributes for the sort key.

myEntity.query({
   part: "hello",
   sort: { $between: [1, 100] }
});

myEntity.query({
   part: "hello",
   sort1: "a",
   sort2: { $gt: "b" }
});

myEntity.query({
   part: "hello",
   $between: [{ sort1: "a", sort2: "1" }, { sort1: "b", sort2: "2" }]
});

Caveats:


sam-goodwin commented 1 year ago

Between should be an array.

between: [start,end]

sam-goodwin commented 1 year ago

Do the types properly protect from having two subsequent startsWith, between, etc?

thantos commented 1 year ago

Do the types properly protect from having two subsequent startsWith, between, etc?

Yeah. The query key condition can only be on the current head of the recursive progressive query key type. Also only on sort attributes.

sam-goodwin commented 1 year ago

I wonder if we should adopt mongo's syntax so that we are not inventing as much. They use $gt, $gte, etc. this same query language can then be used in filter expressions too.

https://www.mongodb.com/docs/manual/tutorial/query-documents/

thantos commented 1 year ago

I wonder if we should adopt mongo's syntax so that we are not inventing as much. They use $gt, $gte, etc. this same query language can then be used in filter expressions too.

https://www.mongodb.com/docs/manual/tutorial/query-documents/

Alright, I've been thinking about this.

At first I didn't think we needed any special characters because there is no ambiguity, and then I thought about adding $or logic, but dynamo key conditions cannot support $or.

BUT, if we want to support a DSL for filtering logic and not an expression, we'll need $or on the object to support complex filter queries.

// val < 100 && (begins_with(val2, "a") || begins_with(val2, "b"))
{
   val: { $lt: 100 },
   $or: [{
        val2: { $beginsWith: "a" }
   }, {
        val2: { $beginsWith: "b" }
   }[
}

I'll make the change

thantos commented 1 year ago

updated docs: https://github.com/functionless/eventual-website/pull/16