Skip to main content
Version: v1

Introduction

The framework takes the approach of schema driven development. It supports multiple kinds of SQL and NoSQL datastores. The developer only needs to specify or generate the schema for a datastore, with authorization policies. The CRUD events and workflows are automatically generated from the schema itself. Shall the developer need to use these within other workflows, they can do that as well.

Currently supported datastores

  • Postgres (via Prisma)
  • Mysql (via Prisma)
  • Mongodb (via Prisma)
  • Elasticsearch (via Elasticgraph, our inhouse implementation providing bunch of exciting features over Elasticsearch, including relationship management and joins.)

The integration supports

  • Model declaration (For both relational and non-relational stores)
  • Schema generation from existing database
  • Universal, autogenerated CRUD API.
  • Validation of the CRUD requests
  • Authorization mechanism at the entity, column, row and ownership levels
  • Automatic caching based on configuration.

8.4.1 Schema specification

The framework extends Prisma specification for specifying the schema of any datastore. This can be generated from an existing database or manually created by the developer. The schema is present as {datastore_name}.prisma file in the src/datasources folder.

datasources

Sample Schema

generator client {
provider = "prisma-client-js"
output = "./generated-clients/mongo"
previewFeatures = ["metrics"]
}

datasource db {
provider = "mongodb"
url = env("MONGO_TEST_URL")
}

model User1 {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
email String @unique
name String?
}

8.4.2 CLI Commands

Any Prisma CLI command can be executed from godspeed CLI using godspeed prisma <command>. For example,

$ godspeed prisma db pull --schema=./src/datasources/mongo_pull.prisma 
_ _
__ _ ___ __| | ___ _ __ ___ ___ __| |
/ _` | / _ \ / _` | / __| | '_ \ / _ \ / _ \ / _` |
| (_| | | (_) | | (_| | \__ \ | |_) | | __/ | __/ | (_| |
\__, | \___/ \__,_| |___/ | .__/ \___| \___| \__,_|
|___/ |_|
Prisma schema loaded from src/datasources/mongo_pull.prisma
Environment variables loaded from .env
Datasource "db"

✔ Introspected 6 models and wrote them into src/datasources/mongo_pull.prisma in 81ms

*** WARNING ***

Could not determine the types for the following fields.
- Model "Post", field: "slug"
- Model "Profile", field: "userId"
- Model "User", field: "email"

Run prisma generate to generate Prisma Client.
note

Please make sure that godspeed prisma <command> is executed inside from devcontainer/project root directory.

8.4.3 Prisma Datastore Setup

The framework has inbuilt feature of setting up datastore automatically whenever a new {datastore_name}.prisma file is created in the src/datasources folder. In case, you are getting any error in the datastore setup, then you can refer to below section for manual setup:

During the project setup, if you have not specified the type of datastore you just added, then you will have to execute godspeed update in project root directory, outside the dev container. This will deploy the container for this datastore in the dev container environment.

Model setup

Prisma model setup is done using prisma generate and db push commands.

Step 1: godspeed prisma generate

$ godspeed prisma generate --schema=./src/datasources/mongo2.prisma 
_ _
__ _ ___ __| | ___ _ __ ___ ___ __| |
/ _` | / _ \ / _` | / __| | '_ \ / _ \ / _ \ / _` |
| (_| | | (_) | | (_| | \__ \ | |_) | | __/ | __/ | (_| |
\__, | \___/ \__,_| |___/ | .__/ \___| \___| \__,_|
|___/ |_|
Environment variables loaded from .env
Prisma schema loaded from src/datasources/mongo2.prisma

✔ Generated Prisma Client (3.15.2 | library) to ./src/datasources/generated-clients/mongo2 in 111ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client

import { PrismaClient } from './src/datasources/generated-clients/mongo2'
const prisma = new PrismaClient()

Step 2: godspeed prisma db push

$ godspeed prisma db push --schema=./src/datasources/mongo.prisma 
_ _
__ _ ___ __| | ___ _ __ ___ ___ __| |
/ _` | / _ \ / _` | / __| | '_ \ / _ \ / _ \ / _` |
| (_| | | (_) | | (_| | \__ \ | |_) | | __/ | __/ | (_| |
\__, | \___/ \__,_| |___/ | .__/ \___| \___| \__,_|
|___/ |_|
Environment variables loaded from .env
Prisma schema loaded from src/datasources/mongo.prisma
Datasource "db"

The database is already in sync with the Prisma schema.

✔ Generated Prisma Client (3.15.2 | library) to ./src/datasources/generated-clients/mongo in 149ms

8.4.4 Auto generating CRUD APIs from data store models

Developer can generate CRUD APIs for all the models in a datastore. Events and Workflows will be auto generated for Create, Read, Update and Delete operations for each model in respective datastore.

Auto-generated events and workflows will be stored in /events/{datasourceName}/{modelName} and /functions/com/gs/{datasourceName}/{modelName} folders respectively.

godspeed gen-crud-api

8.4.5 Sample datastore CRUD task

Please find an example here

8.4.6 Prisma encryption of fields

You can apply encryption on String type fields in Prisma. Be default, the encryption algorithm used is AES-GCM with 256 bit keys.

8.4.6.1 Specification

In your prisma schema, add /// @encrypted to the fields you want to encrypts.
For example, email field in below schema:

generator client {
provider = "prisma-client-js"
output = "./generated-clients/mongo"
previewFeatures = ["metrics"]
}

datasource db {
provider = "mongodb"
url = env("MONGO_TEST_URL")
}

model User1 {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
email String @unique /// @encrypted
name String?
}

8.4.6.2 Configuration

You can specify prisma_secret in environment configuration
For example, this is the sample configuration, set PRISMA_SECRET as env variable:

prisma_secret: PRISMA_SECRET # secret used to generate hash of prisma fields