feat: added `put` to MySql client

pull/243/head
Josh Moore 1 year ago
parent adac5a1538
commit 2d4db02d22

@ -1,6 +1,7 @@
import mysql, { Pool } from 'mysql2/promise'; import mysql, { Pool } from 'mysql2/promise';
import { UserConfig } from '../UserConfig'; import { UserConfig } from '../UserConfig';
import { log } from '../log'; import { log } from '../log';
import { AssFile, AssUser, NID, UploadToken } from 'ass';
type TableNamesType = 'assfiles' | 'assusers' | 'asstokens'; type TableNamesType = 'assfiles' | 'assusers' | 'asstokens';
@ -94,4 +95,19 @@ export class MySql {
} }
}); });
} }
public static put(table: TableNamesType, key: NID, data: UploadToken | AssFile | AssUser): Promise<void> {
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));
});
}
} }

Loading…
Cancel
Save