lucasmafra / type-dynamo Goto Github PK
View Code? Open in Web Editor NEWEasy-to-use ORM for your Typescript projects with DynamoDB and Node.js
License: MIT License
Easy-to-use ORM for your Typescript projects with DynamoDB and Node.js
License: MIT License
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()
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:
Just thought you would want to know ๐
Hey, your link to demo (https://github.com/lucasmafra/type-dynamo/blob/master) doesnt work in the Readme.
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
Apparently, the table schema definition, for CompositeKey is not adding the sort key do it's TableSchema
object
private repo = typeDynamo.define(UserRelationTable, {
tableName: TABLE_NAME,
partitionKey: 'id',
sortKey: 'sort'
}).getInstance()
const dbResult = await this.repo.find({ id })
.withSortKeyCondition(beginsWith('test'))
.execute()
Add the sort key to the TableSchema
when creating the CompositeKey table
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
}
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.
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!
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?
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:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.