How to use the @dataform/core/utils.baseFilename function in @dataform/core

To help you get started, we’ve selected a few @dataform/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dataform-co / dataform / core / compilers.ts View on Github external
function compileSqlx(results: ISqlxParseResults, path: string, defaultSchema: string) {
  const resConfig =
    results.config != null
      ? JSON.parse(results.config.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": '))
      : null;
  const queryConfigSchema = "schema" in resConfig && resConfig != null ? resConfig.schema : null;
  const fQName = [queryConfigSchema || defaultSchema, utils.baseFilename(path)].join(".");
  return `
const parsedConfig = ${results.config || "{}"};
// sqlxConfig should conform to the ISqlxConfig interface.
const sqlxConfig = {
  name: "${fQName}",
  type: "operations",
  dependencies: [],
  tags: [],
  ...parsedConfig
};

const sqlStatementCount = ${results.sql.length};
const hasIncremental = ${!!results.incremental};
const hasPreOperations = ${results.preOperations.length > 1 || results.preOperations[0] !== ""};
const hasPostOperations = ${results.postOperations.length > 1 || results.postOperations[0] !== ""};
const hasInputs = ${Object.keys(results.input).length > 0};
github dataform-co / dataform / core / compilers.ts View on Github external
function compileSqlx(results: ISqlxParseResults, path: string) {
  return `
const parsedConfig = ${results.config || "{}"};
// sqlxConfig should conform to the ISqlxConfig interface.
const sqlxConfig = {
  name: "${utils.baseFilename(path)}",
  type: "operations",
  dependencies: [],
  tags: [],
  ...parsedConfig
};

const sqlStatementCount = ${results.sql.length};
const hasIncremental = ${!!results.incremental};
const hasPreOperations = ${results.preOperations.length > 1 || results.preOperations[0] !== ""};
const hasPostOperations = ${results.postOperations.length > 1 || results.postOperations[0] !== ""};
const hasInputs = ${Object.keys(results.input).length > 0};

const action = session.sqlxAction({
  sqlxConfig,
  sqlStatementCount,
  hasIncremental,
github dataform-co / dataform / api / vm / legacy_gen_index.ts View on Github external
.map(path => {
      return `
      try { global.${utils.baseFilename(path)} = require("./${path}"); } catch (e) {
        if (global.session.compileError) {
          global.session.compileError(e, "${path}");
        } else {
          console.error('Error:', e.message, 'Path: "${path}"');
        }
      }`;
    })
    .join("\n");
github dataform-co / dataform / core / gen_index.ts View on Github external
.map(path => {
      return `
      try { global.${utils.baseFilename(path)} = require("./${path}"); } catch (e) {
        if (global.session.compileError) {
          global.session.compileError(e, "${path}");
        } else {
          console.error('Error:', e.message, 'Path: "${path}"');
        }
      }`;
    })
    .join("\n");
github dataform-co / dataform / core / compilers.ts View on Github external
function compileOperationSql(code: string, path: string) {
  const { sql, js } = extractJsBlocks(code);
  const functionsBindings = getFunctionPropertyNames(OperationContext.prototype).map(
    name => `const ${name} = ctx.${name}.bind(ctx);`
  );

  return `
  operate("${utils.baseFilename(path)}").queries(ctx => {
    ${functionsBindings.join("\n")}
    ${js}
    return \`${sql}\`.split("\\n---\\n");
  })`;
}
github dataform-co / dataform / core / compilers.ts View on Github external
function compileTableSql(code: string, path: string) {
  const { sql, js } = extractJsBlocks(code);
  const functionsBindings = getFunctionPropertyNames(TableContext.prototype).map(
    name => `const ${name} = ${safelyBindCtxFunction(name)};`
  );

  return `
  publish("${utils.baseFilename(path)}").query(ctx => {
    ${functionsBindings.join("\n")}
    ${js}
    return \`${sql}\`;
  })`;
}
github dataform-co / dataform / core / compilers.ts View on Github external
function compileAssertionSql(code: string, path: string) {
  const { sql, js } = extractJsBlocks(code);
  const functionsBindings = getFunctionPropertyNames(AssertionContext.prototype).map(
    name => `const ${name} = ${safelyBindCtxFunction(name)};`
  );

  return `
  assert("${utils.baseFilename(path)}").query(ctx => {
    ${functionsBindings.join("\n")}
    ${js}
    return \`${sql}\`;
  })`;
}
github dataform-co / dataform / core / compilers.ts View on Github external
function compileAssertionSql(code: string, path: string) {
  const { sql, js } = extractJsBlocks(code);
  const functionsBindings = getFunctionPropertyNames(AssertionContext.prototype).map(
    name => `const ${name} = ctx.${name}.bind(ctx);`
  );

  return `
  assert("${utils.baseFilename(path)}").query(ctx => {
    ${functionsBindings.join("\n")}
    ${js}
    return \`${sql}\`;
  })`;
}
github dataform-co / dataform / core / compilers.ts View on Github external
function compileTableSql(code: string, path: string) {
  const { sql, js } = extractJsBlocks(code);
  const functionsBindings = getFunctionPropertyNames(TableContext.prototype).map(
    name => `const ${name} = ctx.${name}.bind(ctx);`
  );

  return `
  publish("${utils.baseFilename(path)}").query(ctx => {
    ${functionsBindings.join("\n")}
    ${js}
    return \`${sql}\`;
  })`;
}