@devrev/meerkat-browser 0.0.96 → 0.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +80 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,85 @@
1
- # meerkat-browser
1
+ # @devrev/meerkat-browser
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ `@devrev/meerkat-browser` is a library for converting cube queries into SQL and executing them in a browser environment using [@duckdb/duckdb-wasm](https://github.com/duckdb/duckdb-wasm). It serves as a client-side query engine within the Meerkat ecosystem.
4
4
 
5
- ## Building
5
+ This package uses `@devrev/meerkat-core` to generate a DuckDB-compatible AST and `@duckdb/duckdb-wasm` to execute the resulting query against data sources available to the browser.
6
6
 
7
- Run `nx build meerkat-browser` to build the library.
7
+ ## Key Features
8
8
 
9
- ## Running unit tests
9
+ - **Cube to SQL Execution**: Translates cube queries into SQL and executes them in the browser.
10
+ - **Browser Optimized**: Built to work seamlessly with `@duckdb/duckdb-wasm`.
11
+ - **Client-Side Analytics**: Enables powerful, in-browser data analysis without a server round-trip.
10
12
 
11
- Run `nx test meerkat-browser` to execute the unit tests via [Jest](https://jestjs.io).
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @devrev/meerkat-browser @devrev/meerkat-core @duckdb/duckdb-wasm
17
+ ```
18
+
19
+ `@duckdb/duckdb-wasm` is a peer dependency and should be configured according to its documentation.
20
+
21
+ ## Usage
22
+
23
+ Here's a example of how to convert a cube query into SQL and execute the query in the client side with duckdb-wasm.
24
+
25
+ ```typescript
26
+ import * as duckdb from '@duckdb/duckdb-wasm';
27
+ import { cubeQueryToSQL } from '@devrev/meerkat-browser';
28
+ import { Query, TableSchema } from '@devrev/meerkat-core';
29
+
30
+ async function main() {
31
+ // 1. Initialize DuckDB-WASM
32
+ const logger = new duckdb.ConsoleLogger();
33
+ const worker = new Worker(duckdb.getJsDelivrWorker());
34
+ const bundle = await duckdb.selectBundle(duckdb.getJsDelivrBundles());
35
+ const db = new duckdb.AsyncDuckDB(logger, worker);
36
+ await db.open(bundle);
37
+ const connection = await db.connect();
38
+
39
+ // 2. Define your table schemas
40
+ const tableSchemas: TableSchema[] = [
41
+ {
42
+ name: 'users',
43
+ // The SQL could point to a registered file or another data source
44
+ sql: 'SELECT * FROM users',
45
+ columns: [
46
+ { name: 'id', type: 'INTEGER' },
47
+ { name: 'name', type: 'VARCHAR' },
48
+ { name: 'city', type: 'VARCHAR' },
49
+ { name: 'signed_up_at', type: 'TIMESTAMP' },
50
+ ],
51
+ },
52
+ ];
53
+
54
+ // 3. Define your Cube query
55
+ const query: Query = {
56
+ measures: ['users.count'],
57
+ dimensions: ['users.city'],
58
+ filters: [
59
+ {
60
+ member: 'users.city',
61
+ operator: 'equals',
62
+ values: ['New York'],
63
+ },
64
+ ],
65
+ limit: 100,
66
+ };
67
+
68
+ // 4. Convert the query to SQL
69
+ const sqlQuery = await cubeQueryToSQL({
70
+ connection,
71
+ query,
72
+ tableSchemas,
73
+ });
74
+
75
+ // 5. You can now execute the generated SQL query with DuckDB
76
+ const result = await connection.query(sqlQuery);
77
+
78
+ console.log(
79
+ 'Query Results:',
80
+ result.toArray().map((row) => row.toJSON())
81
+ );
82
+ }
83
+
84
+ main();
85
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/meerkat-browser",
3
- "version": "0.0.96",
3
+ "version": "0.0.97",
4
4
  "dependencies": {
5
5
  "@swc/helpers": "~0.5.0",
6
6
  "@devrev/meerkat-core": "*",