Reference

NestJS Database Access

To connect your NestJS app to the fully-managed database that Adaptable deploys, you'll need to use the DATABASE_URL environment variable that Adaptable provides to your app. All Adaptable databases require TLS/SSL, so your database configuration must correctly set up TLS/SSL. By using DATABASE_URL, TLS/SSL will be set up correctly for you.

Adaptable is compatible with all NestJS database integrations, such as TypeORM, Prisma, Sequelize, Knex, Mongoose, and MikroORM.

»TypeORM

Below is an example src/app.module.ts which uses the DATABASE_URL environment variable to connect with TypeORM.

important

When using the url configuration property as recommended below, you must not also set any of the host, port, username, password, database, or ssl properties as those will override url.

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
url: process.env.DATABASE_URL,
entities: [],
}),
],
})
export class AppModule {}

»Mongoose

Below is an example src/app.module.ts which uses the DATABASE_URL environment variable to connect with Mongoose.

import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
const databaseUrl =
process.env.DATABASE_URL || 'mongodb://localhost:27017/test';
@Module({
imports: [MongooseModule.forRoot(databaseUrl)],
})
export class AppModule {}

»Prisma

Below is an example schema.prisma for connecting with Prisma:

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

For more information on the database environment variables, see runtime environment variables.

Once you've made code changes, push them to your selected branch in GitHub and Adaptable will re-deploy your app automatically.