Skip to content

Commit

Permalink
Fixed sqlite rqb v2 query not working properly with sync drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukairo-02 committed Dec 20, 2024
1 parent 68c5844 commit 0ab568f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
1 change: 1 addition & 0 deletions drizzle-orm/src/sqlite-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class BaseSQLiteDatabase<
TablesRelationalConfig,
V1.TablesRelationalConfig
>['query'])[tableName] = new RelationalQueryBuilder(
resultKind,
relations.tables,
relations.tablesConfig,
relations.tableNamesMap,
Expand Down
78 changes: 52 additions & 26 deletions drizzle-orm/src/sqlite-core/query-builders/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,71 @@ export class RelationalQueryBuilder<
static readonly [entityKind]: string = 'SQLiteAsyncRelationalQueryBuilderV2';

constructor(
private mode: TMode,
private tables: Record<string, SQLiteTable>,
private schema: TSchema,
private tableNamesMap: Record<string, string>,
private table: SQLiteTable,
private tableConfig: TableRelationalConfig,
private dialect: SQLiteDialect,
private session: SQLiteSession<TMode, any, any, any, any, any>,
) {}
private session: SQLiteSession<any, any, any, any, any, any>,
) {
}

findMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(
config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>,
): SQLiteRelationalQuery<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]> {
return new SQLiteRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'many'> | undefined ?? true,
'many',
);
): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]> {
return this.mode === 'sync'
? new SQLiteSyncRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'many'> | undefined ?? true,
'many',
) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>
: new SQLiteRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'many'> | undefined ?? true,
'many',
) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>;
}

findFirst<TConfig extends DBQueryConfig<'one', TSchema, TFields>>(
config?: KnownKeysOnly<TConfig, DBQueryConfig<'one', TSchema, TFields>>,
): SQLiteRelationalQuery<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined> {
return new SQLiteRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'one'> | undefined ?? true,
'first',
);
): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined> {
return this.mode === 'sync'
? new SQLiteSyncRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'one'> | undefined ?? true,
'first',
) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined>
: new SQLiteRelationalQuery(
this.tables,
this.schema,
this.tableNamesMap,
this.table,
this.tableConfig,
this.dialect,
this.session,
config as DBQueryConfig<'one'> | undefined ?? true,
'first',
) as SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig> | undefined>;
}
}

Expand Down

0 comments on commit 0ab568f

Please sign in to comment.