@sqlanvil/cli 1.8.2 → 1.8.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.
Files changed (2) hide show
  1. package/bundle.js +54 -35
  2. package/package.json +2 -2
package/bundle.js CHANGED
@@ -43209,18 +43209,19 @@ class MysqlExecutionSql {
43209
43209
  publishTasks(table, runConfig, tableMetadata) {
43210
43210
  const tasks = new Tasks();
43211
43211
  const target = this.resolveTarget(table.target);
43212
+ this.preOps(table, runConfig, tableMetadata).forEach(task => tasks.add(task));
43212
43213
  if (table.enumType === sqlanvil.TableType.VIEW) {
43213
43214
  if (table.materialized) {
43214
43215
  tasks.add(Task.statement(this.dropIfExists(table.target, sqlanvil.TableMetadata.Type.VIEW)));
43215
43216
  tasks.add(Task.statement(this.dropIfExists(table.target, sqlanvil.TableMetadata.Type.TABLE)));
43216
43217
  tasks.add(Task.statement(`create table ${target}${this.tableOptions(table)} as ${table.query}`));
43217
43218
  this.createIndexes(table).forEach(stmt => tasks.add(Task.statement(stmt)));
43218
- return tasks;
43219
43219
  }
43220
- tasks.add(Task.statement(`create or replace view ${target} as ${table.query}`));
43221
- return tasks;
43220
+ else {
43221
+ tasks.add(Task.statement(`create or replace view ${target} as ${table.query}`));
43222
+ }
43222
43223
  }
43223
- if (table.enumType === sqlanvil.TableType.INCREMENTAL) {
43224
+ else if (table.enumType === sqlanvil.TableType.INCREMENTAL) {
43224
43225
  const fresh = !this.shouldWriteIncrementally(table, runConfig, tableMetadata);
43225
43226
  if (fresh) {
43226
43227
  tasks.add(Task.statement(this.dropIfExists(table.target, sqlanvil.TableMetadata.Type.TABLE)));
@@ -43235,13 +43236,33 @@ class MysqlExecutionSql {
43235
43236
  else {
43236
43237
  tasks.add(Task.statement(this.upsertInto(table, tableMetadata)));
43237
43238
  }
43238
- return tasks;
43239
43239
  }
43240
- tasks.add(Task.statement(this.dropIfExists(table.target, sqlanvil.TableMetadata.Type.TABLE)));
43241
- tasks.add(Task.statement(`create table ${target}${this.tableOptions(table)} as ${table.query}`));
43242
- this.createIndexes(table).forEach(stmt => tasks.add(Task.statement(stmt)));
43240
+ else {
43241
+ tasks.add(Task.statement(this.dropIfExists(table.target, sqlanvil.TableMetadata.Type.TABLE)));
43242
+ tasks.add(Task.statement(`create table ${target}${this.tableOptions(table)} as ${table.query}`));
43243
+ this.createIndexes(table).forEach(stmt => tasks.add(Task.statement(stmt)));
43244
+ }
43245
+ this.postOps(table, runConfig, tableMetadata).forEach(task => tasks.add(task));
43243
43246
  return tasks;
43244
43247
  }
43248
+ preOps(table, runConfig, tableMetadata) {
43249
+ let preOps = table.preOps;
43250
+ if (semver__namespace.gt(this.sqlanvilCoreVersion, "1.4.8") &&
43251
+ table.enumType === sqlanvil.TableType.INCREMENTAL &&
43252
+ this.shouldWriteIncrementally(table, runConfig, tableMetadata)) {
43253
+ preOps = table.incrementalPreOps;
43254
+ }
43255
+ return (preOps || []).map(pre => Task.statement(pre));
43256
+ }
43257
+ postOps(table, runConfig, tableMetadata) {
43258
+ let postOps = table.postOps;
43259
+ if (semver__namespace.gt(this.sqlanvilCoreVersion, "1.4.8") &&
43260
+ table.enumType === sqlanvil.TableType.INCREMENTAL &&
43261
+ this.shouldWriteIncrementally(table, runConfig, tableMetadata)) {
43262
+ postOps = table.incrementalPostOps;
43263
+ }
43264
+ return (postOps || []).map(post => Task.statement(post));
43265
+ }
43245
43266
  assertTasks(assertion, projectConfig) {
43246
43267
  const tasks = new Tasks();
43247
43268
  const target = this.resolveTarget(assertion.target);
@@ -43718,7 +43739,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
43718
43739
  .filter(validationQuery => !!validationQuery.query);
43719
43740
  }
43720
43741
 
43721
- const version = "1.8.2";
43742
+ const version = "1.8.3";
43722
43743
  const dataformVersion = "3.0.60";
43723
43744
 
43724
43745
  async function build(compiledGraph, runConfig, dbadapter) {
@@ -44450,47 +44471,45 @@ function buildCopySql(selectSql, uri, format, options = {}) {
44450
44471
  }
44451
44472
  function loadDuckdb() {
44452
44473
  try {
44453
- return nativeRequire("duckdb");
44474
+ return nativeRequire("@duckdb/node-api");
44454
44475
  }
44455
44476
  catch (e) {
44456
- throw new Error(`Exporting on Postgres/Supabase requires the optional "duckdb" dependency, which failed to ` +
44457
- `load: ${e.message}`);
44477
+ throw new Error(`Exporting on Postgres/Supabase requires the optional "@duckdb/node-api" dependency, which ` +
44478
+ `failed to load: ${e.message}`);
44458
44479
  }
44459
44480
  }
44460
- function allAsync(conn, sql) {
44461
- return new Promise((resolve, reject) => {
44462
- conn.all(sql, (err, rows) => (err ? reject(err) : resolve(rows || [])));
44463
- });
44481
+ async function runAsync(conn, sql) {
44482
+ await conn.run(sql);
44464
44483
  }
44465
- function withConnection(fn) {
44466
- const duckdb = loadDuckdb();
44467
- const db = new duckdb.Database(":memory:");
44468
- const conn = db.connect();
44484
+ async function withConnection(fn) {
44485
+ const { DuckDBInstance } = loadDuckdb();
44486
+ const instance = await DuckDBInstance.create(":memory:");
44487
+ const conn = await instance.connect();
44469
44488
  const done = () => {
44470
44489
  var _a, _b;
44471
44490
  try {
44472
- (_a = conn.close) === null || _a === void 0 ? void 0 : _a.call(conn);
44491
+ (_a = conn.closeSync) === null || _a === void 0 ? void 0 : _a.call(conn);
44473
44492
  }
44474
44493
  catch (e) {
44475
44494
  }
44476
44495
  try {
44477
- (_b = db.close) === null || _b === void 0 ? void 0 : _b.call(db);
44496
+ (_b = instance.closeSync) === null || _b === void 0 ? void 0 : _b.call(instance);
44478
44497
  }
44479
44498
  catch (e) {
44480
44499
  }
44481
44500
  };
44482
- const setup = !process.env.HOME
44483
- ? allAsync(conn, `SET home_directory='${os__namespace.tmpdir()}'`)
44484
- : Promise.resolve([]);
44485
- return setup
44486
- .then(() => fn(conn))
44487
- .then(result => {
44501
+ try {
44502
+ if (!process.env.HOME) {
44503
+ await runAsync(conn, `SET home_directory='${os__namespace.tmpdir()}'`);
44504
+ }
44505
+ const result = await fn(conn);
44488
44506
  done();
44489
44507
  return result;
44490
- }, err => {
44508
+ }
44509
+ catch (e) {
44491
44510
  done();
44492
- throw err;
44493
- });
44511
+ throw e;
44512
+ }
44494
44513
  }
44495
44514
  async function runDuckdbExport(args) {
44496
44515
  const { spec, selectSql, pg, storage, actionName } = args;
@@ -44501,15 +44520,15 @@ async function runDuckdbExport(args) {
44501
44520
  `export to ${uri}.`);
44502
44521
  }
44503
44522
  return withConnection(async (conn) => {
44504
- await allAsync(conn, "INSTALL postgres; LOAD postgres; INSTALL httpfs; LOAD httpfs;");
44505
- await allAsync(conn, buildAttachSql(pg));
44523
+ await runAsync(conn, "INSTALL postgres; LOAD postgres; INSTALL httpfs; LOAD httpfs;");
44524
+ await runAsync(conn, buildAttachSql(pg));
44506
44525
  if (scheme !== "local") {
44507
44526
  const secret = buildSecretSql(scheme, storage[scheme]);
44508
44527
  if (secret) {
44509
- await allAsync(conn, secret);
44528
+ await runAsync(conn, secret);
44510
44529
  }
44511
44530
  }
44512
- await allAsync(conn, buildCopySql(selectSql, uri, spec.format, spec.options || {}));
44531
+ await runAsync(conn, buildCopySql(selectSql, uri, spec.format, spec.options || {}));
44513
44532
  return { destination: toCopyTarget(uri) };
44514
44533
  });
44515
44534
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "dependencies": {
3
+ "@duckdb/node-api": "^1.5.4-r.1",
3
4
  "@google-cloud/bigquery": "~8.3.0",
4
5
  "chokidar": "^3.5.3",
5
6
  "deepmerge": "^4.2.2",
6
- "duckdb": "^1.4.0",
7
7
  "fs-extra": "^9.0.0",
8
8
  "glob": "13.0.6",
9
9
  "google-sql-syntax-ts": "^1.0.3",
@@ -63,7 +63,7 @@
63
63
  "bin": {
64
64
  "sqlanvil": "bundle.js"
65
65
  },
66
- "version": "1.8.2",
66
+ "version": "1.8.3",
67
67
  "name": "@sqlanvil/cli",
68
68
  "description": "sqlanvil command line interface.",
69
69
  "main": "bundle.js"