tplm-lang 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -84,6 +84,16 @@ const tpl = fromBigQueryTable({
84
84
  credentialsPath: "./credentials.json",
85
85
  });
86
86
 
87
+ // Pre-built connection (any Malloy Connection instance)
88
+ import { fromConnection } from "tplm-lang";
89
+ import { BigQueryConnection } from "@malloydata/db-bigquery";
90
+ const conn = new BigQueryConnection("bigquery", {}, { credentials });
91
+ const tpl = fromConnection({
92
+ connection: conn,
93
+ table: "project.dataset.sales",
94
+ dialect: "bigquery",
95
+ });
96
+
87
97
  // Then query the same way
88
98
  const { html } = await tpl.query("TABLE ROWS region * revenue.sum;");
89
99
  ```
@@ -184,18 +194,29 @@ COLS education * (revenue.sum ACROSS COLS | revenue.mean)
184
194
  ### Easy Connectors (Recommended)
185
195
 
186
196
  ```typescript
187
- import { fromCSV, fromDuckDBTable, fromBigQueryTable } from "tplm-lang";
197
+ import {
198
+ fromCSV, fromDuckDBTable, fromBigQueryTable, fromConnection
199
+ } from "tplm-lang";
188
200
 
189
201
  // CSV or Parquet files
190
202
  const tpl = fromCSV("data/sales.csv");
191
203
  const tpl = fromDuckDBTable("data/sales.parquet");
192
204
 
193
- // BigQuery
205
+ // BigQuery (file-based credentials)
194
206
  const tpl = fromBigQueryTable({
195
207
  table: "project.dataset.sales",
196
208
  credentialsPath: "./credentials.json",
197
209
  });
198
210
 
211
+ // Pre-built connection (inject any Malloy Connection instance)
212
+ import { BigQueryConnection } from "@malloydata/db-bigquery";
213
+ const conn = new BigQueryConnection("bigquery", {}, { credentials });
214
+ const tpl = fromConnection({
215
+ connection: conn,
216
+ table: "project.dataset.sales",
217
+ dialect: "bigquery", // or "duckdb"
218
+ });
219
+
199
220
  // Add computed dimensions with .extend()
200
221
  const tplWithDims = tpl.extend(`
201
222
  dimension: region is pick 'North' when region_code = 1 else 'South'
@@ -50,6 +50,12 @@ export declare function createLocalConnection(): Promise<Connection>;
50
50
  */
51
51
  export declare function getConnection(): Promise<Connection>;
52
52
  export declare function getConnectionType(): ConnectionType | null;
53
+ /**
54
+ * Inject a pre-built Malloy connection directly.
55
+ * Use this when you already have a configured Connection instance
56
+ * (e.g., a BigQueryConnection with in-memory credentials).
57
+ */
58
+ export declare function setConnection(conn: Connection, type: ConnectionType): void;
53
59
  export declare function listDatasets(): Promise<string[]>;
54
60
  export declare function listTables(dataset: string): Promise<{
55
61
  name: string;
@@ -80,4 +86,4 @@ export declare function executeMalloy(malloySource: string, options?: ExecuteOpt
80
86
  */
81
87
  export declare function executeSQL(sql: string): Promise<any[]>;
82
88
  export { Runtime };
83
- export type { DuckDBConnection, BigQueryConnection };
89
+ export type { Connection, DuckDBConnection, BigQueryConnection };
@@ -134,6 +134,16 @@ export function getConnectionType() {
134
134
  }
135
135
  return currentConnectionType;
136
136
  }
137
+ /**
138
+ * Inject a pre-built Malloy connection directly.
139
+ * Use this when you already have a configured Connection instance
140
+ * (e.g., a BigQueryConnection with in-memory credentials).
141
+ */
142
+ export function setConnection(conn, type) {
143
+ connectionInstance = conn;
144
+ currentConnectionType = type;
145
+ pendingOptions = null;
146
+ }
137
147
  // ---
138
148
  // SCHEMA EXPLORATION (BigQuery only)
139
149
  // ---