8

cds deploy to sqlite in-memory database

 3 years ago
source link: https://blogs.sap.com/2021/04/25/cds-deploy-to-sqlite-in-memory-database/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Technical Articles
Posted on April 25, 2021 Less than a 1 minute read

cds deploy to sqlite in-memory database

1 Like 30 Views 1 Comment

cds deploy deploys a given model to a database.

The example below deploys models to the sqlite database myWorkOrder in the directory db

cds deploy --to sqlite:db/myWorkOrder 

The deployment outputs the following information, indicating the database is filled with the initial data in the csv files locates by convention at db/data. Deployment was successful.

> filling jem.mwo.Interactions from db/data/jem.mwo-Interactions.csv 
> successfully deployed to ./db/myWorkOrder

Now we have a persistent database and the package.json is updated accordingly.

From time to time, however, I change my mind and I want to update the initial data and revert to working from memory.

I’ve found that cds deploy to the special database :memory: deploys to sqlite in memory and updates the package.json accordingly.

cds deploy --to sqlite::memory:

Running this command provides the following output.

> filling jem.mwo.Interactions from db/data/jem.mwo-Interactions.csv 
> successfully deployed to sqlite in-memory db
> updated ./package.json

and the package.json is updated

  "cds": {
    "requires": {
      "db": {
        "kind": "sqlite",
        "model": "*",
        "credentials": {
          "database": ":memory:"
        }
      }
    }
  },

This approach allows me to avoid editing package.json manually or remembering to explicitly run from memory. Now I’m free to continue to work in memory until such times as I wish to deploy the model again to a persistent database using the more familiar call.

cds deploy --to sqlite:db/myWorkOrder 

Perhaps you might find this useful.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK