mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
feat(knex): create database interfaces and knexjs nest integration
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
902abf72e6
commit
a9183e82bf
93 changed files with 760 additions and 2927 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import z from 'zod';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
import { DatabaseType } from './database-type.enum';
|
||||
import { parseOptionalNumber } from './utils';
|
||||
|
@ -90,3 +91,39 @@ export default registerAs('databaseConfig', () => {
|
|||
}
|
||||
return databaseConfig.data;
|
||||
});
|
||||
|
||||
export function getKnexConfig(databaseConfig: DatabaseConfig): Knex.Config {
|
||||
switch (databaseConfig.type) {
|
||||
case DatabaseType.SQLITE:
|
||||
return {
|
||||
client: 'better-sqlite3',
|
||||
connection: {
|
||||
filename: databaseConfig.database,
|
||||
},
|
||||
};
|
||||
case DatabaseType.POSTGRES:
|
||||
return {
|
||||
client: 'pg',
|
||||
connection: {
|
||||
host: databaseConfig.host,
|
||||
port: databaseConfig.port,
|
||||
user: databaseConfig.username,
|
||||
database: databaseConfig.database,
|
||||
password: databaseConfig.password,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
application_name: 'HedgeDoc',
|
||||
},
|
||||
};
|
||||
case DatabaseType.MARIADB:
|
||||
return {
|
||||
client: 'mysql',
|
||||
connection: {
|
||||
host: databaseConfig.host,
|
||||
port: databaseConfig.port,
|
||||
user: databaseConfig.username,
|
||||
database: databaseConfig.database,
|
||||
password: databaseConfig.password,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue