Skip to content

Commit

Permalink
no need to finalize queries anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheraff committed Apr 6, 2024
1 parent 8445cdc commit 553b076
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 0 additions & 2 deletions client/src/components/drizzle/Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ function TestChild() {
const data = await prep.all()
console.log("data", data)
await new Promise((resolve) => setTimeout(resolve, 1000))
await prep.finalize()
console.log("finalized")
})()
}, [data])
return <div>Test</div>
Expand Down
10 changes: 4 additions & 6 deletions client/src/db/useDbQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type QueryEntry = {
}

const queryStore = new Map<
/** dbName, sql */
/** dbName, sql, bindings */
string,
QueryEntry
>()
Expand Down Expand Up @@ -91,6 +91,7 @@ function cleanupQuery({
q: QueryEntry
cacheManager: QueryCache
queryKey: readonly [dbName: number, sql: string, bindings: Binding[]]
/** dbName, sql, bindings */
hash: string
dbName: number
}) {
Expand All @@ -109,7 +110,6 @@ function cleanupQuery({

console.log("cleanup query, finalizing statement", hash)
queryStore.delete(hash)
q.statement?.finalize().catch(console.error)
q.statement = null

// stop listening to table changes
Expand Down Expand Up @@ -158,6 +158,7 @@ export function start(dbName: number, ctx: Ctx, client: QueryClient) {
sql: string,
bindings: Binding[],
]
/** dbName, sql, bindings */
const hash = hashKey(queryKey)

/**
Expand Down Expand Up @@ -325,7 +326,6 @@ export function start(dbName: number, ctx: Ctx, client: QueryClient) {
}
for (const [key, q] of queryStore.entries()) {
if (q.dbName === dbName) {
q.statement?.finalize().catch(console.error)
queryStore.delete(key)
}
}
Expand Down Expand Up @@ -382,8 +382,6 @@ export function useDbQuery<
) {
const sqlParams = query?.toSQL()

console.log(query, sqlParams)

const queryKey = [
UNIQUE_KEY,
//@ts-expect-error -- these are exposed by `drizzle-orm-crsqlite-wasm` but not at the type level
Expand Down Expand Up @@ -425,7 +423,7 @@ export function useDbQuery<
/** leaky cache, seems ok though */
const usedTableCache = new Map<string, string[]>()
async function getUsedTables(db: DB, query: string, callback: (tables: string[]) => void) {
const cacheKey = hashKey([db.filename, query])
const cacheKey = hashKey([db.db, query])
const cached = usedTableCache.get(cacheKey)
if (cached) return callback(cached)
const sanitized = query.replaceAll("'", "''")
Expand Down

0 comments on commit 553b076

Please sign in to comment.