Giter VIP home page Giter VIP logo

cds-pg's Introduction

npm version Package Build

cds-pg - PostgreSQL adapter for SAP CDS (CAP)

First a big thank you to our contributors:

Contributors Display

This node module provides an adapter to the PostgreSQL database.

For a short introduction on the background of this project you can check out a short video that has been captured as part of the SAP devtoberfest.

Current status

cds-pg is ready to be used! Still, there's some gaps left to fill - note the list below and please see CONTRIBUTING.md for how to contribute additional capabilities!

Also checkout the following blog posts on how to get started using cds-pg in your local development environment and on SAP Business Technology Platform (BTP), Cloud Foundry:

TODO

  • implement basic SELECT|READ(~ OData GET)
  • implement basic INSERT|CREATE(~ OData POST)
  • implement basic UPDATE(~ OData PUT|PATCH)
  • implement basic DELETE(~ OData DELETE)
  • map OData to PostgreSQL vocabulary
  • implement basic cds deployment
  • use default query builders for UPDATE/DELETE
  • add support for multitenancy (see issue #25)
    • support multiple schemas (at config time)
    • support queries with tenant info (at runtime)
  • add support for full OData vocabulary
    • system query options ($filter, $expand, $select)
    • string functions
    • collection functions
    • date + time functions
    • geo functions
    • arithmetic operators + functions
  • add draft support (see issue #30)
  • add advanced deployment model that supports delta handling/migrations (see issue #27)
  • support virtual fields (see issue 204)
  • support localized entities (see issue 196)

Usage in your CAP project

Add this package to your SAP Cloud Application Programming Model project by running:

npm install cds-pg

Then add this configuration to the cds section of your `package.json:

  "cds": {
    "requires": {
      "db": {
        "kind": "postgres"
      },
      "postgres": {
        "dialect": "plain", // <- for cds >= 5.1
        "impl": "cds-pg",
        "model": [
          "srv"
        ]
      }
    }
  }

For local development you can provide the credentials in the file default-env.json in the root folder of your project:

{
  "VCAP_SERVICES": {
    "postgres": [
      {
        "name": "postgres",
        "label": "postgres",
        "tags": ["plain", "database"],
        "credentials": {
          "host": "localhost",
          "port": "5432",
          "database": "dbname",
          "user": "postgres",
          "password": "postgres",
          "schema":"public"
        }
      }
    ]
  }
}

CDS deployment

cds-pg contains the database adapter to translate the incoming requests to PostgreSQL during runtime, but also includes a quick and dirty command to deploy the current data model to the PostgreSQL database specified in default-env.json. Initial data will also be filled from the provided .csv files following the approach described in Providing Initial Data. Be aware that the existing tables and views are deleted and then re-created according the CDS model, so this should not be used in production environments:

npx cds-pg deploy srv --to db

For a more sophisticated approach, please check out cds-dbm at https://github.com/mikezaschka/cds-dbm, which offers an advanced deployment model including delta handling of data and models! Please also read the following blogposts for a detailed description, on how cds-dbm can be used in combintation with cds-pg:

Projects using cds-pg

  • pg-beershop – An example project with multiple deployment scenarios (Cloud Foundry, Kyma, Azure, Google Cloud Platform)
  • cap-devtoberfest – A simple project showcasing how to run cds-pg and cds-dbm locally and on SAP BTB Cloud Foundry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.