import { Provider } from '@nestjs/common';
import { Kysely, KyselyConfig } from 'kysely';
import { KYSELY_CLIENT_PROVIDER_TOKEN } from './database.module';

export const createKyselyClient = <DB>(options: KyselyConfig): Kysely<DB> => {
  return new Kysely<DB>(options);
};

export const createKyselyProvider = (options: KyselyConfig): Provider => ({
  provide: KYSELY_CLIENT_PROVIDER_TOKEN,
  useValue: createKyselyClient(options),
});
