Skip to content

Operation

Operations define custom SQL operations that don’t fit into the sqlanvil model of publishing a table or writing an assertion.

You can create operations in the following ways. Available config options are defined in OperationConfig, and are shared across all the following ways of creating operations.

Using a SQLX file:

-- definitions/name.sqlx
config {
type: "operations"
}
DELETE FROM dataset.table WHERE country = 'GB'

Using action configs files:

definitions/actions.yaml
actions:
- operation:
filename: name.sql
-- definitions/name.sql
DELETE FROM dataset.table WHERE country = 'GB'

Using the Javascript API:

definitions/file.js
operate("name").query("DELETE FROM dataset.table WHERE country = 'GB'")

Note: When using the Javascript API, methods in this class can be accessed by the returned value. This is where query comes from.

  • ActionBuilder‹Operation›

    Operation

columns(columns: ColumnDescriptor[]): this

deprecated Deprecated in favor of OperationConfig.columns.

Sets the column descriptors of columns in this table.

Parameters:

NameType
columnsColumnDescriptor[]

Returns: this


database(database: string): this

deprecated Deprecated in favor of OperationConfig.project.

Sets the database in which to create the corresponding view for this operation. For BigQuery targets this is the GCP project ID; for Postgres/Supabase targets this is the database name.

Parameters:

NameType
databasestring

Returns: this


dependencies(value: Resolvable | Resolvable[]): this

deprecated Deprecated in favor of OperationConfig.dependencies.

Sets dependencies of the table.

Parameters:

NameType
valueResolvable | Resolvable[]

Returns: this


description(description: string): this

deprecated Deprecated in favor of OperationConfig.description.

Sets the description of this assertion.

Parameters:

NameType
descriptionstring

Returns: this


disabled(disabled: boolean): this

deprecated Deprecated in favor of OperationConfig.disabled.

If called with true, this action is not executed. The action can still be depended upon. Useful for temporarily turning off broken actions.

Parameters:

NameTypeDefault
disabledbooleantrue

Returns: this


hasOutput(hasOutput: boolean): this

deprecated Deprecated in favor of OperationConfig.hasOutput.

Declares that this action creates a dataset which should be referenceable as a dependency target, for example by using the ref function.

Parameters:

NameType
hasOutputboolean

Returns: this


hermetic(hermetic: boolean): void

deprecated Deprecated in favor of OperationConfig.hermetic.

If true, this indicates that the action only depends on data from explicitly-declared dependencies. Otherwise if false, it indicates that the action depends on data from a source which has not been declared as a dependency.

Parameters:

NameType
hermeticboolean

Returns: void


queries(queries: ContextableIActionContext, string | string[]›): this

Sets the query/queries to generate the operation from.

Parameters:

NameType
queriesContextableIActionContext, string | string[]›

Returns: this


schema(schema: string): this

deprecated Deprecated in favor of OperationConfig.dataset.

Sets the schema (BigQuery dataset / Postgres schema) in which to create the output of this action.

Parameters:

NameType
schemastring

Returns: this


setDependOnDependencyAssertions(dependOnDependencyAssertions: boolean): this

deprecated Deprecated in favor of OperationConfig.dependOnDependencyAssertions.

When called with true, assertions dependent upon any dependency will be add as dedpendency to this action.

Parameters:

NameType
dependOnDependencyAssertionsboolean

Returns: this


tags(value: string | string[]): this

deprecated Deprecated in favor of OperationConfig.tags.

Sets a list of user-defined tags applied to this action.

Parameters:

NameType
valuestring | string[]

Returns: this