Saltar al contenido

elemento de actualización de node.js AWS dynamodb

Revisamos de forma completamente cada noticia de nuestro sitio web con la meta de mostrarte en todo momento información veraz y actual.

Solución:

Esto es exactamente lo que dice AWS.DynamoDB.DocumentClient update el método lo hace.

Ya hay un código de muestra sobre cómo usar el update método aquí para AWS SDK para JavaScript en Node.js.

Por ejemplo:

'use strict';

const aws = require('aws-sdk');

// It is recommended that we instantiate AWS clients outside the scope of the handler 
// to take advantage of connection re-use.
const docClient = new aws.DynamoDB.DocumentClient();

exports.handler = (event, context, callback) => 
    const params = 
        TableName: "MYTABLE",
        Key: 
            "id": "1"
        ,
        UpdateExpression: "set variable1 = :x, #MyVariable = :y",
        ExpressionAttributeNames: 
            "#MyVariable": "variable23"
        ,
        ExpressionAttributeValues: 
            ":x": "hello2",
            ":y": "dog"
        
    ;

    docClient.update(params, function(err, data) 
        if (err) console.log(err);
        else console.log(data);
    );
;

puedes actualizar attributes dinamicamente. vea el código a continuación.

export const update = (item) => 
  console.log(item)
  const Item = 
    note: "dynamic",
    totalChild: "totalChild",
    totalGuests: "totalGuests"
  ;
  let updateExpression='set';
  let ExpressionAttributeNames=;
  let ExpressionAttributeValues = ;
  for (const property in Item) 
    updateExpression += ` #$property = :$property ,`;
    ExpressionAttributeNames['#'+property] = property ;
    ExpressionAttributeValues[':'+property]=Item[property];
  

  
  console.log(ExpressionAttributeNames);


  updateExpression= updateExpression.slice(0, -1);
  
  
   const params = 
     TableName: TABLE_NAME,
     Key: 
      booking_attempt_id: item.booking_attempt_id,
     ,
     UpdateExpression: updateExpression,
     ExpressionAttributeNames: ExpressionAttributeNames,
     ExpressionAttributeValues: ExpressionAttributeValues
   ;

   return dynamo.update(params).promise().then(result => 
       return result;
   )
   

Aquí hay un método de utilidad para hacer eso:

update: async (tableName, item, idAttributeName) => 

    var params = 
        TableName: tableName,
        Key: ,
        ExpressionAttributeValues: ,
        ExpressionAttributeNames: ,
        UpdateExpression: "",
        ReturnValues: "UPDATED_NEW"
    ;

    params["Key"][idAttributeName] = item[idAttributeName];

    let prefix = "set ";
    let attributes = Object.keys(item);
    for (let i=0; i

Sección de Reseñas y Valoraciones

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *