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

POC: Simpler database auto-closure using using keyword #6791

Closed
wants to merge 2 commits into from

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Nov 1, 2023

@fregante fregante changed the title Simpler database auto-closure using using keyword POC: Simpler database auto-closure using using keyword Nov 1, 2023
@fregante
Copy link
Contributor Author

fregante commented Nov 1, 2023

ESLint won't support this until it's in Stage 4, which may happen much later unless we swap the parser.

Closing for now

@fregante fregante closed this Nov 1, 2023
@fregante fregante deleted the F/dev/using-typescript-key branch November 1, 2023 08:22
}

/**
* Add a log entry to the database.
* @param entry the log entry to add
*/
export async function appendEntry(entry: LogEntry): Promise<void> {
const db = await getDB();
const {db} = await using getDB();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "using" goes where the const is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It turns out that immediate destructuring isn't possible either so it would look like this:

using resource = await getDB();
resource.db.getAll();

I pushed a new partial commit here just for reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened in issue in the Typescript IDB repository: jakearchibald/idb#300

@grahamlangford grahamlangford added this to the 1.8.2 milestone Nov 1, 2023
@fregante fregante restored the F/dev/using-typescript-key branch November 2, 2023 10:51
@fregante fregante reopened this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants