Giter VIP home page Giter VIP logo

Comments (12)

tywalch avatar tywalch commented on June 4, 2024 1

I'll begin taking a look at this, thank you. As a stop gap, the .params() might be useful in the short term.

from electrodb.

tywalch avatar tywalch commented on June 4, 2024 1

Something like this should also work in there interim:

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { 
  DynamoDBDocumentClient, 
  PutCommand,
  GetCommand,
  ScanCommand,
  QueryCommand,
  UpdateCommand,
  DeleteCommand,
  BatchGetCommand,
  BatchWriteCommand,
} from '@aws-sdk/lib-dynamodb'

const clientV3 = DynamoDBDocumentClient.from(new DynamoDBClient({}));

class DocumentClientWrapper {
  client: DynamoDBDocumentClient;
  constructor(client: DynamoDBDocumentClient) {
    this.client = client;
  }
  get(params: any) {
    return {
      promise: async () => {
        const command = new GetCommand(params);
        return this.client.send(command);
      }
    }
  }
  put(params: any) {
    return {
      promise: async () => {
        const command = new PutCommand(params);
        return this.client.send(command);
      }
    }
  }
  update(params: any) {
    return {
      promise: async () => {
        const command = new UpdateCommand(params);
        return this.client.send(command);
      }
    }
  }
  delete(params: any) {
    return {
      promise: async () => {
        const command = new DeleteCommand(params);
        return this.client.send(command);
      }
    }
  }
  batchWrite(params: any) {
    return {
      promise: async () => {
        const command = new BatchWriteCommand(params);
        return this.client.send(command);
      }
    }
  }
  batchGet(params: any) {
    return {
      promise: async () => {
        const command = new BatchGetCommand(params);
        return this.client.send(command);
      }
    }
  }
  scan(params: any) {
    return {
      promise: async () => {
        const command = new ScanCommand(params);
        return this.client.send(command);
      }
    }
  }
  query(params: any) {
    return {
      promise: async () => {
        const command = new QueryCommand(params);
        return this.client.send(command);
      }
    }
  }
  createSet(value: any) {
    if (Array.isArray(value)) {
      return new Set(value);
    } else {
      return new Set([value]);
    }
  }
}

// client compatible with ElectroDB:
const client = new DocumentClientWrapper(clientV3);

from electrodb.

tywalch avatar tywalch commented on June 4, 2024 1

@ShivamJoker @moltar I have just merged and published v3 support in version 1.7.0! Please let me know if you have any issues when using the v3 client and I will make it priority to resolve your issues 👍

from electrodb.

moltar avatar moltar commented on June 4, 2024 1

Pros:

  • Future-proofing. The end of support for v2 will probably be announced soon, since v3 has been out for a while. And other languages had already EOS announced.
  • Native TypeScript support, without @types/*
  • It is mostly codegen'ed from standard definitions, which ensures that all APIs are compatible
  • Modular (use only what you need)
  • v2 is a heavy dep (if you bundle) (3MB). In v3, take a few common clients, and it'll be ~ 1-2MB and there is a TON of room for them to improve this still. The code is not yet well optimized for bundling.

Cons:

  • Not available in the Lambda environment. (Although this was an anti-pattern anyways, and was not recommended to be used that way.)
  • Less stable and less battle-tested.

from electrodb.

moltar avatar moltar commented on June 4, 2024

Thanks Tyler, I'll give it a shot!

from electrodb.

ShivamJoker avatar ShivamJoker commented on June 4, 2024

Any updates on this?

from electrodb.

tywalch avatar tywalch commented on June 4, 2024

I have been traveling frequently for the past few weeks and haven't had a chance to get this in. This is still on my radar and I am hoping to have more news on it soon.

from electrodb.

ShivamJoker avatar ShivamJoker commented on June 4, 2024

Thanks a lot I'll try it.
Also I am using CDK so should I just make a table and your library will add GSI based on schemas?

from electrodb.

moltar avatar moltar commented on June 4, 2024

Nice one @tywalch!

I still haven't had a chance to try this package out 🙈

Maybe this will give me a boost!

from electrodb.

moltar avatar moltar commented on June 4, 2024

Btw, should @aws-sdk/lib-dynamodb be a peer dep?

Because this will increase bundle sizes for everyone, even if they do not use the v3 SDKs.

These v3 SDKs are quite bloated, unfortunately!

https://bundlephobia.com/package/[email protected]

screenshot-20220321T105644-Fqy4cKb2

from electrodb.

ShivamJoker avatar ShivamJoker commented on June 4, 2024

@moltar so are there any benefits of using V3 with electrodb? In terms of performance

from electrodb.

ShivamJoker avatar ShivamJoker commented on June 4, 2024

from electrodb.

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.