diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index af21d56..1a9f7f4 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1238,6 +1238,8 @@ await describe("semantic layer", async () => { const docs: string[] = []; const dimensions = repository.getDimensions(); const metrics = repository.getMetrics(); + const joins = repository.getJoins(); + for (const dimension of dimensions) { docs.push( `DIMENSION: ${dimension.getPath()}, TYPE: ${dimension.getType()}, DESCRIPTION: ${ @@ -1252,12 +1254,16 @@ await describe("semantic layer", async () => { }, FORMAT: ${metric.getFormat() ?? "-"}`, ); } + for (const join of joins) { + docs.push(`JOIN: ${join.left} -> ${join.right}, TYPE: ${join.type}`); + } assert.deepEqual(docs, [ "DIMENSION: customers.customer_id, TYPE: number, DESCRIPTION: The unique identifier of the customer, FORMAT: -", "DIMENSION: invoices.invoice_id, TYPE: number, DESCRIPTION: The unique identifier of the invoice, FORMAT: -", "DIMENSION: invoices.customer_id, TYPE: number, DESCRIPTION: The unique identifier of the invoice customer, FORMAT: -", "METRIC: invoices.total, TYPE: string, DESCRIPTION: -, FORMAT: percentage", + "JOIN: customers -> invoices, TYPE: oneToMany", ]); }); diff --git a/src/lib/repository.ts b/src/lib/repository.ts index 8dc0446..7c5ed85 100644 --- a/src/lib/repository.ts +++ b/src/lib/repository.ts @@ -277,6 +277,12 @@ export class Repository< return this.joins[modelName]?.[joinModelName]; } + getJoins() { + return Object.values(this.joins) + .flatMap((joins) => Object.values(joins)) + .filter((join) => !join.reversed); + } + build(dialectName: AvailableDialects) { const { client, Dialect } = getClientAndDialect(dialectName); return new QueryBuilder(this, new Dialect(), client);