ASK Lowdb Persistence Adapter
An Alexa Skills Kit persistence adapter for lowdb.
Why?
For deployed Alexa Skills, you should use a proper persistence layer (for example Amazon S3 using the ask-sdk-s3-persistence-adapter), but for local development S3 can be awkward to use. Using lowdb is great because it saves the data locally making it easy to debug and work with.
Installation
Install adapter:
npm i ask-lowdb-persistence-adapter
Install peer dependencies:
npm i lowdb
Usage
Basic usage:
const LowdbPersistenceAdapter = ; // ... const options = // the name of the lowdb database, default value shown here dbName: "persistenceAttributes.db.json" // the name of the key to store persistence attributes under in the // database, default value shown here attributesKey: "persistenceAttributes"; AlexaSkillBuilders ;
Since the primary purpose of this adapter is for use locally when a proper persistence layer is unavailable, a nice pattern for creating your persistence adapter is to use a factory. For example, if one wanted to use S3 when it was available and lowdb otherwise, one could implement it like so:
const LowdbPersistenceAdapter = ;const S3PersistenceAdapter = S3PersistenceAdapter; { thiss3BucketName = s3BucketName; } { if thiss3BucketName return bucketName: thiss3BucketName ; else return ; } // ... const persistenceAdapterFactory = processenvS3_PERSISTENCE_BUCKET; AlexaSkillBuilders ;