This repository was archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Is there anyway to access the table schema of an annotated domain object #203
Copy link
Copy link
Open
Description
Firstly awesome tool I really enjoy using it thanks a lot!
My question
Lets say I have an annotated domain object e.g
import { attribute, table, hashKey } from '@aws/dynamodb-data-mapper-annotations';
import { v4 as uuidv4 } from 'uuid';
abstract class Identifiable {
@hashKey({ defaultProvider: () => uuidv4() })
id: string;
}
@table('User')
class User extends Identifiable {
@rangeKey()
email: string;
@attribute()
firstName: string;
@attribute()
lastName: string;
}
export default User;
This means that from another .ts file I can do something like
import User from 'path/to/user'
mapper.ensureTableExists(User, {readCapacityUnits: 5, writeCapacityUnits: 5})
.then(() => {
// the table has been provisioned and is ready for use!
})
But is there anyway that I can get the table information (i.e; tableName with prefix, hashKey, rangeKey).
I would want something like
import User from 'path/to/user'
const tableData = myMagicFunction(User)
console.log(tableData) //logs {tableName: 'some-prefix-User', hashKey : 'id', rangeKey: 'email', attributes: ['id','email','firstName', 'lastName'] }
Why I want to do this
I am using dynamodb-data-mapper-js in a lambda function and building my stack with CDK. I don't want to have to define my schema (table names, hash keys etc..) twice (once in the lambda for using that tables and once in CDK for building them). I would rather be able to build the tables by importing the schema defined with dynamodb-data-mapper-js
Metadata
Metadata
Assignees
Labels
No labels