-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcli.malloynb
More file actions
180 lines (121 loc) · 4.12 KB
/
cli.malloynb
File metadata and controls
180 lines (121 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
>>>markdown
# Installing the CLI
The [Malloy CLI](https://github.com/malloydata/malloy-cli) is a command-line interface for running `.malloysql` and `.malloy` files. Use it to automate transformations, build pipelines, or compile Malloy queries to SQL.
---
## Installation Options
### Option 1: NPX (No Installation)
Run directly without installing:
```bash
npx malloy-cli --help
```
### Option 2: Global Install via npm
```bash
npm install -g malloy-cli
malloy-cli --help
```
---
## Configure Connections
The CLI stores its own configuration separately from VS Code in `~/.config/malloy/config.json`.
**Note:** The CLI does not support environment variables for connection configuration (except for MotherDuck, which can use `MOTHERDUCK_TOKEN`). Use the CLI commands below to manage connections.
### Connection Commands
```bash
# List all connections
malloy connections list
# Create a new connection
malloy connections create-<type> <name>
# Test a connection
malloy connections test <name>
# Show connection details
malloy connections show <name>
# Delete a connection
malloy connections delete <name>
```
### Create a Connection
```bash
# For BigQuery
malloy-cli connections create-bigquery <connection-name>
# For Postgres
malloy-cli connections create-postgres <connection-name>
# For DuckDB (or MotherDuck)
malloy-cli connections create-duckdb <connection-name>
```
View options for each database type:
```bash
malloy-cli connections create-bigquery --help
```
**BigQuery options:**
```
-p, --project <id> GCP project ID
-l, --location <region> Query location (default: "US")
-k, --service-account-key-path <path> Path to service account JSON key
-t, --timeout <milliseconds> Query timeout
-m, --maximum-bytes-billed <bytes> Limit bytes scanned
```
**DuckDB options:**
```
--database-path <database> Path to DuckDB database file or MotherDuck database (e.g., "md:my_database")
--mother-duck-token <token> MotherDuck API token (can also use MOTHERDUCK_TOKEN env var)
```
### Default Connections
Two connections are created automatically:
- **`bigquery`**: Uses existing gCloud authentication
- **`duckdb`**: Uses a built-in DuckDB instance
If your Malloy files reference these connection names, they work without explicit setup.
### BigQuery with gCloud
If you already use gCloud:
```bash
gcloud auth login --update-adc
malloy-cli connections create-bigquery my-bq
```
### MotherDuck
MotherDuck connections use the `create-duckdb` command with special options. To connect to MotherDuck, you'll need an access token:
1. Log in to MotherDuck and go to **Settings**
2. Create and copy your access token
3. Create the connection using `create-duckdb` with `--database-path` set to `md:` followed by your database name:
**Using environment variable (recommended):**
```bash
export MOTHERDUCK_TOKEN="your_token_here"
malloy-cli connections create-duckdb my-md --database-path "md:my_database"
```
**Using command-line flag:**
```bash
malloy-cli connections create-duckdb my-md \
--database-path "md:my_database" \
--mother-duck-token "your_token_here"
```
If you don't specify a database name, use `md:`:
```bash
malloy-cli connections create-duckdb my-md \
--database-path "md:" \
--mother-duck-token "your_token_here"
```
---
## Basic Commands
### Run Queries
Execute a query and return results:
```bash
# Run a named query from a Malloy file
malloy-cli run path/to/model.malloy --query query_name
# Run a MalloySQL file
malloy-cli run transforms.malloysql
```
### Compile to SQL
Get the generated SQL without executing:
```bash
malloy-cli compile path/to/model.malloy --query query_name
```
Useful for:
- Debugging query logic
- Copying SQL to other tools
- Understanding what Malloy generates
### Get Help
```bash
malloy-cli --help
malloy-cli run --help
malloy-cli compile --help
```
---
## Next Steps
- **[Database Support](database_support.malloynb)** — Overview of all supported databases
- **[Transform & Materialize](../user_guides/transform.malloynb)** — Use the CLI with MalloySQL for data transformations
- [malloy-cli on GitHub](https://github.com/malloydata/malloy-cli)