benhutchins / dyngoose

Elegant DynamoDB object modeling for Typescript.
https://www.npmjs.com/package/dyngoose
ISC License
89 stars 14 forks source link

Question: different fieldname than member name #673

Closed ktwbc closed 5 months ago

ktwbc commented 8 months ago

I can't find in the docs (and am unsure if it's supported) on how to specify a different field name in the class file than the table field name. For example:

 @Dyngoose.Attribute({ name: 'subscriber_id' })
  subscriberId: string;

or something along those lines where the object after a get() would be myObject.subscriberId but the actual ddb table would have that value as "subscriber_id".

I previously used dynamo-types which I know this package used as a source, was that feature brought along?

ktwbc commented 8 months ago

I did find in the source code it appears to use

@Dyngoose.Attribute('String', { name: 'subscriber_id' })

or alternately

@Dyngoose.Attribute.String({ name: 'subscriber_id' })

so if using an alternate name you must specify the type, but none of this is in the docs anywhere that I could find.

benhutchins commented 8 months ago

You got it. That's true, only recently added support for using @Dyngoose.Attribute without a type, but likely could simply usage when you want to allow the type to be inferred.

I'll update the usage and docs with the next release.