From 2d4db02d2238eef9a55e1290ebdfcf8e971acb5a Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sun, 16 Jul 2023 21:24:44 -0600 Subject: [PATCH] feat: added `put` to MySql client --- backend/sql/mysql.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/sql/mysql.ts b/backend/sql/mysql.ts index 4dc1d84..71a6e9f 100644 --- a/backend/sql/mysql.ts +++ b/backend/sql/mysql.ts @@ -1,6 +1,7 @@ import mysql, { Pool } from 'mysql2/promise'; import { UserConfig } from '../UserConfig'; import { log } from '../log'; +import { AssFile, AssUser, NID, UploadToken } from 'ass'; type TableNamesType = 'assfiles' | 'assusers' | 'asstokens'; @@ -94,4 +95,19 @@ export class MySql { } }); } + + public static put(table: TableNamesType, key: NID, data: UploadToken | AssFile | AssUser): Promise { + return new Promise(async (resolve, reject) => { + if (!MySql._ready) return reject(new Error('MySQL not ready')); + + const query = ` +INSERT INTO ${table} ( NanoID, Data ) +VALUES ('${key}', '${JSON.stringify(data)}'); +`; + + return MySql._pool.query(query) + .then(() => resolve(void 0)) + .catch((err) => reject(err)); + }); + } }