Persist message history to SQLite with 1s poller (#15) (#19)
CI / build + unit (push) Successful in 1m4s
CI / build + unit (push) Successful in 1m4s
This commit was merged in pull request #19.
This commit is contained in:
+19
-2
@@ -1,10 +1,27 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { mkdirSync } from 'node:fs';
|
||||
import { dirname } from 'node:path';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { McpController } from './mcp.controller.js';
|
||||
import { MeshController } from './mesh.controller.js';
|
||||
import { MeshService } from './mesh.service.js';
|
||||
import { initMessagesTable, MeshService } from './mesh.service.js';
|
||||
|
||||
// SQLite-backed message history: file path from MESH_DB_PATH (default ./data/mesh-bot.db), parent dir created if missing.
|
||||
function openMessageDb(): DatabaseSync {
|
||||
const path = process.env.MESH_DB_PATH ?? './data/mesh-bot.db';
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
const db = new DatabaseSync(path);
|
||||
initMessagesTable(db);
|
||||
return db;
|
||||
}
|
||||
|
||||
@Module({
|
||||
controllers: [MeshController, McpController],
|
||||
providers: [MeshService],
|
||||
providers: [
|
||||
{
|
||||
provide: MeshService,
|
||||
useFactory: () => new MeshService(openMessageDb()),
|
||||
},
|
||||
],
|
||||
})
|
||||
export class MeshModule {}
|
||||
|
||||
Reference in New Issue
Block a user