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

[FEATURE] Call set on search fields in query/get/delete/scan/update #1093

Closed
4 tasks done
Tracked by #1040
MaximilianSchon opened this issue Jan 8, 2021 · 1 comment
Closed
4 tasks done
Tracked by #1040
Milestone

Comments

@MaximilianSchon
Copy link

MaximilianSchon commented Jan 8, 2021

Summary:

I am using a single table structure, which means most of the the primary keys in my table have some kind of indicator of what type they are, so that it is possible to query them. An example from AWS Re:invent can be seen here: https://www.youtube.com/watch?v=DIQVJqiSUkE&t=2128s.

This does however not mix very well with how dynamoose searches for items, as the set is not called before fetch. It seems like the same problem arises with update, probably because of the same reason. That leaves me with a lot of queries looking like the example under general.

Code sample:

Schema

export const SurveySchema = new dynamoose.Schema({
    "PK": {
        "type": String,
        "default": () => crypto
            .randomBytes(16)
            .toString("hex"),
        "get": (value : string) => value.replace("Survey#", ""),
        "set": (value : string) => `Survey#${value}`,
        "hashKey": true
    },
    "SK": {
        "type": String,
        "rangeKey": true,
    }
}

Model

export const SurveyModel  = dynamoose.model("Survey", SurveySchema, 
    {
        create: false,
        update: false, 
        waitForActive: {
            enabled: false,
            check: null
        },
        suffix: "-" + process.env.ENV,
    })

General

    delete(PK: string, SK: string): Promise<void> {
        return Survey.delete({PK: `Survey#${PK}`, SK: SK});
    }

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
@fishcharlie
Copy link
Member

@MaximilianSchon Adding this to the v3 planning (#1040). One thing I'm planning on working on is having a Model represent a type of data as opposed to a DynamoDB table. Which should also help this as well. But ensuring get and set get called on all methods is important as well.

@MaximilianSchon MaximilianSchon changed the title [FEATURE] Call set on search fields in query/get/delete/scan/update(?) [FEATURE] Call set on search fields in query/get/delete/scan/update Feb 1, 2021
@fishcharlie fishcharlie self-assigned this Nov 22, 2021
@fishcharlie fishcharlie removed their assignment Nov 22, 2021
@fishcharlie fishcharlie added this to the v3 milestone Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants