from() — drizzle-orm Function Reference
Architecture documentation for the from() function in select.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD e522ab7f_d557_6695_4c74_85726b7a8d56["from()"] f56e9cc8_4f98_581a_cbd1_f6264ee5715e["MySqlSelectBuilder"] e522ab7f_d557_6695_4c74_85726b7a8d56 -->|defined in| f56e9cc8_4f98_581a_cbd1_f6264ee5715e e327141d_903f_61a7_65cc_f776f53ea83f["convertIndexToString()"] e522ab7f_d557_6695_4c74_85726b7a8d56 -->|calls| e327141d_903f_61a7_65cc_f776f53ea83f 05cdf6c8_9bfd_a402_2c37_03667291d1e5["toArray()"] e522ab7f_d557_6695_4c74_85726b7a8d56 -->|calls| 05cdf6c8_9bfd_a402_2c37_03667291d1e5 style e522ab7f_d557_6695_4c74_85726b7a8d56 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-orm/src/mysql-core/query-builders/select.ts lines 91–151
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,
isPartialSelect,
session: this.session,
dialect: this.dialect,
withList: this.withList,
distinct: this.distinct,
useIndex,
forceIndex,
ignoreIndex,
},
) as any;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does from() do?
from() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/mysql-core/query-builders/select.ts.
Where is from() defined?
from() is defined in drizzle-orm/src/mysql-core/query-builders/select.ts at line 91.
What does from() call?
from() calls 2 function(s): convertIndexToString, toArray.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free