Skip to content

Commit

Permalink
fix relational query?
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchwadair committed Jul 25, 2024
1 parent 404d420 commit bc86043
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drizzle-orm/src/singlestore-core/dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ export class SingleStoreDialect {
where = and(joinOn, where);

if (nestedQueryRelation) {
let field = sql`json_to_array(${
let field = sql`json_agg(${
sql.join(
selection.map(({ field, tsKey, isJson }) =>
isJson
Expand All @@ -767,7 +767,7 @@ export class SingleStoreDialect {
)
})`;
if (is(nestedQueryRelation, Many)) {
field = sql`coalesce(json_to_arrayagg(${field}), json_to_array())`;
field = sql`coalesce(json_agg(${field}), json_agg())`;
}
const nestedSelection = [{
dbKey: 'data',
Expand Down Expand Up @@ -1025,8 +1025,7 @@ export class SingleStoreDialect {
});
let fieldSql = sql`(${builtRelation.sql})`;
if (is(relation, Many)) {
fieldSql = sql`coalesce(${fieldSql}, json_to_array())`;
}
fieldSql = sql`coalesce(${fieldSql}, json_agg())`; }
const field = fieldSql.as(selectedRelationTsKey);
selection.push({
dbKey: selectedRelationTsKey,
Expand All @@ -1051,7 +1050,7 @@ export class SingleStoreDialect {
where = and(joinOn, where);

if (nestedQueryRelation) {
let field = sql`json_to_array(${
let field = sql`json_agg(${
sql.join(
selection.map(({ field }) =>
is(field, SingleStoreColumn) ? sql.identifier(field.name) : is(field, SQL.Aliased) ? field.sql : field
Expand All @@ -1060,7 +1059,7 @@ export class SingleStoreDialect {
)
})`;
if (is(nestedQueryRelation, Many)) {
field = sql`json_to_arrayagg(${field})`;
field = sql`json_agg(${field})`;
}
const nestedSelection = [{
dbKey: 'data',
Expand Down

0 comments on commit bc86043

Please sign in to comment.