How to use the @dataform/core/session.Session 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 / tests / core / core.spec.ts View on Github external
it("validation_type", () => {
      const sessionSuccess = new Session(path.dirname(__filename), TEST_CONFIG);
      sessionSuccess.publish("exampleSuccess1", { type: "table" });
      sessionSuccess.publish("exampleSuccess2", { type: "view" });
      sessionSuccess.publish("exampleSuccess3", { type: "incremental" }).where("test");
      const cgSuccess = sessionSuccess.compile();
      const cgSuccessErrors = utils.validate(cgSuccess);

      expect(cgSuccessErrors)
        .to.have.property("validationErrors")
        .to.be.an("array").that.is.empty;

      const sessionFail = new Session(path.dirname(__filename), TEST_CONFIG);
      sessionFail.publish("exampleFail", JSON.parse('{"type": "ta ble"}'));
      const cgFail = sessionFail.compile();
      const cgFailErrors = utils.validate(cgFail);

      expect(cgFailErrors)
        .to.have.property("validationErrors")
        .to.be.an("array").that.is.not.empty;

      const err = cgFailErrors.validationErrors.find(e => e.actionName === "schema.exampleFail");
      expect(err)
        .to.have.property("message")
        .that.matches(/Wrong type of table/);
    });
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("incremental table", () => {
      const session = new Session(path.dirname(__filename), TEST_CONFIG);
      session
        .publish("incremental", {
          type: "incremental"
        })
        .query(ctx => `select ${ctx.isIncremental()} as incremental`);
      const graph = session.compile();

      expect(graph.toJSON().tables).deep.equals([
        {
          target: {
            name: "incremental",
            schema: TEST_CONFIG.defaultSchema
          },
          query: "select false as incremental",
          incrementalQuery: "select true as incremental",
          disabled: false,
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("missing_dependency", () => {
      const session = new Session(path.dirname(__filename), TEST_CONFIG);
      session.publish("a", ctx => `select * from ${ctx.ref("b")}`);
      const cGraph = session.compile();
      const gErrors = utils.validate(cGraph);
      expect(gErrors)
        .to.have.property("compilationErrors")
        .to.be.an("array").that.is.not.empty;
      expect(
        gErrors.compilationErrors.filter(item => item.message.match(/Missing dependency/))
      ).to.be.an("array").that.is.not.empty;
    });
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("validation_type_incremental", () => {
      const sessionSuccess = new Session(path.dirname(__filename), TEST_CONFIG);
      sessionSuccess
        .publish("exampleSuccess1", {
          type: "incremental"
        })
        .where("test1");
      sessionSuccess.publish(
        "exampleSuccess2",
        ctx => `
        ${ctx.where("test2")}
        ${ctx.type("incremental")}
        select field as 1
      `
      );
      sessionSuccess.publish(
        "exampleSuccess3",
        ctx => `
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("ref", () => {
      const session = new Session(path.dirname(__filename), TEST_CONFIG);
      session.publish("a", _ => "select 1 as test");
      session.publish("b", ctx => `select * from ${ctx.ref("a")}`);
      session.publish("c", ctx => `select * from ${ctx.ref(undefined)}`);
      session.publish("d", ctx => `select * from ${ctx.ref({ schema: "schema", name: "a" })}`);
      session
        .publish("e", {
          schema: "foo"
        })
        .query(_ => "select 1 as test");
      session.publish("f", ctx => `select * from ${ctx.ref("e")}`);

      const graph = session.compile();
      const graphErrors = utils.validate(graph);

      const tableNames = graph.tables.map(item => item.name);
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("ref", () => {
      const session = new Session(path.dirname(__filename), TEST_CONFIG);
      session.operate("operate-1", () => `select 1 as sample`).hasOutput(true);
      session.operate("operate-2", ctx => `select * from ${ctx.ref("operate-1")}`).hasOutput(true);

      const graph = session.compile();
      const gErrors = utils.validate(graph);

      expect(gErrors)
        .to.have.property("compilationErrors")
        .to.be.an("array").that.is.empty;
      expect(gErrors)
        .to.have.property("validationErrors")
        .to.be.an("array").that.is.empty;
      expect(graph)
        .to.have.property("operations")
        .to.be.an("array")
        .to.have.lengthOf(2);
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it("config_context", () => {
      const session = new Session(path.dirname(__filename), TEST_CONFIG);
      const t = session
        .publish(
          "example",
          ctx => `
          ${ctx.type("table")}
          ${ctx.preOps(["pre_op"])}
          ${ctx.postOps(["post_op"])}
        `
        )
        .compile();

      expect(t.name).equals("schema.example");
      expect(t.type).equals("table");
      expect(t.preOps).deep.equals(["pre_op"]);
      expect(t.postOps).deep.equals(["post_op"]);
    });
github dataform-co / dataform / tests / core / core.spec.ts View on Github external
it(`config with suffix "${testConfig.schemaSuffix}"`, () => {
        const schemaWithSuffix = (schema: string) =>
          testConfig.schemaSuffix ? `${schema}_${testConfig.schemaSuffix}` : schema;
        const session = new Session(path.dirname(__filename), testConfig);
        session
          .publish("example", {
            type: "table",
            dependencies: [],
            description: "this is a table",
            columns: {
              test: "test description"
            }
          })
          .query(_ => "select 1 as test")
          .preOps(_ => ["pre_op"])
          .postOps(_ => ["post_op"]);
        session
          .publish("example", {
            type: "table",
            schema: "schema2",
github dataform-co / dataform / core / index.ts View on Github external
function globalSession() {
  if (!(global as any)._DF_SESSION) {
    (global as any)._DF_SESSION = new Session(process.cwd());
  }
  return (global as any)._DF_SESSION as Session;
}
const session = globalSession();