Skip to content

Commit e2bcb11

Browse files
author
Michael Wittwer
committed
feat(aws-sdk-v3): resolve ts issues in snippets
1 parent e561484 commit e2bcb11

20 files changed

+42
-25
lines changed

snippets/app.snippet.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
import {DynamoDB} from '@aws-sdk/client-dynamodb'
12
import { DynamoStore } from '@shiftcoders/dynamo-easy'
2-
import * as AWS from 'aws-sdk/global'
33
import { Person } from './models'
44

55
// update the aws config with your credentials to enable successful connection
6-
AWS.config.update({ region: 'yourAwsRegion' })
7-
8-
const personStore = new DynamoStore(Person)
6+
const personStore = new DynamoStore(Person, new DynamoDB({ region: 'yourAwsRegion' }))
97

108
// add a new item
119
personStore.put({ id: 'wernerv', name: 'Werner Hans Peter Vogels', yearOfBirth: 1958 })

snippets/expressions/attribute2-condition.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import {DynamoDB} from '@aws-sdk/client-dynamodb'
12
import { attribute2, DynamoStore } from '@shiftcoders/dynamo-easy'
23
import { Person } from '../models'
34

4-
const personStore = new DynamoStore(Person)
5+
const personStore = new DynamoStore(Person, new DynamoDB({}))
56

67
personStore.delete('volgelsw')
78
.onlyIf(

snippets/expressions/or-not-and-condition.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { and, attribute, DynamoStore, not, or } from '@shiftcoders/dynamo-easy'
22
import { Person } from '../models'
3+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
34

4-
const personStore = new DynamoStore(Person)
5+
const personStore = new DynamoStore(Person, new DynamoDB({}))
56
personStore.delete('vogelsw')
67
.onlyIf(
78
or(

snippets/expressions/update-expression.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DynamoStore, update } from '@shiftcoders/dynamo-easy'
22
import { Person } from '../models'
3+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
34

4-
const personStore = new DynamoStore(Person)
5+
const personStore = new DynamoStore(Person, new DynamoDB({}))
56
personStore.update('vogelsw')
67
.operations(
78
update('name').set('Werner Vogels'),

snippets/looks-easy-right.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DynamoStore } from '@shiftcoders/dynamo-easy'
22
import { Person } from './models'
3+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
34

4-
const personStore = new DynamoStore(Person)
5+
const personStore = new DynamoStore(Person, new DynamoDB({}))
56

67
personStore
78
.scan()

snippets/multi-model-requests/batch-get.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { BatchGetRequest, BatchGetResponse } from '@shiftcoders/dynamo-easy'
22
import { AnotherModel, Person } from '../models'
3+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
34

45
const keysToFetch: Array<Partial<Person>> = [{ id: 'vogelsw' }]
56
const otherKeysToFetch: Array<Partial<AnotherModel>> = [{ propA: 'Foo', propB: 'Bar' }]
67

7-
new BatchGetRequest()
8+
new BatchGetRequest(new DynamoDB({}))
89
.forModel(Person, keysToFetch)
910
.forModel(AnotherModel, otherKeysToFetch)
1011
.exec()

snippets/multi-model-requests/batch-write.snippet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BatchWriteRequest } from '@shiftcoders/dynamo-easy'
22
import { AnotherModel, Person } from '../models'
3+
import { DynamoDB, ReturnConsumedCapacity } from '@aws-sdk/client-dynamodb'
34

45
const keysToDelete: Array<Partial<Person>> = [{ id: 'vogelsw' }]
56
const otherKeysToDelete: Array<Partial<AnotherModel>> = [{ propA: 'Foo', propB: 'Bar' }]
@@ -8,8 +9,8 @@ const objectsToPut: AnotherModel[] = [
89
{ propA: 'foo2', propB: 'bar2', updated: new Date() },
910
]
1011

11-
new BatchWriteRequest()
12-
.returnConsumedCapacity('TOTAL')
12+
new BatchWriteRequest(new DynamoDB({}))
13+
.returnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
1314
.delete(Person, keysToDelete)
1415
.delete(AnotherModel, otherKeysToDelete)
1516
.put(AnotherModel, objectsToPut)

snippets/multi-model-requests/transact-get.snippet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { TransactGetRequest } from '@shiftcoders/dynamo-easy'
22
import { AnotherModel, Person } from '../models'
3+
import { DynamoDB, ReturnConsumedCapacity } from '@aws-sdk/client-dynamodb'
34

4-
new TransactGetRequest()
5-
.returnConsumedCapacity('TOTAL')
5+
new TransactGetRequest(new DynamoDB({}))
6+
.returnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
67
.forModel(Person, { id: 'vogelsw' })
78
.forModel(AnotherModel, { propA: 'Foo', propB: 'Bar' })
89
.exec()

snippets/multi-model-requests/transact-write.snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {
77
TransactWriteRequest,
88
} from '@shiftcoders/dynamo-easy'
99
import { AnotherModel, Person } from '../models'
10+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
1011

1112
const objectToPut: AnotherModel = { propA: 'Foo', propB: 'Bar', updated: new Date() }
1213

13-
new TransactWriteRequest()
14+
new TransactWriteRequest(new DynamoDB({}))
1415
.transact(
1516
new TransactConditionCheck(Person, 'vogelsw').onlyIf(attribute('yearOfBirth').gte(1958)),
1617
new TransactDelete(AnotherModel, 'Foo', 'Bar'),
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DynamoStore } from '@shiftcoders/dynamo-easy'
22
import { Person } from '../models'
3+
import { DynamoDB } from '@aws-sdk/client-dynamodb'
34

4-
new DynamoStore(Person)
5+
new DynamoStore(Person, new DynamoDB({}))
56
.batchGet([{ id: 'a' }, { id: 'b' }])
67
.exec()
78
.then(res => console.log('fetched items:', res))

0 commit comments

Comments
 (0)