Documentation
¶
Overview ¶
Package export implements mechanisms to subsets of data, from one database to another. Note that it only supports auto-incrementing (single) primary/foreign keys, which must fit in int64.
Index ¶
- Constants
- Variables
- type Dialect
- type Exporter
- type InsertRows
- type JoinRef
- type Mapper
- type Reader
- type ReaderImpl
- type Result
- type Row
- type RowTransformer
- type Rows
- type Schema
- type SelectBatch
- type SelectRows
- type SimpleMapper
- type Snippet
- type Table
- type Target
- type Template
- type UnimplementedDialect
- type Writer
- type WriterImpl
Constants ¶
const (
DefaultBatchSize = 1000
)
Variables ¶
var (
ErrUnimplemented = errors.New(`go-sql/export: unimplemented`)
)
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect interface {
SelectBatch(args *SelectBatch) (*Snippet, error)
SelectRows(args *SelectRows) (*Snippet, error)
InsertRows(args *InsertRows) (*Snippet, error)
// contains filtered or unexported methods
}
Dialect models an SQL dialect. Note that all methods should return (nil, nil) or (nil, ErrUnimplemented) if args is nil. See also UnimplementedDialect.
type Exporter ¶
type Exporter struct {
Reader Reader
Writer Writer
// Mapper maps old ids to new ids.
Mapper Mapper
// RowTransformer may be provided as a hook to modify rows before they are inserted.
RowTransformer RowTransformer
Schema *Schema
Logger *logiface.Logger[logiface.Event]
// Offset provides an initial offset, to start querying from.
Offset map[string]int64
// Filters further restrict the target data set.
Filters []*Snippet
// BatchSize configures the max limit, and defaults to DefaultBatchSize if 0.
BatchSize int
// MaxSelectIn configures the maximum number of IDs to "SELECT ... WHERE <id> in (...<values>)".
// If zero it defaults to the (resolved) batch size.
MaxSelectIn int
// MaxOffsetConditions configures the maximum number of offsets columns to support.
// Default is unlimited.
MaxOffsetConditions int
}
type InsertRows ¶
type JoinRef ¶
type JoinRef struct {
// Alias represents the joined table.
Alias string
// Column is the column name, in ONE OF Alias's table OR the parent Target's table, depending on Reverse.
Column string
// Reverse is set to true to indicate that Column belongs to the parent Target, rather than Alias.
Reverse bool
}
JoinRef models part of an expression like "JOIN table b ON a.b_id = b._id" OR "JOIN table a ON a.b_id = b._id".
type ReaderImpl ¶
type RowTransformer ¶
type Schema ¶
type Schema struct {
Template *Template
PrimaryKeys map[Table]string
ForeignKeys map[Table]map[string]Table
Dependencies map[Table][]Table
// AliasOrder contains each key from Template.Targets, sorted by Target.Order + string sort.
// Target.Order is in descending order (larger number first), and is higher priority than the string sort.
// It is to be used control evaluation of the "offset" conditions in the SelectBatch WHERE clause, which, by
// nature, must align with specific ORDER BY expressions.
AliasOrder []string
}
Schema defines the structure of the data to be exported, and may be initialised via Template.Schema.
type SelectBatch ¶
type SelectRows ¶
type SimpleMapper ¶
type Table ¶
func (Table) MarshalJSON ¶
func (Table) MarshalText ¶
func (*Table) UnmarshalJSON ¶
func (*Table) UnmarshalText ¶
type Target ¶
type Target struct {
// ForeignKey is optional, and models the join condition for this Target.
ForeignKey *JoinRef
Table Table
// PrimaryKey is the column of the table's primary key. It's after SELECT and (in some cases) ON.
PrimaryKey string
// Order is used to indicate the order of the predicates (expressions in WHERE and ORDER BY).
// Larger numbers should appear first.
Order int
}
type Template ¶
type Template struct {
// Targets are all joined tables with alias (can include the same table more than once).
Targets map[string]*Target
// Filters are SQL snippets to AND together in groups, to filter the batch data set.
Filters []*Snippet
}
Template is the input used to generate a Schema, and is based on a query in the format of "SELECT [<pk> as <alias> ...] {FROM/JOIN} [WHERE] [ORDER BY ...]", where Targets are joined tables.
type UnimplementedDialect ¶
type UnimplementedDialect struct{}
func (UnimplementedDialect) InsertRows ¶
func (UnimplementedDialect) InsertRows(*InsertRows) (*Snippet, error)
func (UnimplementedDialect) SelectBatch ¶
func (UnimplementedDialect) SelectBatch(*SelectBatch) (*Snippet, error)
func (UnimplementedDialect) SelectRows ¶
func (UnimplementedDialect) SelectRows(*SelectRows) (*Snippet, error)