Giter VIP home page Giter VIP logo

Comments (4)

jonterry-sans avatar jonterry-sans commented on September 26, 2024

Is there a way as it stands right now to make the partition key be duplicated to the sort key? Given the array notation for defining sort keys, I don't see how that is possible. I attempted to alias the pk with id, and then define id in the schema as ["sk", 0] but then the alias isn't unique and I get the associated error for that scenario.

Edit: Would it be possible to use a default provider here that has access to what the pk is set to?

Edit 2: So far the solution I have is the following. Do you know of a better solution?

// Schema
const Record = new Model("Record", {
  table: "TestRecordTable",
  partitionKey: "partitionKey",
  sortKey: "sortKey",
  schema: {
    partitionKey: {type: "string", alias: "id"},
    sortKey: {type: "string", hidden: false},
    sk: ["sortKey", 0],
    pk: ["partitionKey", 0]
  }
);

// DB Operation
const id = `record#${uuid.v4()}`;
const item = {
  pk: id,
  sk: id
};

from dynamodb-toolbox.

jeremydaly avatar jeremydaly commented on September 26, 2024

The easiest thing would probably be to use default instead.

// Schema
const Record = new Model("Record", {
  table: "TestRecordTable",
  partitionKey: "partitionKey",
  sortKey: "sortKey",
  schema: {
    partitionKey: {type: "string", alias: "id"},
    sortKey: {type: "string", onUpdate: true, default: (f) => f.partitionKey }
  }
);

I'm working on a better way to do this.

from dynamodb-toolbox.

jonterry-sans avatar jonterry-sans commented on September 26, 2024

Unfortunately this doesn't work if the partition key also has a default provider. Although your solution does reduce that amount of data that I have to provide to the Record.put() call.

from dynamodb-toolbox.

garretcharp avatar garretcharp commented on September 26, 2024

+1 to this feature, I have to duplicate values quite a bit for GSIs, and setting the default over and over is a bit annoying

from dynamodb-toolbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.