async function main(params) {
const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'info' })
let db;
logger.info("Sqllite testing")
try {
if (fs.existsSync(filepath)) {
db = new sqlite3.Database(filepath);
logger.info("Connected to existing SQLite database.")
} else {
db = new sqlite3.Database(filepath, (error) => {
if (error) {
return {
error: {
status:400,
body: {
message:error
}
}
}
}
logger.info("Connection with SQLite has been established");
createTable(db);
});
}
// Call insertRow with the db and data
// insertRow(db,params.data,logger);
} catch (error) {
return {
error: {
status:400,
body: {
error
}
}
}
} finally {
if (db) {
db.close(); // Close the database connection
}
}
}
function createTable(db) {
db.exec(`
CREATE TABLE IF NOT EXISTS sharks
(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
phoneno VARCHAR(50) NOT NULL
);
`);
return{
status:200,
body:{
message:"created successfully",
success:"true"
}
}
}
// function insertRow(db, data,logger) {
// const { name, email, password, phoneno } = data;
// db.run(
// `INSERT INTO sharks (name, email, password, phoneno) VALUES (?, ?, ?, ?)`,
// [name, email, password, phoneno],
// function (error) {
// if (error) {
// return {
// error: {
// status:400,
// body: {
// error
// }
// }
// }
// } else {
// logger.info(`Inserted a row with the ID: ${this.lastID}`)
// return{
// status:200,
// body:{
// message:"inserted a row",
// success:"true"
// }
// }
// }
// }
// );
// }
// main({
// "data": {
// "name": "xyz",
// "email": "xyz@gmail.com",
// "password": "xyz1234",
// "phoneno": "xxxxxxxxxxxx"
// }
// });
exports.main = main;