Closed nakyeonko3 closed 3 months ago
인메모리 데이터 베이스 구현완료
import sqlite3 from 'sqlite3';
class ConnectionMaker {
constructor() {}
makeConnection() {
const db = new sqlite3.Database(`:memory:`, (err) => {
if (err) {
console.error('Error connecting to database:', err);
} else {
console.log('Connected to the in-memory SQlite database.');
}
});
return db;
}
}
export default class InMemoDatabase {
constructor() {
this.db = new ConnectionMaker().makeConnection();
this.createTable();
}
createTable() {
this.db.serialize(() => {
this.db.run(`
CREATE TABLE IF NOT EXISTS Employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT,
phone TEXT,
position TEXT,
profileImg TEXT,
password TEXT
)`);
});
}
insertEmployees(employees) {
(employees || []).forEach((employee) => {
this.insertEmployee(employee);
});
}
insertEmployee({ name, email, phone, position, profileImg }) {
const sql = `INSERT INTO Employees (name, email, phone, position, profileImg) VALUES (?, ?, ?, ?, ?)`;
this.db.run(sql, [name, email, phone, position, profileImg], (err) => {
if (err) {
console.error('Error inserting Employee:', err);
}
});
}
getAllEmployees(callback) {
const sql = 'SELECT * FROM Employees';
this.db.all(sql, [], (err, rows) => {
if (err) {
console.error('Error selecting all Employees:', err);
}
callback(rows);
});
}
}
Tasks
예상 기간
토요일 23시 59분까지 완료 예정
당장 필요한 API 위주로 개발할 예정. 필요한 API 가 있으면 댓글로 적어주세요