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.

Naming the operation:

By default an operation is named after its file: definitions/name.sqlx creates an operation called name. Set name in the config to override that. Other actions refer to it by the new name in dependencies, or with ref() if the operation sets hasOutput: true, since self() inside it then resolves to that name:

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

name works the same way next to filename in an action configs file. In the Javascript API the name is the first argument.

  • 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 Google Cloud project ID; for Postgres/Supabase targets this is the database name in workflow_settings.yaml.

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: Contextable‹IActionContext, string | string[]›): this

Sets the query/queries to generate the operation from.

Parameters:

NameType
queriesContextable‹IActionContext, 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