GelDatabase Class — drizzle-orm Architecture
Architecture documentation for the GelDatabase class in db.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 2d57d0b7_4a77_af8e_8027_62a4fb11f803["GelDatabase"] 9b087225_652d_6b65_62a9_87af0bff69c9["db.ts"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|defined in| 9b087225_652d_6b65_62a9_87af0bff69c9 d12a6080_0a2b_c44d_b2e5_fd495a343fd9["constructor()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| d12a6080_0a2b_c44d_b2e5_fd495a343fd9 de5b0f24_d478_a1db_8df5_4c89acbc2b82["$with()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| de5b0f24_d478_a1db_8df5_4c89acbc2b82 aafdc4b0_652a_1d5b_4c00_2be6dfd07b3b["$count()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| aafdc4b0_652a_1d5b_4c00_2be6dfd07b3b de082ae7_ed27_1ff7_a0ea_26b4841c3633["with()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| de082ae7_ed27_1ff7_a0ea_26b4841c3633 8b6fe780_2735_4d40_58d5_5812a013740c["select()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 8b6fe780_2735_4d40_58d5_5812a013740c c3eded38_37aa_4fe4_bd2c_4904f6aec4e4["selectDistinct()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| c3eded38_37aa_4fe4_bd2c_4904f6aec4e4 629dd302_a3f5_ca4b_2314_108ea327f807["selectDistinctOn()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 629dd302_a3f5_ca4b_2314_108ea327f807 530dda0f_a6c2_24bc_0de1_af7772e2b801["update()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 530dda0f_a6c2_24bc_0de1_af7772e2b801 2dfa5289_723e_ca21_62bb_5086546fc2fc["insert()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 2dfa5289_723e_ca21_62bb_5086546fc2fc 8b614768_fd24_bca5_2913_3732dc60d8e0["delete()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 8b614768_fd24_bca5_2913_3732dc60d8e0 e8e29963_fbb6_348d_5909_b77cb7286be4["execute()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| e8e29963_fbb6_348d_5909_b77cb7286be4 27f51009_7960_cf02_6403_fcd1154c9b3d["transaction()"] 2d57d0b7_4a77_af8e_8027_62a4fb11f803 -->|method| 27f51009_7960_cf02_6403_fcd1154c9b3d
Relationship Graph
Source Code
drizzle-orm/src/gel-core/db.ts lines 27–623
export class GelDatabase<
TQueryResult extends GelQueryResultHKT,
TFullSchema extends Record<string, unknown> = Record<string, never>,
TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,
> {
static readonly [entityKind]: string = 'GelDatabase';
declare readonly _: {
readonly schema: TSchema | undefined;
readonly fullSchema: TFullSchema;
readonly tableNamesMap: Record<string, string>;
readonly session: GelSession<TQueryResult, TFullSchema, TSchema>;
};
query: TFullSchema extends Record<string, never>
? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>
: {
[K in keyof TSchema]: RelationalQueryBuilder<TSchema, TSchema[K]>;
};
constructor(
/** @internal */
readonly dialect: GelDialect,
/** @internal */
readonly session: GelSession<any, any, any>,
schema: RelationalSchemaConfig<TSchema> | undefined,
) {
this._ = schema
? {
schema: schema.schema,
fullSchema: schema.fullSchema as TFullSchema,
tableNamesMap: schema.tableNamesMap,
session,
}
: {
schema: undefined,
fullSchema: {} as TFullSchema,
tableNamesMap: {},
session,
};
this.query = {} as typeof this['query'];
if (this._.schema) {
for (const [tableName, columns] of Object.entries(this._.schema)) {
(this.query as GelDatabase<TQueryResult, Record<string, any>>['query'])[tableName] = new RelationalQueryBuilder(
schema!.fullSchema,
this._.schema,
this._.tableNamesMap,
schema!.fullSchema[tableName] as GelTable,
columns,
dialect,
session,
);
}
}
this.$cache = { invalidate: async (_params: any) => {} };
}
/**
* Creates a subquery that defines a temporary named result set as a CTE.
*
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
*
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
*
* @param alias The alias for the subquery.
*
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
*
* @example
*
* ```ts
* // Create a subquery with alias 'sq' and use it in the select query
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
*
* const result = await db.with(sq).select().from(sq);
* ```
*
* To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
*
* ```ts
Domain
Defined In
Source
Frequently Asked Questions
What is the GelDatabase class?
GelDatabase is a class in the drizzle-orm codebase, defined in drizzle-orm/src/gel-core/db.ts.
Where is GelDatabase defined?
GelDatabase is defined in drizzle-orm/src/gel-core/db.ts at line 27.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free