Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Query multiple entity types in one find operation #245

Answered by whimzyLive
darbio asked this question in Q&A
Discussion options

When modelling a relationship in DynamoDb, one way of doing so is by aggregating entities using the pk value and having different sk values. An example of this is as follows:

entity pk sk gsi1_pk gsi1_sk gsi2_pk gsi2_sk
Incident INCIDENT#${ID} INCIDENT#${ID} INCIDENT INCIDENT#${ID} INCIDENT OPEN#${GEOHASH}
IncidentResource INCIDENT#${ID} RESOURCE#${ID}
IncidentLogEntry INCIDENT#${ID} LOG#${DATE}#${RANDOM}

This design allows you to query on pk and have multiple items returned in the one query. The items are then composed into an aggregate model for the rest of the application to mess with.

Does this library support querying using find on the pk attribute and returning different types of entity? It seems that the solution would be to have the result of a query auto-parsed based upon the type of the returned item from DynamoDb.

In plain DynamoDb I would query on the pk attribute and then switch on the type, but the find method on entityManager requires you to know the type of the entity prior to execution.

const results = await this.connection.entityManager.find(IncidentEntity, { id: id }) // what if I am not an IncidentEntity?

You must be logged in to vote

@darbio Great question. I just want to say, yes this is the direction in which TypedORM is heading.
This is not supported yet but we are actively working on it to make this happen.

You can also follow all the discussions on the same topic on this issue.

Also, we are always open to creative ideas and contributions, so if you have any, send them this way.

Replies: 1 comment

Comment options

@darbio Great question. I just want to say, yes this is the direction in which TypedORM is heading.
This is not supported yet but we are actively working on it to make this happen.

You can also follow all the discussions on the same topic on this issue.

Also, we are always open to creative ideas and contributions, so if you have any, send them this way.

You must be logged in to vote
0 replies
Answer selected by whimzyLive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.