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

Consider changing the middleware api #457

Open
demetris-manikas opened this issue May 22, 2024 · 0 comments
Open

Consider changing the middleware api #457

demetris-manikas opened this issue May 22, 2024 · 0 comments

Comments

@demetris-manikas
Copy link
Contributor

demetris-manikas commented May 22, 2024

This is a suggestion for v2
The following type definition in httpServer/middleware.ts looks a bit odd (somewhat golang like).

query<C extends UserDatabaseClient, R, T extends unknown[]>(qry: (dbclient: C, ...args: T) => Promise<R>, ...args: T): Promise<R>;

The following definition is a lot cleaner.

  query<C extends UserDatabaseClient, R>(qry: (dbclient: C) => Promise<R>): 

This is how I would write my code (I can do it already)
No need for any extra args defined but just the dbclient,

let username = getItFromSomewhere();
const u = await ctx.query(
    (dbClient: Knex) => {
      return dbClient<UserTable>(userTableName).select("username").where({ username: username })
    }
);

Instead of

let user = getItFromSomewhere();
const u = await ctx.query(
    (dbClient: Knex, user: string) => {
      return dbClient<UserTable>(userTableName).select("username").where({ username: user })
    },
    user
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants