What is @sap/cds?
@sap/cds (SAP Cloud Application Programming Model) is a framework for building enterprise-grade services and applications. It provides a comprehensive set of tools and libraries to develop, deploy, and manage data-centric applications. The package supports defining data models, services, and business logic, and it integrates seamlessly with SAP HANA and other databases.
What are @sap/cds's main functionalities?
Defining Data Models
This feature allows you to define data models using CDS (Core Data Services) and interact with them. The code sample demonstrates defining a simple data model for a bookshop and implementing a service to read book data.
const cds = require('@sap/cds');
const { entities } = cds.model;
const Books = entities('my.bookshop.Books');
module.exports = cds.service.impl(async function() {
this.on('READ', Books, async (req) => {
return [{ ID: 1, title: '1984', author: 'George Orwell' }];
});
});
Service Implementation
This feature allows you to implement services that handle CRUD operations. The code sample shows how to implement READ and CREATE operations for a 'Books' entity.
const cds = require('@sap/cds');
module.exports = cds.service.impl(async function() {
this.on('READ', 'Books', async (req) => {
return [{ ID: 1, title: '1984', author: 'George Orwell' }];
});
this.on('CREATE', 'Books', async (req) => {
const { ID, title, author } = req.data;
return { ID, title, author };
});
});
Deploying to SAP HANA
This feature allows you to deploy your CDS models and services to an SAP HANA database. The code sample demonstrates how to deploy a service to SAP HANA using the provided credentials.
const cds = require('@sap/cds');
cds.deploy('srv').to('hana', {
credentials: {
host: 'your-hana-host',
port: 'your-hana-port',
user: 'your-hana-user',
password: 'your-hana-password'
}
}).then(() => {
console.log('Deployment to SAP HANA successful');
}).catch((err) => {
console.error('Deployment failed', err);
});
Other packages similar to @sap/cds
loopback
LoopBack is a highly extensible Node.js framework for building APIs and connecting them with backend data sources. It provides a similar data modeling and service implementation experience as @sap/cds but is more general-purpose and not specifically tailored for SAP environments.
sequelize
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It allows you to define models, perform CRUD operations, and manage database migrations. While it provides robust data modeling capabilities, it lacks the integrated service layer and SAP-specific features of @sap/cds.
typeorm
TypeORM is an ORM for TypeScript and JavaScript (ES7, ES6, ES5). It supports multiple databases and provides a rich set of features for data modeling, migrations, and query building. TypeORM is more focused on database interactions and does not provide the comprehensive service layer found in @sap/cds.