Giter Site home page Giter Site logo

lucasmafra / type-dynamo Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 4.0 9.29 MB

Easy-to-use ORM for your Typescript projects with DynamoDB and Node.js

License: MIT License

TypeScript 100.00%
orm dynamodb typescript database typedynamo typeorm datamapper nosql aws

type-dynamo's People

Contributors

lucasmafra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

type-dynamo's Issues

withSortKeyCondition(beginsWith()) throws error

When you use the beginsWith expression with the withSortKeyCondition a dynamo error is thrown. I'm using the TypeDynamo version 0.1.3.

Here is my code:

const items = await this.repo.onIndex.idAllRoomsKeyIndex
      .find({ id: userId })
      .withSortKeyCondition(beginsWith('all'))
      .execute()

And here is the error:

{ ValidationException: Invalid KeyConditionExpression: Invalid function name; function: beginsWith,
message: 'Invalid KeyConditionExpression: Invalid function name; function: beginsWith',
code: 'ValidationException',
time: 2018-10-29T19:55:50.196Z,
requestId: 'PKM2UTJ3ERP495736KR0SJO4PJVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 35.338869028594075 }

That is probably happening because the correct dynamo sintax is begins_with() instead of beginsWith()

Not pushed to npm?

Sorry to raise another issue!

Im not sure whats wrong either the docs or the code or something hasnt been pushed to npm or whatever but a lot of the examples dont work.

For example:

// dynamo.config.ts
import { TypeDynamo } from 'type-dynamo'
export const typeDynamo = new TypeDynamo({
  accessKeyId: process.env.accessKeyId,
  secretAccessKey: process.env.secretAccessKey,
})

Doesnt compile as it needs the region param.

import { UserRepo } from './User'

async function getUserById(id: string) { 
  const result = await UserRepo.find({id}).execute() // pass the id as an object { "id": id }
  const user = result.data
  console.log(user.id, user.name, user.email, user.age) // you're type-safe
}

find() doesnt exist on the repo:

image

Just thought you would want to know ๐Ÿ‘

query operation not working properly

Current Behavior

When i try to query, using any sortKeyCondition and error is thrown:

{ ValidationException: Invalid KeyConditionExpression: An expression attribute name used in the document path is not defined; attribute name: #pff79e8cns

Possible Solution

Apparently, the table schema definition, for CompositeKey is not adding the sort key do it's TableSchema object

Steps to Reproduce

private repo = typeDynamo.define(UserRelationTable, {
    tableName: TABLE_NAME,
    partitionKey: 'id',
    sortKey: 'sort'
  }).getInstance()
 const dbResult = await this.repo.find({ id })
      .withSortKeyCondition(beginsWith('test'))
      .execute()

Detailed Description

Add the sort key to the TableSchema when creating the CompositeKey table

Possible Implementation

Change the buildTableSchema function in src/schema/type-dynamo/define-table/composite-key/composite-key.ts to:

private buildTableSchema(schema: any): TableSchema {
        const tableSchema: TableSchema = {
            tableName: schema.tableName,
            partitionKey: schema.partitionKey,
            sortKey: schema.sortKey,
            writeCapacity: schema.writeCapacity || 1,
            readCapacity: schema.readCapacity || 1,
        }
        return tableSchema
    }

Unit Tests?

Hey,

This is a really nice looking library, im very impressed with your usage of Typescript, but im just wondering about the lack of automated tests. Was there a specific reason why you omitted those?

Thanks again, its an awesome bit of work.

TypeError: dynamo.define(...).withGlobalIndex is not a function

Hello!

I would like to report a possible bug. I get the error TypeError: dynamo.define(...).withGlobalIndex is not a function when defining my table with an index.
Here is my table definition:

const dynamo = new TypeDynamo({ region: process.env.region || 'us-east-1' })

const userRepo = dynamo.define(UserTable, {
  tableName: UserSchema.tableName,
  partitionKey: 'id',
}).withGlobalIndex({
  indexName: 'emailIndex',
  partitionKey: 'email',
  projectionType: 'ALL',
}).getInstance()

and here is my UserTable class

 export class UserTable {
  id: string
  username: string
  name: string
  email: string
}

I believe the error comes from the file src/schema/type-dynamo/type-dynamo.ts, where your implementation of the function TypeDynamo.define returns a DynamoTableWithSimpleKey instead of a TypeDynamoDefineTableSimpleKey.

        if (schema.sortKey !== undefined) {
            return new TypeDynamoDefineTableCompositeKey(this.dynamoPromise, schema).getInstance() as any
        }
        return new TypeDynamoDefineTableSimpleKey(this.dynamoPromise, schema).getInstance() as any

probably because of the getInstance()? Let me know if I am doing something wrong, that might well be the case!

Great lib by the way!

Installation via NPM failing

When I try to install this package in the provided type-dynamo-examples/serverless-todo-application example an error like this crashes the installation:

ERR! path /home/lukas/IdeaProjects/type-dynamo-examples/serverless-todo-application/node_modules/type-dynamo/dist/cli.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/lukas/IdeaProjects/type-dynamo-examples/serverless-todo-application/node_modules/type-dynamo/dist/cli.js'
npm ERR! enoent This is related to npm not being able to find a file. 

It seems like the referenced cli.js is missing from the dist folder which is confirmed, if you look into unpkg: https://www.unpkg.com/browse/[email protected]/dist/. Would it be possible to add this file to the Github Repo in order to fix the build?

aws-sdk as dev dependency

Is there any special reason for aws-sdk being a direct dependecy? This increases my bundle size significally, since webpack is not able to exclude a dependecy of a dependecy properly, I've done some workarounds, but it would be much easier if aws-sdk was included as a devDependency or peerDependency

An example, my code:

import { APIGatewayEvent, Context, Callback } from 'aws-lambda'
import { TypeDynamo } from 'type-dynamo'

export const typeDynamo = new TypeDynamo({ region: process.env.REGION || 'us-east-1' })

export async function teste(event: APIGatewayEvent, context: Context, callback: Callback) {
  try {
    console.log(typeDynamo)
    callback(undefined, {})
  } catch (err) {
    callback(undefined, { err })
  }
}

This are my dependencies:

  "dependencies": {
    "type-dynamo": "^0.1.4"
  },
  "devDependencies": {
    "@types/aws-lambda": "8.10.1",
    "@types/aws-sdk": "2.7.0",
    "aws-sdk": "2.277.1",
    "serverless": "1.30.1",
    "serverless-offline": "3.25.6",
    "serverless-webpack": "5.1.1",
    "ts-loader": "4.2.0",
    "tslint": "5.11.0",
    "typescript": "2.9.2",
    "webpack": "4.5.0",
    "webpack-bundle-analyzer": "3.0.2",
    "webpack-node-externals": "1.7.2"
  },

And this is my bundle:

captura de tela 2018-11-01 as 10 03 26

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.