db.js 632 B

1234567891011121314151617181920212223242526272829303132
  1. import knex from "knex";
  2. import {configGet, configHas} from "./lib/config.js";
  3. const generateDbConfig = () => {
  4. if (!configHas("database")) {
  5. throw new Error(
  6. "Database config does not exist! Please read the instructions: https://nginxproxymanager.com/setup/",
  7. );
  8. }
  9. const cfg = configGet("database");
  10. if (cfg.engine === "knex-native") {
  11. return cfg.knex;
  12. }
  13. return {
  14. client: cfg.engine,
  15. connection: {
  16. host: cfg.host,
  17. user: cfg.user,
  18. password: cfg.password,
  19. database: cfg.name,
  20. port: cfg.port,
  21. },
  22. migrations: {
  23. tableName: "migrations",
  24. },
  25. };
  26. };
  27. export default knex(generateDbConfig());