Skip to content

Commit

Permalink
Expose query builder schema
Browse files Browse the repository at this point in the history
  • Loading branch information
retro committed Mar 20, 2024
1 parent a626c11 commit 52e1f75
Show file tree
Hide file tree
Showing 12 changed files with 710 additions and 61 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ const repository = semanticLayer
({ sql, dimensions }) =>
sql`${dimensions.invoices.invoice_id} = ${dimensions.invoice_lines.invoice_id}`
);

const queryBuilder = repository.build("postgresql");
```

### Data Querying
Expand All @@ -126,31 +128,31 @@ Leverage the library's querying capabilities to fetch dimensions and metrics, ap

```typescript
// Dimension and metric query
const query = repository.query({
const query = queryBuilder.buildQuery({
dimensions: ["customers.customer_id"],
metrics: ["invoices.total"],
order: { "customers.customer_id": "asc" },
limit: 10,
});

// Metric query with filters
const query = repository.query({
const query = queryBuilder.buildQuery({
metrics: ["invoices.total", "invoice_lines.quantity"],
filters: [
{ operator: "equals", member: "customers.customer_id", value: [1] },
],
});

// Dimension query with filters
const query = repository.query({
const query = queryBuilder.buildQuery({
dimensions: ["customers.first_name", "customers.last_name"],
filters: [
{ operator: "equals", member: "customers.customer_id", value: [1] },
],
});

// Filtering and sorting
const query = repository.query({
const query = queryBuilder.buildQuery({
dimensions: ["customers.first_name"],
metrics: ["invoices.total"],
filters: [{ operator: "gt", member: "invoices.total", value: [100] }],
Expand Down
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"pg": "^8.11.3",
"rimraf": "^5.0.5",
"semantic-release": "^23.0.4",
"typescript": "^5.4.2"
"typescript": "^5.4.2",
"zod-to-json-schema": "^3.22.4"
},
"config": {
"commitizen": {
Expand Down
Loading

0 comments on commit 52e1f75

Please sign in to comment.