Search

    Using Databases

    This guide is about defining, providing, implementing, deploying, and publishing services — so about Service Providers in general.

    Content

    Deployment

    Get an overview of your deployment options, which will be explained in the following section.

    SQLite

    The fastest way to let your application run is using a local SQLite database via the npm module sqlite3, which is a devDependency of your project. Using the command line cds deploy --to sqlite helps you deploy the database parts of the project to a local SQLite database. It

    • Creates an SQLite database file in your project.
    • Drops existing tables and views, and re-creates them according the CDS model.
    • Deploys CSV files with initial data.

    See it in action

    SAP HANA

    Turning into a production-near mode, you can use SAP HANA Cloud in your project. There are two ways to include SAP HANA in your setup: Use SAP HANA in a hybrid mode, meaning running your services locally and connect to your database in the cloud, or running your whole application on SAP Business Technology Platform. This is possible either in trial accounts or in productive accounts. To make the following configuration steps work, we assume that you’ve provisioned, set up, and started, for example, your SAP HANA Cloud instance in the trial environment. If you need to prepare your SAP HANA first, see How to Get an SAP HANA Cloud Instance for SAP Business Technology Platform, Cloud Foundry environment to learn about your options.

    Enhance Project Configuration for SAP HANA Cloud

    To prepare the project, execute:

    cds add hana
    

    This configures deployment for SAP HANA to use the hdbtable and hdbview formats. The default format of hdbcds is not available on SAP HANA Cloud.

    For Node.js

    No further configuration is necessary. For your information, this is what the previous command has changed in package.json:

    For Java

    See tutorial Use SAP HANA as the Database for a CAP Java Application for the rest of the configuration.

    Deploy using cds deploy

    cds deploy --to hana lets you deploy just the database parts of the project to an SAP HANA instance. The server application (the Node.js or Java part) still runs locally and connects to the remote database instance, allowing for fast development roundtrips.

    Make sure that you’re logged in to Cloud Foundry. Then in the project root folder, just execute:

    cds deploy --to hana
    

    Behind the scenes, cds deploy --to hana does the following:

    • Compiles the CDS model to SAP HANA files (usually in gen/db, or db/gen)
    • Generates hdbtabledata files for the CSV files in the project. If an hdbtabledata file is already present next to the CSV files, no new file is generated.
    • Creates a Cloud Foundry service of type hdi-shared, which creates an HDI container. Also, you can explicitly specify the name like so: cds deploy --to hana:<myService>.
    • Starts @sap/hdi-deploy locally. Should you need a tunnel to access the database, you can specify its address with --tunnel-address <host:port>.
    • Puts default-env.json in the project root. With this information cds watch/run can connect to the HDI container at runtime using the production profile (--production).

    If you run into issues, see the Troubleshooting guide.

    Deploy Using cf deploy or cf push

    See the Deploying to Cloud Foundry guide for how to deploy the complete application to SAP BTP.

    Providing Initial Data

    CSV files in your project are picked up by deployments for both SQLite and SAP HANA. The following conventions apply:

    • The files must be located in folders db/csv, db/data/, or db/src/csv.
    • They contain data for one entity each. File names must follow the pattern <namespace>-<entity>.csv, for example, my.bookshop-Books.csv.
    • They must start with a header line that lists the needed element names.

    🚫 Danger On SAP HANA, only use CSV files for configuration data that can’t be changed by application users. CSV files are deployed as hdbtabledata, which assumes exclusive ownership of the data. It’s overwritten with the next application deployment.
    If you have accidentally deployed such data to a productive database, see this troubleshooting entry for how to recover from this situation.

    Show/Hide Beta Features