-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
518 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Field, ObjectType } from "@nestjs/graphql"; | ||
|
||
@ObjectType() | ||
export class DatabaseConnection { | ||
@Field() | ||
connectionUrl: string; | ||
|
||
@Field() | ||
name: string; | ||
|
||
@Field({ nullable: true }) | ||
hideDoltFeatures?: boolean; | ||
|
||
@Field({ nullable: true }) | ||
useSSL?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { FileStoreService } from "./fileStore.service"; | ||
|
||
@Module({ providers: [FileStoreService], exports: [FileStoreService] }) | ||
export class FileStoreModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import * as fs from "fs"; | ||
import { resolve } from "path"; | ||
import { DatabaseConnection } from "../databases/database.model"; | ||
|
||
@Injectable() | ||
export class FileStoreService { | ||
constructor() {} | ||
|
||
getStore(): Array<DatabaseConnection> { | ||
try { | ||
const file = fs.readFileSync( | ||
resolve(__dirname, "../../store/store.json"), | ||
{ | ||
encoding: "utf8", | ||
}, | ||
); | ||
if (!file) { | ||
return []; | ||
} | ||
const parsed = JSON.parse(file); | ||
return parsed; | ||
} catch (err) { | ||
console.error("Error reading store.json:", err); | ||
return []; | ||
} | ||
} | ||
|
||
addItemToStore(item: DatabaseConnection): void { | ||
const store = this.getStore(); | ||
|
||
const existingItem = store.find(storeItem => storeItem.name === item.name); | ||
if (existingItem) { | ||
if (existingItem.connectionUrl === item.connectionUrl) return; | ||
throw new Error("name already exists"); | ||
} | ||
|
||
store.push(item); | ||
|
||
if (!fs.existsSync(resolve(__dirname, "../../store"))) { | ||
fs.mkdirSync(resolve(__dirname, "../../store")); | ||
} | ||
|
||
fs.writeFileSync( | ||
resolve(__dirname, "../../store/store.json"), | ||
JSON.stringify(store), | ||
{ | ||
encoding: "utf8", | ||
}, | ||
); | ||
} | ||
|
||
removeItemFromStore(name: string): void { | ||
const store = this.getStore(); | ||
const newStore = store.filter(item => item.name !== name); | ||
fs.writeFileSync( | ||
resolve(__dirname, "../../store/store.json"), | ||
JSON.stringify(newStore), | ||
{ | ||
encoding: "utf8", | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.