Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: entity query conditions #385

Merged
merged 9 commits into from
Jun 14, 2023
Merged

Conversation

thantos
Copy link
Contributor

@thantos thantos commented Jun 2, 2023

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

  • Between
  • Begins with - only string values
  • Less/Greater Than [Equal]
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:

  • Numeric fields will be evaluated as strings when part of a multi-attribute key part.
    • ex: ["name", "age"], { name: "sam", age: { $gt: 30 } } - greatThan 30 will use string based "30" and not numeric

  • TODO: add documentation

@sam-goodwin
Copy link
Owner

Between should be an array.

between: [start,end]

@thantos thantos requested a review from sam-goodwin June 3, 2023 09:54
@thantos thantos marked this pull request as ready for review June 3, 2023 09:54
@sam-goodwin
Copy link
Owner

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

@thantos
Copy link
Contributor Author

thantos commented Jun 4, 2023

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
Copy link
Owner

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
Copy link
Contributor Author

thantos commented Jun 7, 2023

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

  • $lt, $gt, $lte, $gte
  • $between (array)
  • $beginsWith

@thantos
Copy link
Contributor Author

thantos commented Jun 13, 2023

updated docs: functionless/eventual-website#16

@thantos thantos requested a review from sam-goodwin June 14, 2023 00:12
@thantos thantos merged commit 3a9e1e7 into main Jun 14, 2023
@thantos thantos deleted the sussman/feat/entity-query-conditions branch June 14, 2023 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants