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

Allow returning a promise instead of calling done from afterCreate #6152

Open
KristjanTammekivi opened this issue Nov 8, 2024 · 0 comments

Comments

@KristjanTammekivi
Copy link
Contributor

KristjanTammekivi commented Nov 8, 2024

Environment

Knex version: 3.1.0
Database + version: Postgres 13
OS: Linux

Feature discussion / request

Explain what is your use case

I want to use async functions as afterCreate. Used to be possible, but had to call done, now there is a deprecation warning each time a connection is created ((node:44774) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake)

Explain what kind of feature would support this

Allow the callback to be an async function

Give some API proposal, how the feature should work

Check if the afterCreate function takes 1 argument or 2, if 1 then skip promisify, if 2 then promisify. Something like

const fn = (afterCreate.length === 1 ? afterCreate : promisify(afterCreate));
await fn(connection);

Also maybe should do a typing change for afterCreate, currently it's only Function, we could have it as

type AfterCreate = ((client: any) => Promise<any>) | ((client: any, done: (err?: Error | null) => void) => void)

I'll create a pull request

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

No branches or pull requests

1 participant
  NODES
COMMUNITY 2
Project 5
USERS 1