create-dql-app 0.11.0 → 1.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,123 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship.
41
+
42
+ "Contribution" shall mean any work of authorship, including the original version
43
+ of the Work and any modifications or additions to that Work or Derivative Works
44
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
45
+ by the copyright owner or by an individual or Legal Entity authorized to submit
46
+ on behalf of the copyright owner.
47
+
48
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
49
+ of whom a Contribution has been received by Licensor and subsequently
50
+ incorporated within the Work.
51
+
52
+ 2. Grant of Copyright License.
53
+
54
+ Subject to the terms and conditions of this License, each Contributor hereby
55
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
56
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
57
+ publicly display, publicly perform, sublicense, and distribute the Work and such
58
+ Derivative Works in Source or Object form.
59
+
60
+ 3. Grant of Patent License.
61
+
62
+ Subject to the terms and conditions of this License, each Contributor hereby
63
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
64
+ irrevocable patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution.
68
+
69
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
70
+ in any medium, with or without modifications, and in Source or Object form,
71
+ provided that You meet the following conditions:
72
+
73
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
74
+ this License; and
75
+
76
+ (b) You must cause any modified files to carry prominent notices stating that
77
+ You changed the files; and
78
+
79
+ (c) You must retain, in the Source form of any Derivative Works that You
80
+ distribute, all copyright, patent, trademark, and attribution notices from the
81
+ Source form of the Work, excluding those notices that do not pertain to any part
82
+ of the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
85
+ any Derivative Works that You distribute must include a readable copy of the
86
+ attribution notices contained within such NOTICE file, excluding those notices
87
+ that do not pertain to any part of the Derivative Works.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
92
+ for inclusion in the Work by You to the Licensor shall be under the terms and
93
+ conditions of this License, without any additional terms or conditions.
94
+
95
+ 6. Trademarks.
96
+
97
+ This License does not grant permission to use the trade names, trademarks,
98
+ service marks, or product names of the Licensor, except as required for
99
+ reasonable and customary use in describing the origin of the Work.
100
+
101
+ 7. Disclaimer of Warranty.
102
+
103
+ Unless required by applicable law or agreed to in writing, Licensor provides the
104
+ Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
105
+ express or implied, including, without limitation, any warranties or conditions
106
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
107
+ PURPOSE.
108
+
109
+ 8. Limitation of Liability.
110
+
111
+ In no event and under no legal theory, whether in tort (including negligence),
112
+ contract, or otherwise, unless required by applicable law, shall any Contributor
113
+ be liable to You for damages, including any direct, indirect, special,
114
+ incidental, or consequential damages of any character arising as a result of this
115
+ License or out of the use or inability to use the Work.
116
+
117
+ 9. Accepting Warranty or Additional Liability.
118
+
119
+ While redistributing the Work or Derivative Works thereof, You may choose to
120
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
121
+ other liability obligations and/or rights consistent with this License.
122
+
123
+ END OF TERMS AND CONDITIONS
@@ -12,10 +12,10 @@
12
12
 
13
13
  import { spawnSync } from 'node:child_process';
14
14
  import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
15
- import { dirname, join, resolve, basename } from 'node:path';
15
+ import { dirname, join, resolve, basename, relative } from 'node:path';
16
16
  import { fileURLToPath } from 'node:url';
17
17
 
18
- const VERSION = '0.11.0';
18
+ const VERSION = '1.0.1';
19
19
  const __dirname = dirname(fileURLToPath(import.meta.url));
20
20
  const TEMPLATES_DIR = resolve(__dirname, '..', 'templates');
21
21
 
@@ -100,6 +100,13 @@ function detectDbtSibling(target) {
100
100
  return null;
101
101
  }
102
102
 
103
+ function detectPackageManager() {
104
+ const ua = process.env.npm_config_user_agent ?? '';
105
+ if (ua.startsWith('pnpm/')) return 'pnpm';
106
+ if (ua.startsWith('yarn/')) return 'yarn';
107
+ return 'npm';
108
+ }
109
+
103
110
  async function main() {
104
111
  const args = parseArgs(process.argv.slice(2));
105
112
  if (!args.dir) {
@@ -129,28 +136,38 @@ async function main() {
129
136
  copyDir(tplDir, target);
130
137
 
131
138
  const dbtSibling = detectDbtSibling(target);
139
+ // Store dbt path as relative-to-project — keeps dql.config.json portable.
140
+ const dbtRel = dbtSibling ? (relative(target, dbtSibling) || '.') : '../my-dbt-project';
132
141
  const vars = {
133
142
  PROJECT_NAME: projectName,
134
143
  YEAR: String(new Date().getFullYear()),
135
- DBT_PROJECT_DIR: dbtSibling ? resolve(dbtSibling) : '../my-dbt-project',
144
+ DBT_PROJECT_DIR: dbtRel,
136
145
  DBT_DETECTED: dbtSibling ? 'true' : 'false',
137
146
  };
138
147
  for (const f of walk(target)) substitute(f, vars);
139
148
 
140
149
  if (dbtSibling) {
141
150
  console.log(c.dim(` detected sibling dbt project at ${dbtSibling}`));
142
- console.log(c.dim(` wired into cdql.yaml — run 'dql sync dbt' to import\n`));
151
+ console.log(c.dim(` wired into dql.config.json — run 'dql sync dbt' to import\n`));
143
152
  }
144
153
 
145
154
  // Best-effort: try to run `git init` so users get a clean first commit.
146
155
  const gitResult = spawnSync('git', ['init', '-q'], { cwd: target });
147
156
  if (gitResult.status === 0) console.log(c.dim(' initialized git repo'));
148
157
 
158
+ const pm = detectPackageManager();
159
+ const installCmd = pm === 'npm' ? 'npm install' : `${pm} install`;
160
+ const runCmd = pm === 'npm' ? 'npm run notebook' : `${pm} notebook`;
161
+ const dbtTip = dbtSibling
162
+ ? `\n\n${c.dim('Tip:')} run ${c.bold('dbt parse')} inside ${c.dim(dbtSibling)}\n first, then ${c.bold(pm === 'npm' ? 'npm run sync' : `${pm} sync`)} to import the dbt DAG.`
163
+ : '';
164
+
149
165
  console.log(`
150
166
  ${c.green('✓ Ready.')} Next steps:
151
167
 
152
168
  ${c.bold(`cd ${args.dir}`)}
153
- ${c.bold('npx @duckcodeailabs/dql-cli notebook')}
169
+ ${c.bold(installCmd)}
170
+ ${c.bold(runCmd)}${dbtTip}
154
171
 
155
172
  Your notebook will open at ${c.cyan('http://localhost:5173')}.
156
173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-dql-app",
3
- "version": "0.11.0",
3
+ "version": "1.0.1",
4
4
  "description": "Scaffold a new DQL project. Run with: npx create-dql-app <name>",
5
5
  "license": "MIT",
6
6
  "author": "DuckCode AI Labs",
@@ -10,7 +10,14 @@
10
10
  "url": "https://github.com/duckcode-ai/dql.git",
11
11
  "directory": "packages/create-dql-app"
12
12
  },
13
- "keywords": ["dql", "dbt", "analytics", "notebook", "semantic-layer", "lineage"],
13
+ "keywords": [
14
+ "dql",
15
+ "dbt",
16
+ "analytics",
17
+ "notebook",
18
+ "semantic-layer",
19
+ "lineage"
20
+ ],
14
21
  "bin": {
15
22
  "create-dql-app": "./bin/create-dql-app.mjs"
16
23
  },
@@ -20,14 +27,14 @@
20
27
  "README.md"
21
28
  ],
22
29
  "type": "module",
23
- "scripts": {
24
- "test": "node test/smoke.mjs",
25
- "build": "echo 'no build step — pure JS'"
26
- },
27
30
  "engines": {
28
31
  "node": ">=20"
29
32
  },
30
33
  "publishConfig": {
31
34
  "access": "public"
35
+ },
36
+ "scripts": {
37
+ "test": "node test/smoke.mjs",
38
+ "build": "echo 'no build step — pure JS'"
32
39
  }
33
- }
40
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "project": "{{PROJECT_NAME}}",
3
+ "connections": {
4
+ "default": {
5
+ "driver": "duckdb",
6
+ "filepath": ":memory:"
7
+ }
8
+ },
9
+ "semanticLayer": {
10
+ "provider": "dql",
11
+ "path": "semantic-layer"
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "version": 1,
3
+ "metadata": {
4
+ "title": "{{PROJECT_NAME}} — Welcome",
5
+ "description": "Replace this cell with your first query."
6
+ },
7
+ "cells": [
8
+ {
9
+ "id": "intro",
10
+ "type": "markdown",
11
+ "source": "# {{PROJECT_NAME}}\n\nWelcome to DQL. Connect a warehouse in `dql.config.json`, then edit the cell below."
12
+ },
13
+ {
14
+ "id": "first_query",
15
+ "type": "sql",
16
+ "title": "First query",
17
+ "source": "select 1 as hello"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "notebook": "dql notebook",
7
+ "compile": "dql compile",
8
+ "doctor": "dql doctor"
9
+ },
10
+ "devDependencies": {
11
+ "@duckcodeailabs/dql-cli": "^1.0.0"
12
+ }
13
+ }
@@ -5,24 +5,38 @@ A DQL analytics project, scaffolded by `create-dql-app`.
5
5
  ## Run
6
6
 
7
7
  ```bash
8
- npx @duckcodeailabs/dql-cli notebook
8
+ npm install
9
+ npm run notebook
9
10
  ```
10
11
 
11
- Opens the notebook at <http://localhost:5173>.
12
+ Opens the notebook at <http://localhost:5173>. (`pnpm install && pnpm notebook`
13
+ works too.)
12
14
 
13
15
  ## Layout
14
16
 
15
17
  ```
16
- cdql.yaml project config (connections, dbt, governance)
17
- notebooks/ analytics notebooks (.dql)
18
- blocks/ certified reusable blocks, grouped by domain
18
+ dql.config.json project config (connections, dbt, semantic layer)
19
+ package.json npm scripts — `notebook`, `compile`, `sync`, `doctor`
20
+ notebooks/ .dqlnb notebooks (JSON format)
21
+ blocks/ certified reusable .dql blocks
19
22
  semantic-layer/ metrics + dimensions authored locally
20
23
  dashboards/ compiled static HTML dashboards (git-ignored)
21
24
  ```
22
25
 
26
+ ## Using with dbt
27
+
28
+ If your dbt project is a sibling (e.g. `../dbt`), it was auto-wired into
29
+ `dql.config.json` under the `dbt:` key. Then:
30
+
31
+ ```bash
32
+ (cd ../dbt && dbt parse) # produces target/manifest.json
33
+ npm run sync # refreshes the DQL cache from dbt
34
+ npm run compile # builds dql-manifest.json with lineage
35
+ ```
36
+
23
37
  ## Next steps
24
38
 
25
- 1. **Run the welcome notebook** — `notebooks/welcome.dql`
39
+ 1. **Run the welcome notebook** — `notebooks/welcome.dqlnb`
26
40
  2. **Connect your warehouse** — [docs.duckcode.ai/guides/connect-warehouse](https://docs.duckcode.ai/guides/connect-warehouse/)
27
41
  3. **Import your dbt project** — [docs.duckcode.ai/guides/import-dbt](https://docs.duckcode.ai/guides/import-dbt/)
28
42
  4. **Author a certified block** — [docs.duckcode.ai/guides/authoring-blocks](https://docs.duckcode.ai/guides/authoring-blocks/)
@@ -0,0 +1,29 @@
1
+ // dql-format: 1
2
+
3
+ block "Revenue by segment" {
4
+ domain = "finance"
5
+ type = "custom"
6
+ description = "Gross revenue grouped by customer segment."
7
+ tags = ["revenue", "sample"]
8
+
9
+ query = """
10
+ SELECT
11
+ c.customer_segment AS segment,
12
+ SUM(o.amount) AS revenue,
13
+ COUNT(DISTINCT o.customer_id) AS customers
14
+ FROM orders o
15
+ JOIN customers c ON c.customer_id = o.customer_id
16
+ GROUP BY 1
17
+ ORDER BY revenue DESC
18
+ """
19
+
20
+ visualization {
21
+ chart = "bar"
22
+ x = segment
23
+ y = revenue
24
+ }
25
+
26
+ tests {
27
+ assert row_count > 0
28
+ }
29
+ }
@@ -1,22 +1,29 @@
1
1
  // dql-format: 1
2
2
 
3
- dashboard: {
4
- title: "{{PROJECT_NAME}} — Overview"
5
- description: "Revenue overview generated by create-dql-app."
6
- layout: "grid"
7
- }
8
-
9
- ---
10
- type: markdown
11
- ---
12
-
13
- # Overview — {{YEAR}}
3
+ dashboard "{{PROJECT_NAME}} — Overview" {
4
+ chart.kpi(
5
+ SELECT SUM(amount) as revenue FROM orders,
6
+ metrics = ["revenue"]
7
+ )
14
8
 
15
- Compiled with `dql compile dashboards/overview.dql --out build/`. Host the
16
- resulting HTML anywhere.
9
+ chart.bar(
10
+ SELECT customer_id, SUM(amount) as spend
11
+ FROM orders
12
+ GROUP BY customer_id
13
+ ORDER BY spend DESC
14
+ LIMIT 10,
15
+ x = customer_id,
16
+ y = spend,
17
+ title = "Top 10 customers by spend"
18
+ )
17
19
 
18
- ---
19
- type: dql
20
- ---
21
-
22
- @block("revenue_by_segment")
20
+ chart.line(
21
+ SELECT order_date, SUM(amount) as revenue
22
+ FROM orders
23
+ GROUP BY order_date
24
+ ORDER BY order_date,
25
+ x = order_date,
26
+ y = revenue,
27
+ title = "Daily revenue"
28
+ )
29
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "project": "{{PROJECT_NAME}}",
3
+ "connections": {
4
+ "default": {
5
+ "driver": "duckdb",
6
+ "filepath": ":memory:"
7
+ }
8
+ },
9
+ "semanticLayer": {
10
+ "provider": "dql",
11
+ "path": "semantic-layer"
12
+ },
13
+ "dbt": {
14
+ "projectDir": "{{DBT_PROJECT_DIR}}",
15
+ "manifestPath": "target/manifest.json"
16
+ },
17
+ "governance": {
18
+ "required_fields": ["domain", "owner", "description"]
19
+ }
20
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "version": 1,
3
+ "metadata": {
4
+ "title": "{{PROJECT_NAME}} — Welcome",
5
+ "description": "A tour of DQL in four cells. Run them top-to-bottom with Cmd+Enter."
6
+ },
7
+ "cells": [
8
+ {
9
+ "id": "intro",
10
+ "type": "markdown",
11
+ "source": "# Welcome to {{PROJECT_NAME}}\n\nThis notebook runs against a DuckDB-backed Jaffle Shop dataset — the same demo data dbt ships.\n\n- Run each cell with `Cmd/Ctrl + Enter`.\n- Charts render inline from SQL results.\n- The certified block in cell 4 lives in `blocks/revenue_by_segment.dql` and can be reused across notebooks and dashboards."
12
+ },
13
+ {
14
+ "id": "orders_overview",
15
+ "type": "sql",
16
+ "title": "Orders overview",
17
+ "source": "select\n count(*) as total_orders,\n count(distinct customer_id) as unique_customers,\n sum(amount) as lifetime_revenue\nfrom orders"
18
+ },
19
+ {
20
+ "id": "daily_revenue",
21
+ "type": "sql",
22
+ "title": "Daily revenue",
23
+ "source": "select\n order_date,\n sum(amount) as revenue\nfrom orders\ngroup by 1\norder by 1"
24
+ },
25
+ {
26
+ "id": "revenue_by_segment",
27
+ "type": "dql",
28
+ "title": "Revenue by segment (certified block)",
29
+ "source": "@block(\"Revenue by segment\")"
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "DQL analytics project.",
6
+ "scripts": {
7
+ "notebook": "dql notebook",
8
+ "compile": "dql compile",
9
+ "sync": "dql sync dbt",
10
+ "doctor": "dql doctor",
11
+ "test": "dql test"
12
+ },
13
+ "devDependencies": {
14
+ "@duckcodeailabs/dql-cli": "^1.0.0"
15
+ }
16
+ }
@@ -1,13 +0,0 @@
1
- project:
2
- name: {{PROJECT_NAME}}
3
- version: 1
4
-
5
- connections:
6
- # Swap this for your warehouse — postgres, snowflake, bigquery, etc.
7
- # See https://docs.duckcode.ai/reference/connectors/
8
- default:
9
- driver: duckdb
10
- path: ./warehouse.duckdb
11
-
12
- governance:
13
- required_fields: [domain, owner, description]
@@ -1,17 +0,0 @@
1
- // dql-format: 1
2
-
3
- ---
4
- type: markdown
5
- ---
6
-
7
- # {{PROJECT_NAME}}
8
-
9
- Welcome to DQL. Start by connecting a warehouse (`cdql.yaml`), then replace
10
- this cell with your first query.
11
-
12
- ---
13
- type: sql
14
- name: first_query
15
- ---
16
-
17
- select 1 as hello;
@@ -1,23 +0,0 @@
1
- // dql-format: 1
2
-
3
- block revenue_by_segment {
4
- domain: "finance"
5
- owner: "analytics@{{PROJECT_NAME}}.local"
6
- tags: ["revenue", "sample"]
7
- description: "Gross revenue grouped by customer segment."
8
-
9
- query: |
10
- select
11
- c.segment,
12
- sum(o.order_total) as revenue,
13
- count(distinct o.customer_id) as customers
14
- from orders o
15
- join customers c on c.customer_id = o.customer_id
16
- group by 1
17
- order by revenue desc
18
-
19
- visualization: bar(x: "segment", y: "revenue", title: "Revenue by segment")
20
-
21
- tests:
22
- - row_count > 0
23
- }
@@ -1,17 +0,0 @@
1
- project:
2
- name: {{PROJECT_NAME}}
3
- version: 1
4
-
5
- connections:
6
- default:
7
- driver: duckdb
8
- path: ./warehouse.duckdb
9
-
10
- # Remove this block if you aren't using dbt. DQL reads target/manifest.json
11
- # directly — see https://docs.duckcode.ai/guides/import-dbt/
12
- dbt:
13
- projectDir: {{DBT_PROJECT_DIR}}
14
- manifestPath: target/manifest.json
15
-
16
- governance:
17
- required_fields: [domain, owner, description]
@@ -1,44 +0,0 @@
1
- // dql-format: 1
2
-
3
- // Welcome to DQL. This notebook runs against a DuckDB-backed Jaffle Shop
4
- // dataset — the same demo data dbt ships. Press ⌘↵ on each cell.
5
-
6
- ---
7
- type: markdown
8
- ---
9
-
10
- # {{PROJECT_NAME}}
11
-
12
- A tour of DQL in four cells. Run them top-to-bottom.
13
-
14
- ---
15
- type: sql
16
- name: orders_overview
17
- ---
18
-
19
- select
20
- count(*) as total_orders,
21
- count(distinct customer_id) as unique_customers,
22
- sum(order_total) as lifetime_revenue
23
- from orders;
24
-
25
- ---
26
- type: sql
27
- name: daily_revenue
28
- ---
29
-
30
- select
31
- order_date,
32
- sum(order_total) as revenue
33
- from orders
34
- group by 1
35
- order by 1;
36
-
37
- ---
38
- type: dql
39
- name: revenue_by_segment
40
- ---
41
-
42
- // Reference a certified block. The block lives in blocks/finance/ and can
43
- // be reused across notebooks, dashboards, and other blocks.
44
- @block("revenue_by_segment")