Skip to content

Commit dc535cc

Browse files
committed
feat: add query plan utility for SQLite queries
1 parent abffd3e commit dc535cc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/query-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { LibSQLDatabase } from 'drizzle-orm/libsql'
2+
import { SQLiteRelationalQuery } from 'drizzle-orm/sqlite-core/query-builders/query'
3+
4+
import relations from './relations'
5+
import * as schema from './schema'
6+
7+
export const getQueryPlan = async <Q extends SQLiteRelationalQuery<'async', unknown>>(
8+
db: LibSQLDatabase<typeof schema, typeof relations>,
9+
query: Q,
10+
) => db.run(`EXPLAIN QUERY PLAN ${query.toSQL().sql}`).then((r) => r.rows.map((row) => row.detail))

0 commit comments

Comments
 (0)