dyngoose
Version:
Elegant DynamoDB object modeling for Typescript
102 lines (72 loc) • 2.64 kB
text/typescript
import { Dyngoose } from '.'
.$Table({
name: `testable-${Math.random()}`,
backup: false,
})
export class TestableTable extends Dyngoose.Table {
.$PrimaryKey('id', 'title')
public static readonly primaryKey: Dyngoose.Query.PrimaryKey<TestableTable, number, string>
.$GlobalSecondaryIndex({ hashKey: 'title', projection: 'ALL' })
public static readonly titleIndex: Dyngoose.Query.GlobalSecondaryIndex<TestableTable>
.$DocumentClient()
public static readonly documentClient: Dyngoose.DocumentClient<TestableTable>
.Attribute.Any()
public generic: any
.Attribute.Number({ default: 1 })
public id: number
.Attribute()
public dynamic: number | string
.Attribute.String()
public title: string
.Attribute.Date({ nowOnCreate: true })
public createdAt: Date
.Attribute.Date({ nowOnUpdate: true })
public updatedAt: Date
.Attribute.Date({ timeToLive: true })
public expiresAt: Date
.Attribute.Date({ unixTimestamp: true })
public unixTimestamp: Date
.Attribute.Date({ millisecondTimestamp: true })
public msTimestamp: Date
.Attribute.Date({ dateOnly: true })
public dateOnly: Date
.Attribute.Date()
public fullDate: Date
.Attribute('String', { default: 'SomeDefault' })
public defaultedString: string
.Attribute.String()
public testString: string
.Attribute.StringSet()
public testStringSet: Set<string>
.Attribute.StringSet({ array: true })
public testStringSetArray: string[]
.Attribute.String({ lowercase: true })
public lowercaseString: string
.Attribute.String({ uppercase: true })
public uppercaseString: string
.Attribute.String({ trim: true })
public trimmedString: string
.Attribute.Number()
public testNumber: number
.Attribute.NumberSet()
public testNumberSet: Set<bigint | number> | null
.Attribute.NumberSet({ default: () => new Set([42, 420]) })
public testNumberSetWithDefaults: Set<number>
.Attribute.Number()
public testBigInt: bigint
.Attribute.String({ name: 'testAttributeNameNotMatchingPropertyName' })
public testAttributeNaming: string
.Attribute.Map({
name: 'someMap',
attributes: {
property1: Dyngoose.Attribute.String({ name: 'someProperty1' }),
},
})
public testMap?: { property1?: string }
}
before(async () => {
await TestableTable.createTable()
})
after(async () => {
await TestableTable.deleteTable()
})