41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type { Expression } from '../expression/expression.js';
|
|
export type ExplainFormat = 'text' | 'xml' | 'json' | 'yaml' | 'traditional' | 'tree';
|
|
export interface Explainable {
|
|
/**
|
|
* Executes query with `explain` statement before the main query.
|
|
*
|
|
* ```ts
|
|
* const explained = await db
|
|
* .selectFrom('person')
|
|
* .where('gender', '=', 'female')
|
|
* .selectAll()
|
|
* .explain('json')
|
|
* ```
|
|
*
|
|
* The generated SQL (MySQL):
|
|
*
|
|
* ```sql
|
|
* explain format=json select * from `person` where `gender` = ?
|
|
* ```
|
|
*
|
|
* You can also execute `explain analyze` statements.
|
|
*
|
|
* ```ts
|
|
* import { sql } from 'kysely'
|
|
*
|
|
* const explained = await db
|
|
* .selectFrom('person')
|
|
* .where('gender', '=', 'female')
|
|
* .selectAll()
|
|
* .explain('json', sql`analyze`)
|
|
* ```
|
|
*
|
|
* The generated SQL (PostgreSQL):
|
|
*
|
|
* ```sql
|
|
* explain (analyze, format json) select * from "person" where "gender" = $1
|
|
* ```
|
|
*/
|
|
explain<O extends Record<string, any> = Record<string, any>>(format?: ExplainFormat, options?: Expression<any>): Promise<O[]>;
|
|
}
|