import { Injectable } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { Surreal } from "surrealdb.node"; @Injectable() export class SurrealDBService { constructor(private configService: ConfigService) {} db: Surreal; async onModuleInit() { this.db = new Surreal(); try { // Connect to the database await this.db.connect( `rocksdb://${this.configService.get("surrealDB.path")}` ); // Select a specific namespace / database await this.db.use({ ns: this.configService.get("surrealDB.namespace") || "default", db: this.configService.get("surrealDB.name") || "default", }); } catch (e) { console.error("ERROR", e); } } }