Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify UserDatabase/UserDatabaseQuery/UserDatabaseTransaction declarations #459

Open
devhawk opened this issue May 22, 2024 · 1 comment

Comments

@devhawk
Copy link
Collaborator

devhawk commented May 22, 2024

During review of #448, we considered simplifying several interfaces/types related to UserDatabase.

export interface UserDatabase {
  transaction<R, T extends unknown[]>(transactionFunction: UserDatabaseTransaction<R, T>, config: TransactionConfig, ...args: T): Promise<R>;
  queryFunction<C extends UserDatabaseClient, R, T extends unknown[]>(queryFunction: UserDatabaseQuery<C, R, T>, ...params: T): Promise<R>;
  query<R, T extends unknown[]>(sql: string, ...params: T): Promise<R[]>;
  queryWithClient<R, T extends unknown[] = unknown[]>(client: UserDatabaseClient, sql: string, ...params: T): Promise<R[]>;
  // other members omitted for clarity
}

type UserDatabaseQuery<C extends UserDatabaseClient, R, T extends unknown[]> = (ctxt: C, ...args: T) => Promise<R>;
type UserDatabaseTransaction<R, T extends unknown[]> = (ctxt: UserDatabaseClient, ...args: T) => Promise<R>;

Having a type argument T extending unknown[] doesn't provide much value. I think this type argument could be removed, simplifying the definitions. The new definitions would look something like this:

export interface UserDatabase {
  transaction<R>(transactionFunction: UserDatabaseTransaction<R, T>, config: TransactionConfig, ...args: unknown[]): Promise<R>;
  queryFunction<C extends UserDatabaseClient, R>(queryFunction: UserDatabaseQuery<C, R, T>, ...params: unknown[]): Promise<R>;
  query<R>(sql: string, ...params: unknown[]): Promise<R[]>;
  queryWithClient<R>(client: UserDatabaseClient, sql: string, ...params: unknown[]): Promise<R[]>;
  // other members omitted for clarity
}

type UserDatabaseQuery<C extends UserDatabaseClient, R> = (ctxt: C, ...args: unknown[]) => Promise<R>;
type UserDatabaseTransaction<R> = (ctxt: UserDatabaseClient, ...args: unknown[]) => Promise<R>;
@demetris-manikas
Copy link
Contributor

This should probably be closed or assigned a label for v2 as it will change the signature of the related functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants