Skip to content

Commit

Permalink
Rewrite granularities
Browse files Browse the repository at this point in the history
  • Loading branch information
retro committed Aug 7, 2024
1 parent 56da423 commit a197102
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 310 deletions.
19 changes: 12 additions & 7 deletions src/__tests__/clone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ const userModel = semanticLayer
type: "string",
sql: ({ model, sql }) => sql`COUNT(DISTINCT ${model.column("UserId")})`,
})
.withGranularity("name", [
{
key: "name",
elements: ["first_name", "last_name", "user_id"],
display: ["first_name", "last_name"],
},
.withCategoricalGranularity("customer", ({ element }) => [
element("user")
.withDimensions(["user_id", "first_name", "last_name"])
.withFormat(
["first_name", "last_name"],
({ dimension }) =>
`${dimension("first_name")} ${dimension("last_name")}`,
),
]);

const customerModel = userModel.clone("customer");
Expand Down Expand Up @@ -82,7 +84,10 @@ const queryBuilder = repository.build("postgresql");

describe("clone", async () => {
it("can clone a model", async () => {
assert.deepEqual(userModel.granularities, customerModel.granularities);
assert.deepEqual(
userModel.categoricalGranularities,
customerModel.categoricalGranularities,
);
assert.deepEqual(
userModel.granularitiesNames,
customerModel.granularitiesNames,
Expand Down
9 changes: 3 additions & 6 deletions src/__tests__/dialects/mssql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as semanticLayer from "../../index.js";

import { assert, beforeAll, describe, it } from "vitest";

import fs from "node:fs/promises";
import path from "node:path";
import { InferSqlQueryResultType } from "../../index.js";
import { MSSQLServerContainer } from "@testcontainers/mssqlserver";
import fs from "node:fs/promises";
import mssql from "mssql";
import { InferSqlQueryResultType } from "../../index.js";
import path from "node:path";

const customersModel = semanticLayer
.model()
Expand Down Expand Up @@ -476,9 +476,6 @@ describe("mssql dialect", () => {
limit: 1,
});

console.log(query.sql);
console.log(query.bindings);

const result = await runQuery<InferSqlQueryResultType<typeof query>>(
query.sql,
query.bindings,
Expand Down
Loading

0 comments on commit a197102

Please sign in to comment.