withddl

package
v0.15.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package withddl allows you to automatically ensure the tables against which you want to apply statements are up-to-date.

Index

Constants

View Source
const QueryToTriggerWithDDL = "SELECT _vt_no_such_column__init_schema FROM _vt.vreplication LIMIT 1"

Variables

This section is empty.

Functions

This section is empty.

Types

type WithDDL

type WithDDL struct {
	// contains filtered or unexported fields
}

WithDDL allows you to execute statements against tables whose schema may not be up-to-date. If the tables don't exist or result in a schema error, it can apply a series of idempotent DDLs that will create or bring the tables to the desired state and retry.

func New

func New(ddls []string) *WithDDL

New creates a new WithDDL.

func (*WithDDL) DDLs added in v0.11.0

func (wd *WithDDL) DDLs() []string

DDLs returns a copy of the ddls

func (*WithDDL) Exec

func (wd *WithDDL) Exec(ctx context.Context, query string, fQuery any, fDDL any) (*sqltypes.Result, error)

Exec executes the query using the supplied function. If there are any schema errors, it applies the DDLs and retries. It takes 2 functions, one to run the query and the other to run the DDL commands. This is generally needed so that different users can be used to run the commands. i.e. AllPrivs user for DDLs and App user for query commands. Funcs can be any of these types: func(query string) (*sqltypes.Result, error) func(query string, maxrows int) (*sqltypes.Result, error) func(query string, maxrows int, wantfields bool) (*sqltypes.Result, error) func(ctx context.Context, query string, maxrows int, wantfields bool) (*sqltypes.Result, error)

func (*WithDDL) ExecIgnore

func (wd *WithDDL) ExecIgnore(ctx context.Context, query string, f any) (*sqltypes.Result, error)

ExecIgnore executes the query using the supplied function. If there are any schema errors, it returns an empty result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL