dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

Feature Request: Implement `Disposable` for `PreparedQuery` #257

Open NfNitLoop opened 7 months ago

NfNitLoop commented 7 months ago

Docs for PreparedQuery.finalize() say:

This must be called once the query is no longer needed to avoid leaking resources.

So users need to write something like:

const pq = connection.prepareQuery(query);
try {
    // ...
} finally {
    pq.finalize()
}

But, if it were to implement Disposable, then users would only need to write:

using pq = connection.prepareQuery(query);
// ...

Workaround:

In the meantime, users can explicitly defer a call to finalize like this:

const pq = connection.prepareQuery(query);
using stack = new DisposableStack();
stack.defer(() => pq.finalize());

// ...

Note that until this issue is resolved, you will also need to explicitly:

import { DisposableStack } from "https://deno.land/x/dispose@1.0.1/mod.ts"