CAP MySQL Database Adapter

7.9.0 · active · verified Wed Apr 22

cds-mysql is a database adapter for the SAP Cloud Application Programming Model (CAP) framework, enabling applications to connect to and interact with MySQL and MariaDB databases. It is heavily inspired by the cds-pg module. The current stable version is 7.9.0, supporting Node.js 18 and npm 9 or higher. This module allows CAP applications to leverage MySQL/MariaDB for data persistence, offering features such as fundamental CRUD operations, deep insert for associations/compositions, Fiori draft support, temporal aspects (without time-travel queries), incremental IDs, CSV-based initial data provisioning, full-text search, schema migration optimization, media attachment support, localized data, and multi-tenancy including experimental `@sap/cds-mtxs` integration. It differentiates itself by providing comprehensive CAP feature support for MySQL, aiming for seamless integration with the CAP runtime.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install cds-mysql, configure it in `package.json` or `.cdsrc.json`, and set up database credentials using environment variables for a local CAP project.

npm i cds-mysql mysql2

// package.json (or .cdsrc.json)
// Add this to your CAP project's package.json to configure cds-mysql
// This tells CAP to use 'mysql' as the database kind.
{
  "requires": {
    "db": {
      "kind": "mysql"
    }
  }
}

// .env file in your local CDS project root
// Fill with your database credentials
CDS_REQUIRES_DB_CREDENTIALS_HOST=127.0.0.1
CDS_REQUIRES_DB_CREDENTIALS_PORT=3306
CDS_REQUIRES_DB_CREDENTIALS_DATABASE=your_database_name
CDS_REQUIRES_DB_CREDENTIALS_USER=your_db_user
CDS_REQUIRES_DB_CREDENTIALS_PASSWORD=your_db_password

// To start the CAP server with MySQL:
npx cds-serve

view raw JSON →