-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
accd1c0
commit da0f66c
Showing
5 changed files
with
2,492 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sqlite3 from 'sqlite3'; | ||
import { open } from 'sqlite'; | ||
import { logger } from './logger'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
const dbPath = path.join(__dirname, '../database.sqlite'); | ||
|
||
export const initializeDatabase = async () => { | ||
try { | ||
// Ensure directory exists | ||
const dbDir = path.dirname(dbPath); | ||
logger.info(dbDir); | ||
if (!fs.existsSync(dbDir)) { | ||
fs.mkdirSync(dbDir, { recursive: true }); | ||
} | ||
|
||
// Open the database | ||
const db = await open({ | ||
filename: dbPath, | ||
driver: sqlite3.Database, | ||
}); | ||
|
||
// Enable foreign keys | ||
await db.exec('PRAGMA foreign_keys = ON'); | ||
|
||
logger.info('Database initialized successfully'); | ||
return db; | ||
} catch (error) { | ||
logger.error('Database initialization failed', error); | ||
throw error; | ||
} | ||
}; |
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,11 @@ | ||
import express from 'express'; | ||
const app = express(); | ||
const port = 3000; | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World!'); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`); | ||
}); |
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,22 @@ | ||
// /** | ||
// * Simple logger utility for application logging | ||
// */ | ||
// export const logger = { | ||
// info: (message: string) => { | ||
// console.log(`[INFO] ${new Date().toISOString()}: ${message}`); | ||
// }, | ||
// error: (message: string, error?: any) => { | ||
// console.error(`[ERROR] ${new Date().toISOString()}: ${message}`); | ||
// if (error) { | ||
// console.error(error); | ||
// } | ||
// }, | ||
// warn: (message: string) => { | ||
// console.warn(`[WARN] ${new Date().toISOString()}: ${message}`); | ||
// }, | ||
// debug: (message: string) => { | ||
// if (process.env.NODE_ENV !== 'production') { | ||
// console.debug(`[DEBUG] ${new Date().toISOString()}: ${message}`); | ||
// } | ||
// }, | ||
// }; |
Oops, something went wrong.