Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StatementsToSchema ¶
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 ¶
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 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 ¶
NewTempSchema creates a temporary schema on the supplied instance and returns it as a Workspace.