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

Proposal: integration for DynamoDB expression syntax #447

Open
tvanhens opened this issue Aug 26, 2022 · 7 comments
Open

Proposal: integration for DynamoDB expression syntax #447

tvanhens opened this issue Aug 26, 2022 · 7 comments
Labels
dynamo enhancement New feature or request

Comments

@tvanhens
Copy link
Contributor

tvanhens commented Aug 26, 2022

Perhaps this is a stretch, or there is a better way of accomplishing the same task, but having DyanamoDB expression arguments behave as functionless integrations would enable some interesting use cases while being able to benefit from TypeScript checking and syntax.

Desired Behavior

Query

// Ideal syntax for query
table.query((item) => {
  // Query requires a boolean response value
  return (
    item.type === "connection" && // filter expression to narrow type
    item.pk === `connection|${event.body.tenantId}` && // pk is always required in KeyConditionExpression
    item.version === "1" // filter expression
  );
});
// Transforms to:
await $AWS.DynamoDB.Query({
  Table: table,
  KeyConditionExpression: "#name2 = :val2",
  FilterExpression: "#name1 = :val1 and #name3 = :val3",
  ExpressionAttributeNames: {
    "#name1": "type",
    "#name2": "pk",
    "#name3": "version",
  },
  ExpressionAttributeValues: {
    ":val1": { S: "connection" },
    ":val2": { S: `connection|${event.body.tenantId}` },
    ":val3": { S: "1" },
  },
});
@thantos
Copy link
Collaborator

thantos commented Aug 26, 2022

Some related ideas in here if you did see them: #106

@thantos thantos added the dynamo label Aug 26, 2022
@tvanhens
Copy link
Contributor Author

tvanhens commented Aug 26, 2022

I did not catch that one. I did a search but I glanced passed it because I assumed it was only scoped to the config of a table not the usage. Can close in favor of the linked issue if you'd prefer to track the work context there.

@thantos
Copy link
Collaborator

thantos commented Aug 26, 2022

Could you write examples in relation to the table and the call in a function or sfn?

Very similar to what I wrote in #106 though

table.updateItem(item, (prev) => ({ ...prev, value: prev.value + 1 }));

Could you create a new issue (or re-use this one) with what you want the top level to look like? Personally I think they should be as clean like the event bridge ones.

bus
   .when(event => event.source === "lambda")
   .map(event=>({ name: event.detail.name}))
  .pipe()```

@tvanhens
Copy link
Contributor Author

Can do.

Question on the event bus case. Do when and map collapse together to form one low-level resource (e.g. a filter rule)? Or, do they represent discrete resources with each one mapping 1:1 with a low-level resource?

Wondering because it might change how I think of the ideal API here.

@thantos
Copy link
Collaborator

thantos commented Aug 26, 2022

Dynamo doesn't nessecarily need to be fluent, better if we can keep it as one closure. Limitations in the compilation target and the ability to compose with event bus drove the current design (cannot call two integrations, must filter then transform).

when creates the Pattern document and map adds a Input Transform to whatever is in pipe.

when can be chained together

when(event => event.source === "lambda").when(event => event["detail-type"] === "myType")`

This is the same as

when(event => event.source === "lambda" && event["detail-type"] === "myType")

whens can be re-used and no Rule is actually created until map or pipe is called.

const lambdaEvent = bus.when(event => event.source === "lambda");
const lambdaFailure = lambdaEvent.when(event => detail.status === "Failure");
const lambdaSuccess = lambdaEvent.when(event => detail.status === "Success");

lambdaEvent .pipe(someFunction);
lambdaFailure .pipe(someFunction);
lambdaSuccess .pipe(someFunction);

This would create 3 rules.

@tvanhens
Copy link
Contributor Author

I updated the text with my ideal API. Unfortunately, I only have Query because I haven't been able to reason through a consistent way to collapse PutItem and UpdateItem into a consistent singular closure yet. Going to revisit your linked issue and will add additional examples as they start to crystalize.

@sam-goodwin
Copy link
Collaborator

I did not catch that one. I did a search but I glanced passed it because I assumed it was only scoped to the config of a table not the usage. Can close in favor of the linked issue if you'd prefer to track the work context there.

I think we are trying to move to a convention like the typescript repo where we add a keyword section to each issue along with tags.

We should probably have issue templates?

@thantos thantos added the enhancement New feature or request label Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamo enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants