Skip to content

Commit

Permalink
Revert back to read only
Browse files Browse the repository at this point in the history
  • Loading branch information
karamba228 committed Oct 3, 2024
1 parent 17c7430 commit 38e88da
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ import path from "path";
const dbPath = path.join(process.cwd(), "public/scores.duckdb");
console.log("Creating new DB", { dbPath });

let db: duckdb.Database | null = null;
if (!db) {
db = new duckdb.Database(
dbPath,
{
access_mode: "READ_WRITE", // Open in READ_WRITE mode
max_memory: "512MB",
threads: "1",
},
(err) => {
if (err) {
console.log(`Error opening database in READ_WRITE mode: ${err}`);
} else {
console.log("Database opened in READ_WRITE mode successfully.");
}
},
);
} else {
console.log("Database is already connected in READ_WRITE mode.");
}
const db = new duckdb.Database(
dbPath,
{
access_mode: "READ_ONLY",
max_memory: "512MB",
threads: "4",
},
(err) => {
if (err) {
console.log(`Error creating in-memory database: ${err}`);
return;
}
},
);

// export async function getDB(): Promise<duckdb.Database> {
// const PROJECT_ROOT = getConfig().serverRuntimeConfig.PROJECT_ROOT;
Expand Down Expand Up @@ -61,7 +55,7 @@ export async function fetchAll<T>(
): Promise<T[]> {
return new Promise((res, rej) => {
console.log(`Executing duckdb query`);
db!.all(sql, ...args, (err, data) => {
db.all(sql, ...args, (err, data) => {
if (err) {
rej(err);
return;
Expand Down

0 comments on commit 38e88da

Please sign in to comment.