This commit is contained in:
parent
ad8cd5d03c
commit
e98758efe2
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"cSpell.words": ["nestjs", "nodenext", "nuxt", "tailwindcss"]
|
"cSpell.words": ["nestjs", "nodenext", "nuxt", "postgres", "tailwindcss"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.0.1",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
|
"drizzle-orm": "^0.45.1",
|
||||||
|
"postgres": "^3.4.8",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
import { DatabaseModule } from './database/database.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [DatabaseModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
9
apps/api/src/database/database.module.ts
Normal file
9
apps/api/src/database/database.module.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { Global, Module } from '@nestjs/common';
|
||||||
|
import { DatabaseProvider, DRIZZLE_CLIENT } from './database.provider';
|
||||||
|
|
||||||
|
@Global()
|
||||||
|
@Module({
|
||||||
|
providers: [DatabaseProvider],
|
||||||
|
exports: [DRIZZLE_CLIENT],
|
||||||
|
})
|
||||||
|
export class DatabaseModule {}
|
||||||
20
apps/api/src/database/database.provider.ts
Normal file
20
apps/api/src/database/database.provider.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { drizzle, PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
||||||
|
import postgres from 'postgres';
|
||||||
|
import * as schema from '@proj/db';
|
||||||
|
import { Provider } from '@nestjs/common';
|
||||||
|
|
||||||
|
export const DRIZZLE_CLIENT = 'DRIZZLE_CLIENT';
|
||||||
|
|
||||||
|
export type DrizzleDB = PostgresJsDatabase<typeof schema>;
|
||||||
|
|
||||||
|
export const DatabaseProvider: Provider = {
|
||||||
|
provide: DRIZZLE_CLIENT,
|
||||||
|
useFactory: (): DrizzleDB => {
|
||||||
|
const connectionString =
|
||||||
|
process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/db';
|
||||||
|
const client = postgres(connectionString);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
|
||||||
|
return drizzle(client, { schema }) as DrizzleDB;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"target": "ES2023",
|
"target": "ES2023",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
"rootDir": "../..",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|
@ -19,6 +20,10 @@
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"strictBindCallApply": false,
|
"strictBindCallApply": false,
|
||||||
"noFallthroughCasesInSwitch": false
|
"noFallthroughCasesInSwitch": false,
|
||||||
|
"paths": {
|
||||||
|
"@proj/db": ["../../packages/db/index.ts"],
|
||||||
|
"@proj/db/*": ["../../packages/db/*"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,12 @@ importers:
|
||||||
'@nestjs/platform-express':
|
'@nestjs/platform-express':
|
||||||
specifier: ^11.0.1
|
specifier: ^11.0.1
|
||||||
version: 11.1.14(@nestjs/common@11.1.14)(@nestjs/core@11.1.14)
|
version: 11.1.14(@nestjs/common@11.1.14)(@nestjs/core@11.1.14)
|
||||||
|
drizzle-orm:
|
||||||
|
specifier: ^0.45.1
|
||||||
|
version: 0.45.1(postgres@3.4.8)
|
||||||
|
postgres:
|
||||||
|
specifier: ^3.4.8
|
||||||
|
version: 3.4.8
|
||||||
reflect-metadata:
|
reflect-metadata:
|
||||||
specifier: ^0.2.2
|
specifier: ^0.2.2
|
||||||
version: 0.2.2
|
version: 0.2.2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue