const { Database, Table, YAMLDriver } = require('st.db')
const { BaseDatabase } = require('../lib/main')
* @template {Record<'name' | 'value' | 'table', string>} Args
* @extends {BaseDatabase<T, Args>}
class CustomDatabase extends BaseDatabase {
driver: new YAMLDriver(__dirname + '/database.yaml')
* @type {Map<string, Table>}
* Creates a new instance of the `CustomDatabase` class.
* @param {string[] | undefined} tables - The tables to be initialized.
constructor(tables = ['main']) {
if (!tables.includes('main')) tables.unshift('main');
tables.forEach((table) => this.tables.set(table, new Table(table, this.driver)))
* @template {void} Return - The value to return.
* @param {Args} args - Delete value args.
* @returns {Promise<Return>}
async deleteValue({ name }) {
const fetchedTable = this.tables.get(table ?? 'main')
await fetchedTable.delete(name)
* @template {ReturnType<Database['get']>} Return - The value to return.
* @param {Args} args - Get value args.
* @returns {Promise<Return>}
async getValue({ name, table }) {
const fetchedTable = this.tables.get(table ?? 'main')
return await fetchedTable.get(name)
* @template {boolean} Return - The value to return.
* @param {Args} args - Delete value args.
* @returns {Promise<Return>}
async hasValue({ name, table }) {
const fetchedTable = this.tables.get(table ?? 'main')
return await fetchedTable.has(name)
* @template {void} Return - The value to return.
* @param {Args} args - Set value args.
* @returns {Promise<Return>}
async setValue({ name, value, table }) {
const fetchedTable = this.tables.get(table ?? 'main')
await fetchedTable.set(name, value)
* In this case, do nothing as this lib does not require connection or something.
module.exports = CustomDatabase