File tree Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,11 @@ declare namespace ConnectDynamoDB {
32
32
* Upgrade to DynamoDB's TimeToLive configuration.
33
33
*/
34
34
reapInterval ?: number ;
35
+ /**
36
+ * Disable initialization.
37
+ * Useful if the table already exists or if you want to skip existence checks in a serverless environment such as AWS Lambda.
38
+ */
39
+ initialized ?: boolean ;
35
40
}
36
41
37
42
interface DynamoDBStoreOptionsSpecialKey {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ const options: DynamoDBStoreOptions = {
33
33
writeCapacityUnits : 25 ,
34
34
specialKeys : specialKeysOptions ,
35
35
skipThrowMissingSpecialKeys : true ,
36
+ initialized : true ,
36
37
} ;
37
38
38
39
expectType < express . RequestHandler > (
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ module.exports = function (connect) {
45
45
function DynamoDBStore ( options ) {
46
46
options = options || { } ;
47
47
Store . call ( this , options ) ;
48
- this . initialized = false ;
48
+ this . initialized = options . initialized || false ;
49
49
this . prefix = null == options . prefix ? "sess:" : options . prefix ;
50
50
this . hashKey = null == options . hashKey ? "id" : options . hashKey ;
51
51
this . readCapacityUnits =
Original file line number Diff line number Diff line change @@ -148,6 +148,28 @@ describe("DynamoDBStore", () => {
148
148
await client . send ( new DeleteTableCommand ( { TableName : tableName } ) ) ;
149
149
} ) ;
150
150
} ) ;
151
+
152
+ describe ( "skip initializing" , ( ) => {
153
+ const tableName = "sessions-test-" + Math . random ( ) . toString ( ) ;
154
+ const store = new DynamoDBStore ( {
155
+ client,
156
+ table : tableName ,
157
+ initialized : true ,
158
+ } ) ;
159
+ const describeSessionsTableSpy = sinon . spy (
160
+ store ,
161
+ "describeSessionsTable"
162
+ ) ;
163
+ const createSessionsTableSpy = sinon . spy ( store , "createSessionsTable" ) ;
164
+
165
+ it ( "Should skip table existence checks and creation" , async ( ) => {
166
+ describeSessionsTableSpy . notCalled . should . equal ( true ) ;
167
+ createSessionsTableSpy . notCalled . should . equal ( true ) ;
168
+ await store . initialize ( ) ;
169
+ describeSessionsTableSpy . notCalled . should . equal ( true ) ;
170
+ createSessionsTableSpy . notCalled . should . equal ( true ) ;
171
+ } ) ;
172
+ } ) ;
151
173
} ) ;
152
174
153
175
describe ( "Setting" , ( ) => {
You can’t perform that action at this time.
0 commit comments