diff --git a/backend/sql/database.ts b/backend/sql/database.ts index f09edbb..39b8593 100644 --- a/backend/sql/database.ts +++ b/backend/sql/database.ts @@ -1,43 +1,4 @@ -import { AssFile, AssUser, NID, UploadToken } from "ass"; - -export type DatabaseValue = AssFile | AssUser | UploadToken; -export type DatabaseTable = 'assfiles' | 'assusers' | 'asstokens'; - -// todo: move this to types.d.ts -/** - * interface for database classes - */ -export interface Database { - /** - * preform database initialization tasks - */ - open(): Promise; - - /** - * preform database suspension tasks - */ - close(): Promise; - - /** - * set up database - */ - configure(): Promise; - - /** - * put a value in the database - */ - put(table: DatabaseTable, key: NID, data: DatabaseValue): Promise; - - /** - * get a value from the database - */ - get(table: DatabaseTable, key: NID): Promise; - - /** - * get all values from the database - */ - getAll(table: DatabaseTable): Promise<{ [key: string]: DatabaseValue | undefined }[]>; -} +import { NID, Database, DatabaseTable, DatabaseValue } from "ass"; export class DBManager { private static _db: Database; diff --git a/backend/sql/json.ts b/backend/sql/json.ts index 4086a75..789772f 100644 --- a/backend/sql/json.ts +++ b/backend/sql/json.ts @@ -1,9 +1,8 @@ -import { AssFile, AssUser, FilesSchema, UsersSchema } from 'ass'; +import { AssFile, AssUser, FilesSchema, UsersSchema, Database, DatabaseTable, DatabaseValue } from 'ass'; import path, { resolve } from 'path'; import fs from 'fs-extra'; -import { Database, DatabaseTable, DatabaseValue } from './database.js'; import { log } from '../log.js'; import { nanoid } from '../generators.js'; diff --git a/backend/sql/mysql.ts b/backend/sql/mysql.ts index 7072b86..4a9dd81 100644 --- a/backend/sql/mysql.ts +++ b/backend/sql/mysql.ts @@ -1,10 +1,9 @@ -import { AssFile, AssUser, NID, UploadToken } from 'ass'; +import { AssFile, AssUser, NID, UploadToken, Database, DatabaseTable, DatabaseValue } from 'ass'; import mysql, { Pool } from 'mysql2/promise'; import { log } from '../log.js'; import { UserConfig } from '../UserConfig.js'; -import { Database, DatabaseTable, DatabaseValue } from './database.js'; export class MySQLDatabase implements Database { private _pool: Pool; diff --git a/backend/sql/postgres.ts b/backend/sql/postgres.ts index 6b4280c..033f7d0 100644 --- a/backend/sql/postgres.ts +++ b/backend/sql/postgres.ts @@ -1,8 +1,7 @@ -import { PostgresConfiguration } from 'ass'; +import { PostgresConfiguration, Database, DatabaseTable, DatabaseValue } from 'ass'; import pg from 'pg'; import { log } from '../log.js'; -import { Database, DatabaseTable, DatabaseValue } from './database.js'; import { UserConfig } from '../UserConfig.js'; /** diff --git a/common/types.d.ts b/common/types.d.ts index 2d13284..fe32941 100644 --- a/common/types.d.ts +++ b/common/types.d.ts @@ -3,6 +3,9 @@ declare module 'ass' { type IdType = 'random' | 'original' | 'gfycat' | 'timestamp' | 'zws' + export type DatabaseValue = AssFile | AssUser | UploadToken; + export type DatabaseTable = 'assfiles' | 'assusers' | 'asstokens'; + /** * Core Express server config. * This is separate from the user configuration starting in 0.15.0 @@ -51,6 +54,42 @@ declare module 'ass' { } } + /** + * interface for database classes + */ + + export interface Database { + /** + * preform database initialization tasks + */ + open(): Promise; + + /** + * preform database suspension tasks + */ + close(): Promise; + + /** + * set up database + */ + configure(): Promise; + + /** + * put a value in the database + */ + put(table: DatabaseTable, key: NID, data: DatabaseValue): Promise; + + /** + * get a value from the database + */ + get(table: DatabaseTable, key: NID): Promise; + + /** + * get all values from the database + */ + getAll(table: DatabaseTable): Promise<{ [key: string]: DatabaseValue | undefined; }[]>; + } + interface DatabaseConfiguration { kind: 'mysql' | 'postgres' | 'json'; options?: MySQLConfiguration | PostgresConfiguration;