Knex

PHOTO EMBED

Wed Aug 25 2021 02:35:21 GMT+0000 (UTC)

Saved by @huilt1232 #add.env

yarn add knex @types/knex pg @types/pg

yarn knex init -x ts

yarn knex --env production <any-command>     (in production environment)

--create .env

npm install dotenv @types/dotenv

.env file 
DB_NAME=test
DB_USERNAME=postgres
DB_PASSWORD=postgres



knexfile.ts
import dotenv from 'dotenv';
dotenv.config();

module.exports = {

  // development environment
  development: {
    debug: true,
    client: "postgresql",
    connection: {
      database: process.env.DB_NAME,
      user: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: "knex_migrations"
    }
  },

  // staging environment
  staging: {
    client: "postgresql",
    connection: {
      database: process.env.DB_NAME,
      user: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: "knex_migrations"
    }
  },

  // production environment
  production: {
    client: "postgresql",
    connection: {
      database: process.env.DB_NAME,
      user: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: "knex_migrations"
    }
  }

};
content_copyCOPY

https://cms.tecky.io/mod/page/view.php?id