Integrate hugo static generator
This commit is contained in:
56
backend/models/userModel.ts
Normal file
56
backend/models/userModel.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import pool from 'backend/miscellaneous/db'
|
||||
|
||||
class UserD {
|
||||
name?: string;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export enum values {
|
||||
pass = 1,
|
||||
omdb_key,
|
||||
twitch_client_id,
|
||||
twitch_client_secret,
|
||||
}
|
||||
|
||||
const namesOfValues: string[] = ["", "pass", "omdb_key", "twitch_client_id", "twitch_client_secret"];
|
||||
|
||||
function getValue(name: values): string | undefined {
|
||||
try {
|
||||
const rows = pool.query("SELECT name, value FROM userData where id = ?;").as(UserD).all(name);
|
||||
if (rows.length > 0)
|
||||
return rows[0].value;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function updateValue(name: string, value: string): number {
|
||||
try {
|
||||
const result = pool.query("UPDATE userData SET value = ? WHERE name = ?").run(value, name);
|
||||
return result.changes;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getAll(): UserD[] {
|
||||
try {
|
||||
const rows = pool.query("SELECT name, value FROM userData;").as(UserD).all();
|
||||
return rows;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export default {
|
||||
getValue,
|
||||
updateValue,
|
||||
getAll,
|
||||
namesOfValues
|
||||
};
|
Reference in New Issue
Block a user