MCPcopy Create free account
hub / github.com/dataform-co/dataform / sqlxAction

Method sqlxAction

core/session.ts:120–247  ·  view source on GitHub ↗
(actionOptions: {
    // sqlxConfig has type any here because any object can be passed in from the compiler - the
    // structure of it is verified at later steps.
    sqlxConfig: any;
    sqlStatementCount: number;
    sqlContextable: (
      ctx:
        | TableContext
        | AssertionContext
        | OperationContext
        | DataPreparationContext
        | IActionContext
    ) => string[];
    incrementalWhereContextable: (ctx: ITableContext) => string;
    preOperationsContextable: (ctx: ITableContext) => string[];
    postOperationsContextable: (ctx: ITableContext) => string[];
    inputContextables: [
      {
        refName: string[];
        contextable: (ctx: IActionContext) => string;
      }
    ];
  })

Source from the content-addressed store, hash-verified

118 }
119
120 public sqlxAction(actionOptions: {
121 // sqlxConfig has type any here because any object can be passed in from the compiler - the
122 // structure of it is verified at later steps.
123 sqlxConfig: any;
124 sqlStatementCount: number;
125 sqlContextable: (
126 ctx:
127 | TableContext
128 | AssertionContext
129 | OperationContext
130 | DataPreparationContext
131 | IActionContext
132 ) => string[];
133 incrementalWhereContextable: (ctx: ITableContext) => string;
134 preOperationsContextable: (ctx: ITableContext) => string[];
135 postOperationsContextable: (ctx: ITableContext) => string[];
136 inputContextables: [
137 {
138 refName: string[];
139 contextable: (ctx: IActionContext) => string;
140 }
141 ];
142 }) {
143 const { sqlxConfig } = actionOptions;
144 const actionType = sqlxConfig.hasOwnProperty("type") ? sqlxConfig.type : "operations";
145 if (actionOptions.sqlStatementCount > 1 && actionType !== "operations") {
146 this.compileError(
147 "Actions may only contain more than one SQL statement if they are of type 'operations'."
148 );
149 }
150 if (sqlxConfig.hasOwnProperty("protected") && actionType !== "incremental") {
151 this.compileError(
152 "Actions may only specify 'protected: true' if they are of type 'incremental'."
153 );
154 }
155 if (actionOptions.incrementalWhereContextable && actionType !== "incremental") {
156 this.compileError(
157 "Actions may only include incremental_where if they are of type 'incremental'."
158 );
159 }
160 if (actionOptions.inputContextables.length > 0 && actionType !== "test") {
161 this.compileError("Actions may only include input blocks if they are of type 'test'.");
162 }
163 if (actionOptions.preOperationsContextable && !definesDataset(actionType)) {
164 this.compileError("Actions may only include pre_operations if they create a dataset.");
165 }
166 if (actionOptions.postOperationsContextable && !definesDataset(actionType)) {
167 this.compileError("Actions may only include post_operations if they create a dataset.");
168 }
169
170 if (!sqlxConfig.filename) {
171 sqlxConfig.filename = utils.getCallerFile(this.rootDir);
172 }
173
174 switch (actionType) {
175 case "view":
176 const view = new View(this, sqlxConfig).query(ctx => actionOptions.sqlContextable(ctx)[0]);
177 if (actionOptions.incrementalWhereContextable) {

Callers

nothing calls this directly

Calls 12

compileErrorMethod · 0.95
testMethod · 0.95
definesDatasetFunction · 0.85
queriesMethod · 0.80
expectMethod · 0.80
inputMethod · 0.80
queryMethod · 0.45
whereMethod · 0.45
preOpsMethod · 0.45
postOpsMethod · 0.45
pushMethod · 0.45
configMethod · 0.45

Tested by

no test coverage detected