Good day fellow CAPpers,
Today I'll share one of the lessons I've learned working with CAP, something that may not be clear in the current tutorials or documentation. It's about deploying a CAP application using SQLite on BTP, Cloud Foundry environment. The key is to make it very clear to the application that you want SQLite, because the default option is HANA, or maybe Postgres. On the capire documentation, they recommend SQLite only for development.
In your package.json, you have to include the sqlite dependency as a project dependency, not only a development one:
"dependencies": {
"@cap-js/sqlite": "^1.7.3",
"@sap/cds": "^8",
"express": "^4",
"sqlite3": "^5"
},
"devDependencies": {
"@sap/cds-dk": "^8",
"@sap/eslint-plugin-cds": "^3"
},
As you may have noted, there are 2 sqlite dependencies: @cap-js/sqlite and sqlite3. The former is supported by the CAP team and should be preferred, but it didn't work in the past when deploying on BTP. Therefore, I had also to include the latter one, which is the default Node.js library for SQLite.
To work with in-memory SQLite is easy. You only need to include in your package.json (or even better in your .cdsrc.json) :
"cds": {
"requires": {
"db": {
"kind": "sqlite",
"impl": "@cap-js/sqlite",
"credentials": {
"url": ":memory:"
}
}
}
}
Optionally, you may also include under the requires level:
"features": {
"in_memory_db": true
}
"cds": {
"requires": {
"db": {
"kind": "sqlite",
"impl": "@cap-js/sqlite",
"credentials": {
"url": "db.sqlite"
}
}
}
}
_schema-version: '3.1'
ID: my-app-id
version: 1.0.0
description: "My app description."
build-parameters:
before-all:
- builder: custom
commands:
- npm ci
- npx cds build --production
- xcopy .\\db\\data .\\gen\\srv\\srv\\data\\ /y
- xcopy .\\db.sqlite .\\gen\\srv /y
- cp -r db/data gen/srv/srv/data
- cp -r db.sqlite gen/srv
I'd like to thank:
May this post help you on your troubleshooting. Reply if you find any issues so I, and the community, can help.
Lucas Magrini Rigo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |