2023-09-27 07:03:36 -05:00
|
|
|
const db = require('better-sqlite3')('brainz-social.db');
|
|
|
|
db.pragma('journal_mode = WAL');
|
|
|
|
|
|
|
|
export default {
|
|
|
|
db,
|
|
|
|
|
|
|
|
getConfig: (key) => {
|
|
|
|
const row = db.prepare('SELECT * FROM config WHERE key = ?').get(key);
|
|
|
|
return row.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
setConfig: (key, value) => {
|
|
|
|
db.prepare("INSERT OR REPLACE INTO config (key, value) VALUES(?, ?);").run(key, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
createApplication: (client_name, redirect_uri, scopes, website, client_id, client_secret) => {
|
|
|
|
db.prepare("INSERT INTO applications (client_name, redirect_uri, scopes, website, client_id, client_secret) VALUES (?, ?, ?, ?, ?, ?);").run(client_name, redirect_uri, scopes, website, client_id, client_secret);
|
2023-09-27 08:30:39 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getApplication: (client_id) => {
|
|
|
|
return db.prepare("SELECT id, client_id, client_secret, redirect_uri, scopes, website FROM applications WHERE client_id = ?").get(client_id);
|
|
|
|
},
|
|
|
|
|
|
|
|
createToken: (token, scope, application_id, user_id, created_at) => {
|
|
|
|
db.prepare("INSERT INTO oauth_tokens (token, scope, application_id, user_id, created_at, revoked) VALUES (?, ?, ?, ?, ?, false)").run(token, scope, application_id, user_id, created_at);
|
2023-09-27 07:03:36 -05:00
|
|
|
}
|
|
|
|
};
|