Skip to content

Instantly share code, notes, and snippets.

@viktorfa

viktorfa/database.js

Last active Aug 17, 2020
Embed
What would you like to do?
Database config for Strapi in Lambda with SQLite
// config/database.js
const getDatabaseConfig = ({ env }) => {
if (
env("IS_OFFLINE", null) === "true" ||
env("LAMBDA_RUNTIME_DIR", null) === null
) {
// In local simulated Lambda or normal Strapi
return {
connector: "bookshelf",
settings: {
client: "sqlite",
filename: env("DATABASE_FILENAME", ".tmp/data.db"),
},
options: {
useNullAsDefault: true,
},
};
} else {
// In Lambda on AWS
return {
connector: "bookshelf",
settings: {
client: "sqlite",
filename: env("DATABASE_FILENAME", "/tmp/data.db"),
},
options: {
useNullAsDefault: true,
},
};
}
};
module.exports = ({ env }) => ({
defaultConnection: "default",
connections: {
default: getDatabaseConfig({ env }),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment