Hello! by the increase of complexity of my database, i'm remaking my database code, this is my new typage:
import { ErrorsTS, GuildTS, MessageStructure, UserTS, EventsTS, MessageTS } from '../../../interfaces/Database';
type Tables = 'errors' | 'events' | 'guilds' | 'message_structures' | 'messages' | 'users';
type DBTables<table extends Tables | void> =
table extends 'errors' ? ErrorsTS :
table extends 'events' ? EventsTS :
table extends 'guilds' ? GuildTS :
table extends 'message_structures' ? MessageStructure :
table extends 'messages' ? MessageTS :
table extends 'users' ? UserTS :
Tables
export { DBTables }
So, for this, i'm creating a custom pg class
import { Client, ClientConfig } from 'pg';
import { DBTables } from './types';
import { SQLClient } from './Main';
class CustomClient extends Client {
constructor(config: string | ClientConfig | undefined) {
super(config);
}
async Insert(table: DBTables<void>, values: DBTables<typeof table>) {
return await SQLClient.query(
`INSERT INTO ${table} (${Object.keys(values)}) VALUES (${Object.keys(values).map((x, i) => `$${i + 1}`)})`,
Object.values(values)
)
}
}
export default CustomClient;
But the parameter values of CustomClient.Insert function have the any value 😦 how can i solve this?