MySqlSelectBuilder Class — drizzle-orm Architecture
Architecture documentation for the MySqlSelectBuilder class in select.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD f56e9cc8_4f98_581a_cbd1_f6264ee5715e["MySqlSelectBuilder"] beabf465_fa9a_6d7b_17f0_933ae73209d6["select.ts"] f56e9cc8_4f98_581a_cbd1_f6264ee5715e -->|defined in| beabf465_fa9a_6d7b_17f0_933ae73209d6 fe940f74_a490_6a4b_cc57_34207272cc32["constructor()"] f56e9cc8_4f98_581a_cbd1_f6264ee5715e -->|method| fe940f74_a490_6a4b_cc57_34207272cc32 e522ab7f_d557_6695_4c74_85726b7a8d56["from()"] f56e9cc8_4f98_581a_cbd1_f6264ee5715e -->|method| e522ab7f_d557_6695_4c74_85726b7a8d56
Relationship Graph
Source Code
drizzle-orm/src/mysql-core/query-builders/select.ts lines 60–152
export class MySqlSelectBuilder<
TSelection extends SelectedFields | undefined,
TPreparedQueryHKT extends PreparedQueryHKTBase,
TBuilderMode extends 'db' | 'qb' = 'db',
> {
static readonly [entityKind]: string = 'MySqlSelectBuilder';
private fields: TSelection;
private session: MySqlSession | undefined;
private dialect: MySqlDialect;
private withList: Subquery[] = [];
private distinct: boolean | undefined;
constructor(
config: {
fields: TSelection;
session: MySqlSession | undefined;
dialect: MySqlDialect;
withList?: Subquery[];
distinct?: boolean;
},
) {
this.fields = config.fields;
this.session = config.session;
this.dialect = config.dialect;
if (config.withList) {
this.withList = config.withList;
}
this.distinct = config.distinct;
}
from<TFrom extends MySqlTable | Subquery | MySqlViewBase | SQL>(
source: TFrom,
onIndex?: TFrom extends MySqlTable ? IndexConfig
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views',
): CreateMySqlSelectFromBuilderMode<
TBuilderMode,
GetSelectTableName<TFrom>,
TSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,
TSelection extends undefined ? 'single' : 'partial',
TPreparedQueryHKT
> {
const isPartialSelect = !!this.fields;
let fields: SelectedFields;
if (this.fields) {
fields = this.fields;
} else if (is(source, Subquery)) {
// This is required to use the proxy handler to get the correct field values from the subquery
fields = Object.fromEntries(
Object.keys(source._.selectedFields).map((
key,
) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),
);
} else if (is(source, MySqlViewBase)) {
fields = source[ViewBaseConfig].selectedFields as SelectedFields;
} else if (is(source, SQL)) {
fields = {};
} else {
fields = getTableColumns<MySqlTable>(source);
}
let useIndex: string[] = [];
let forceIndex: string[] = [];
let ignoreIndex: string[] = [];
if (is(source, MySqlTable) && onIndex && typeof onIndex !== 'string') {
if (onIndex.useIndex) {
useIndex = convertIndexToString(toArray(onIndex.useIndex));
}
if (onIndex.forceIndex) {
forceIndex = convertIndexToString(toArray(onIndex.forceIndex));
}
if (onIndex.ignoreIndex) {
ignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));
}
}
return new MySqlSelectBase(
{
table: source,
fields,
Domain
Source
Frequently Asked Questions
What is the MySqlSelectBuilder class?
MySqlSelectBuilder is a class in the drizzle-orm codebase, defined in drizzle-orm/src/mysql-core/query-builders/select.ts.
Where is MySqlSelectBuilder defined?
MySqlSelectBuilder is defined in drizzle-orm/src/mysql-core/query-builders/select.ts at line 60.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free