You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.3 KiB
69 lines
1.3 KiB
const { database } = require('../database')
|
|
|
|
async function createMention(nom, uniter) {
|
|
const query = database.prepare('INSERT INTO mentions (nom, uniter) VALUES (?, ?)')
|
|
|
|
try {
|
|
let response = await query.run(nom, uniter)
|
|
|
|
return response
|
|
} catch (error) {
|
|
return error
|
|
}
|
|
}
|
|
|
|
async function deleteMention(id) {
|
|
const query = database.prepare('DELETE FROM mentions WHERE id = ?')
|
|
|
|
try {
|
|
let response = await query.run(id)
|
|
|
|
return response
|
|
} catch (error) {
|
|
return error
|
|
}
|
|
}
|
|
|
|
async function getMentions() {
|
|
const query = database.prepare('SELECT * FROM mentions')
|
|
|
|
try {
|
|
let response = await query.all()
|
|
|
|
return response
|
|
} catch (error) {
|
|
return error
|
|
}
|
|
}
|
|
|
|
async function getSingleMention(id) {
|
|
const query = database.prepare('SELECT * FROM mentions WHERE id = ?')
|
|
|
|
try {
|
|
let response = query.get(id)
|
|
|
|
return response
|
|
} catch (error) {
|
|
return error
|
|
}
|
|
}
|
|
|
|
async function updateMention(nom, uniter, id) {
|
|
const query = database.prepare('UPDATE mentions SET nom = ?, uniter = ? WHERE id = ?')
|
|
|
|
try {
|
|
let response = query.run(nom, uniter, id)
|
|
|
|
return response
|
|
} catch (error) {
|
|
return error
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
createMention,
|
|
deleteMention,
|
|
getMentions,
|
|
getSingleMention,
|
|
updateMention
|
|
}
|
|
|