Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jay2
Product and Topic Expert
Product and Topic Expert

Who should read this blog?

If you're a developer working with CAP (SAP Cloud Application Programming Model) and seeking guidance on deploying your applications in the BTP (SAP Business Technology Platform) Cloud Foundry environment with SQLite database integration, this blog is tailor-made for you.

Motivation

Picture this: You're building an app for training sessions. Initially, we thought of using HANA Cloud, but then we thought, "Hey, let's try SQLite for simplicity during development and testing." Everything was smooth sailing while tinkering with it in our BAS (Business Application Studio). But when it came to deploying and testing the app, SQLite just wouldn't cut it. We needed to figure out how to make our app work with SQLite for development but still deploy smoothly. After some trial and error, we cracked the code.

Just a heads-up: This trick is only for playing around with your app during development and testing. It's not suitable for the big leagues of production.

Pre-requisite

  1. Business application studio
  2. Cloud foundry space
  3. Create CAP project from template

Please following steps after you have created a CAP project -

  • Update the package.json to reflect these entries.
{
    "requires": {
        "db": {
            "kind": "sqlite",
            "credentials": {
                "database": "db.sqlite"
            }
        },
        "auth": {
            "[development]": {
                "kind": "dummy"
            },
            "[production]": {
                "kind": "basic",
                "users": {
                    "admin": {
                        "password": "admin"
                    }
                }
            }
        }
    }
}​
  • Open package.json from root directory and modify following-
    1. Remove "@cap-js/sqlite” from dev dependencies and add "@cap-js/sqlite" to dependencies.
    2. Open Terminal and run npm install
  • Now let's modify mta.yaml file where we are going to add a couple of commands which will deploy the SQLite and also copy the SQLite file during deployment.
build-parameters:
 before-all:
- builder: custom 
  commands:
   - npmci
   - npx cds build --production - npx cds deploy
   - cp -r db.sqlite gen/srv
  • Last step is build and deploy your application on cloud foundry 
    1. mbt build 
    2. cf deploy ‘path_to_your_mta_archive’

Conclusion : 

With this quick tweak, you'll be all set to create and deploy CAP applications with SQLite databases. Hopefully, this helps your next project!