workspace

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatementsToSchema

func StatementsToSchema(statements []string, opts Options) (*tengo.Schema, error)

StatementsToSchema serially executes the supplied statements in a temporary workspace, and then returns the introspected schema. Errors are not tracked on a per-statement basis; the returned error value will be nil only if all statements succeeded. If multiple statements returned an error, the return value here will be from the first such erroring statement.

Types

type Options

type Options struct {
	Type                Type
	Instance            *tengo.Instance // only TypeTempSchema
	Flavor              tengo.Flavor    // only TypeLocalDocker
	SchemaName          string
	KeepSchema          bool // only TypeTempSchema
	DefaultCharacterSet string
	DefaultCollation    string
	LockWaitTimeout     time.Duration
}

Options represent different parameters controlling the workspace that is used. Some options are specific to a Type.

type TableError

type TableError struct {
	TableName string
	Err       error
}

TableError represents a problem that occurred when attempting to create a table in a workspace.

func MaterializeIdealSchema

func MaterializeIdealSchema(idealSchema *fs.IdealSchema, opts Options) (schema *tengo.Schema, tableErrors []TableError, fatalErr error)

MaterializeIdealSchema converts an IdealSchema to a tengo.Schema. It obtains a Workspace, executes the creation DDL contained in an IdealSchema there, introspects it into a *tengo.Schema, cleans up the Workspace, and then returns the introspected schema. SQL errors (tables that could not be created) are non-fatal, and are returned in the second return value. The third return value represents fatal errors only.

func (TableError) Error

func (te TableError) Error() string

Error satisfies the builtin error interface.

type TempSchema

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

TempSchema is a Workspace that exists as a schema that is created on another database instance. The schema is cleaned up when done interacting with the workspace.

func (*TempSchema) Cleanup

func (ts *TempSchema) Cleanup() error

Cleanup either drops the temporary schema (if not using reuse-temp-schema) or just drops all tables in the schema (if using reuse-temp-schema). If any tables have any rows in the temp schema, the cleanup aborts and an error is returned.

func (*TempSchema) ConnectionPool

func (ts *TempSchema) ConnectionPool(params string) (*sqlx.DB, error)

ConnectionPool returns a connection pool (*sqlx.DB) to the temporary workspace schema, using the supplied connection params (which may be blank).

func (*TempSchema) IntrospectSchema

func (ts *TempSchema) IntrospectSchema() (*tengo.Schema, error)

IntrospectSchema introspects and returns the temporary workspace schema.

type Type

type Type int

Type represents a type of workspace provider to use.

const (
	TypeTempSchema  Type = iota
	TypeLocalDocker      // not implemented yet
)

Constants enumerating different types of workspaces

type Workspace

type Workspace interface {
	// ConnectionPool returns a *sqlx.DB representing a connection pool for
	// interacting with the workspace. The pool should already be using the
	// correct default database for interacting with the workspace schema.
	ConnectionPool(params string) (*sqlx.DB, error)

	// IntrospectSchema returns a *tengo.Schema representing the current state
	// of the workspace schema.
	IntrospectSchema() (*tengo.Schema, error)

	// Cleanup cleans up the workspace, leaving it in a state where it could be
	// re-used/re-initialized as needed. Repeated calls to Cleanup() may error.
	Cleanup() error
}

Workspace represents a "scratch space" for DDL operations and schema introspection.

func NewTempSchema

func NewTempSchema(opts Options) (ws Workspace, err error)

NewTempSchema creates a temporary schema on the supplied instance and returns it as a Workspace.

Jump to

Keyboard shortcuts

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