Giter Club home page Giter Club logo

Comments (6)

mobsense avatar mobsense commented on July 21, 2024

Can you test if using params.fields works. i.e.

 ProjectionExpression: params.fields.length ? params.fields.join(', ') : undefined

from dynamodb-onetable.

mkovel avatar mkovel commented on July 21, 2024

@mobsense
I tried with this.params.fields.length ? this.params.fields.join(', ') : undefined and it was working, but then i faced with another issue.
entity filed can not has a name as name, and these cases should use ExpressionAttributeNames,
I am trying to say that params.fields solves the problem only partially.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Can you please give more details and an example. I don't fully understand your comment. Sorry.

If it is a new issue, please open a new issue.

from dynamodb-onetable.

mkovel avatar mkovel commented on July 21, 2024

I did your fix in Expression.js

...
ProjectionExpression: params.fields && params.fields.length ? params.fields.join(', ') : undefined,
...

Then created a small test.

const { Model, Table } = require('dynamodb-onetable');
const { documentClient } = require('./src/db');

const myTableName = `myTable`;
const table = new Table({
  client: documentClient,
  name: myTableName,
});

const RoleModel = new Model(table, 'Role', {
  fields: {
    pk: { value: 'rbac' },
    sk: { value: 'Role:${name}' },

    name: { type: String, required: true },
    permissions: { type: Array, required: true },
  },
});

(async () => {

  // ### add three role1, role2,  role3
  await Promise.all(
    ['1', '2', '3'].map(async (name) => {
      await RoleModel.create({
        name: `role${name}`,
        permissions: [`get:/api/endpoint${name}`],
      });
    }),
  );

  // this Model.get() works fine
  const roleOk = await RoleModel.get(
    {
      _type: `Role`,
    },
    {
      fields: [
        //
        'updated',
      ],
    },
  );
  console.log('### logOK:', roleOk);
  // ### logOK: { updated: 1620050849535 }

  const roleErr = await RoleModel.get(
    {
      name: `role1`,
    },
    {
      fields: [
        //
        'name',
        'permissions',
      ],
    },
  );
  console.log('### log Err:', roleErr);
 // it throws error 
 // Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: name
// the same error for  'permissions' field name


})();

@mobsense
Hope now it's clear.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Thank you. We can reproduce this now. Will update with a fix later today.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

The core issues is that ProjectionExpressions must use symbolic Attribute Names and Values to avoid the huge DynamoDB reserved word list.

This fix is cleaning up the handling of Attribute Names and Values by adding two functions addName and addValue, and also adding duplicate removal and optimization. i.e. you can use the same attribute name / value and it will only use one reference.

from dynamodb-onetable.

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.