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

The problem of closing the connection #71

Closed
ussoft2011 opened this issue Dec 17, 2024 · 4 comments
Closed

The problem of closing the connection #71

ussoft2011 opened this issue Dec 17, 2024 · 4 comments

Comments

@ussoft2011
Copy link

How should I close the connection? I couldn't find the close method. Please help me, thank you.

const instance = await DuckDBInstance.create(backPath, {
threads: '4'
});
const connection = await instance.connect();

@jraymakers
Copy link
Contributor

There isn't a way to explicitly close a connection right now. See #55.

However, if you just drop your reference to the connection, say by setting it to null, it will be automatically closed when it is garbage collected. This usually happens in under a second.

@jraymakers
Copy link
Contributor

Duplicate of #55.

@ussoft2011
Copy link
Author

Thank you for your reply. My code environment is Windows 11, Node.js, and I'm using @duckdb/node-api in an Electron application to create a local DuckDB file, write data, and after performing a SELECT query, I delete the DuckDB file. According to your method, after writing data to DuckDB, I set instance and connection to null. However, the DuckDB file is still occupied when I try to delete it. Please help me, thank you

const instance = await DuckDBInstance.create(backPath, {
threads: '4'
});

const connection = await instance.connect();

} finally {

    if (instance) instance = null;
    if (connection) connection = null;
    if (pgClient) await pgClient.end();

}

@jraymakers
Copy link
Contributor

For this use case, I think it'll work better to DETACH the database before you delete it. According to DuckDB's documentation, closing a connection won't fully disassociate DuckDB from any attached databases.

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

2 participants