question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] v3 single table attribute mapping

See original GitHub issue

Summary:

I’m using the alpha of v3 to build out a single table design using multiple models each with their own schema. As a result of this single table design I’m using generic attributes (pk, sk, etc.) to store different things depending on the model. The problem is that you lose the meaning of these values on the different models.

Is there any plan to introduce a mapping of model attributes to underlying table attributes?

Example

const userSchema = new dynamoose.Schema({
    "id": {
       type: String,
       map: "pk"
     }
    "type": {
       type: String,
       map: "sk"
     }
});

const orderSchema = new dynamoose.Schema({
    "userId": {
       type: String,
       map: "pk"
     }
    "orderId": {
       type: String,
       map: "sk"
     }
});

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fishcharliecommented, Dec 18, 2021

@alexedwardjones Nope, no plans until you created this issue 😉. Love this idea tho. I will prioritize it for v3. Really appreciate the feedback and feature suggestion.

Also, thank you for trying v3. Any feedback (good or bad) is appreciated. Even good feedback tells us that we are almost ready to ship. So really appreciate it. Feel free to continue to create issues or contact me with any other feedback.

Thanks again!

0reactions
fishcharliecommented, Jun 16, 2022

@AlisonVilela

I wonder if it would be possible to add prefix too?

How would this work? Would it just prefix all values with a certain prefix string? How would this work on reads from DynamoDB? Or would it only apply to saves? How about a prefix on a key property and you get using that property? Would the value you get on be prefixed with that value before running the query?

Something similar that you might want to look into is the set function: https://beta.dynamoosejs.com/guide/Schema#set-function--async-function. This would allow you to set a function that gets run whenever saving an item to DynamoDB, and also when retrieving an item with that property as part of the query. I think that might meet your needs here.

and maybe a way to add multiple PK and SK

I don’t understand what you mean here. In DynamoDB you can only have one primary key, and one sort key. You can’t have multiple of both. Just not allowed in DynamoDB.

If you are wanting to combine two attributes that you have into a single PK or SK attribute, that can be easily achieved using the combine type in Dynamoose: https://beta.dynamoosejs.com/guide/Schema#attribute-types. However, it is important to note that the underlying values will also be stored as part of your item.

For example, lets say you had a raceId property, and a partId property. And you want your PK to be the values of both of those properties, separated by a -. You could use the Combine type on your PK property, and have it combine the raceId and partId values automatically for you. But the underlying item will still include the raceId and partId values as different attributes.

Using the Schema’s Parent would work similar?

Apologies, but I don’t understand what you mean here at all.


Hopefully this answers your questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attribute field mapping—ArcGIS Pro | Documentation
Use the Field Map parameter to control how attribute fields from the input datasets are processed and written, or mapped, to the output...
Read more >
QGIS: create layout with one map its attribute table per feature
I have 800 features in the survey. The goal is to create 800 individual PDFs that have a map and attribute table of...
Read more >
Viewing and Editing the Attribute Table in ArcGIS Pro - YouTube
In the video we edit some attributes both as single records, then also as multiple records using the 'calculate field' function.
Read more >
Attribute Table - MapStore
In GIS, the Attribute Table associated to a vector layer is a table that stores tabular information related to the layer. The columns...
Read more >
SchemaMapper: Attribute Mapping - FME Community
Attribute mapping is the act of transforming and/or connecting one or more ... commas in your lookup table CSV can confuse FME during...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found