You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `@verybigthings/semantic-layer` library is crafted to simplify interactions between applications and relational databases, by providing a framework that abstracts SQL query complexities into a more manageable form. It aids in constructing analytical queries while addressing common issues such as join fanout and chasm traps. The library intelligently determines optimal join strategies for requested models, based on their definitions within the database. Designed for direct integration into existing code bases, it operates without the need for deploying external services.
9
+
Welcome to the semanticlayer library! Let's dive in and create a simple data model in just a few steps.
10
10
11
-
## Key Features
11
+
## Installation
12
12
13
-
-**Declarative Schema and Query Building:** Utilize a fluent, TypeScript-based API to define your database schema and queries declaratively.
14
-
-**Type Safety:** Minimize errors with type-safe interfaces for query construction, enhancing code reliability.
15
-
-**Dynamic SQL Query Generation:** Automatically construct complex SQL queries tailored to your application's business logic, eliminating the need for string concatenation.
13
+
First, let's get the library installed (use npm or a package manager of your choice):
16
14
17
-
## Getting Started
18
-
19
-
### Installation
20
-
21
-
To integrate the Semantic Layer Library into your project, run the following command with npm:
22
-
23
-
```shell
15
+
```bash
24
16
npm install @verybigthings/semantic-layer
25
17
```
26
18
27
-
## Usage Examples
19
+
## Building Your First Semantic Layer
28
20
29
-
### Defining Models and Fields
21
+
Imagine you're running a music store. You have customers, and they make purchases. Let's model this!
30
22
31
-
This library allows you to define models and their respective fields, including dimensions and metrics, which represent the various columns and computed values within your database.
23
+
### Step 1: Create Your Models
32
24
33
-
**Defining a Model:**
25
+
We'll create two models: `customers` and `invoices`.
const result =awaitsomeSqlClient.query(query.sql, query.bindings);
164
114
```
165
115
166
-
### Executing queries
167
-
168
-
Note: `@verybigthings/semantic-layer` focuses on SQL generation. Execute the generated queries with your SQL client:
116
+
For example, with the `pg` package for PostgreSQL:
169
117
170
118
```typescript
171
-
const result =awaitsqlClient.query(query.sql, query.bindings);
119
+
const result =awaitpg.query(query.sql, query.bindings);
172
120
```
173
121
174
-
### Limitations
122
+
And there you have it! You've just set up a semantic layer for your music store data. This layer will make it easy to analyze customer purchases without writing complex SQL queries each time.
175
123
176
-
At the moment, only PostgreSQL queries are generated correctly. We're working on adding support for additional dialects.
124
+
Read the [documentation](https://verybigthings.github.io/semantic-layer/)for more information.
177
125
178
126
## Acknowledgments
179
127
180
-
`@verybigthings/semantic-layer` draws inspiration from several BI libraries, particularly [Cube.dev](https://cube.dev). While our API is very close to that of Cube.dev, future development may change our approach.
128
+
`@verybigthings/semantic-layer` draws inspiration from several BI libraries, particularly [Cube.dev](https://cube.dev). While our API was initially inspired by Cube.dev, it has since diverged based on our own needs and preferences.
0 commit comments