importer

package
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

generalized data importer

TODO

This package is part of a wider project, github.com/mutablelogic/go-sqlite. Please see the module documentation for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConfig = SQImportConfig{
		Header:     true,
		TrimSpace:  true,
		LazyQuotes: true,
	}
)

Functions

This section is empty.

Types

type Importer

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

func DefaultImporter

func DefaultImporter(url string, w SQImportWriter) (*Importer, error)

Create an importer with default configuation

func NewImporter

func NewImporter(c SQImportConfig, u string, w SQImportWriter) (*Importer, error)

Create a new importer with a database writer

func (*Importer) Decoder

func (this *Importer) Decoder(mimetype string) (SQImportDecoder, error)

Return a new decoder for the given mimetype, or guess the mimetype when opening the file

func (*Importer) Name

func (i *Importer) Name() string

func (*Importer) NewCSVDecoder

func (this *Importer) NewCSVDecoder(c io.Closer, r io.Reader, delimiter rune) (SQImportDecoder, error)

NewCSVDecoder returns a CSV decoder setting options

func (*Importer) NewXLSDecoder

func (this *Importer) NewXLSDecoder(r io.Reader) (SQImportDecoder, error)

NewXLSDecoder returns a XLS decoder setting options

func (*Importer) ReadWrite

func (i *Importer) ReadWrite(dec SQImportDecoder) error

Read a row from the source data and potentially insert into the table. On end of data, returns io.EOF.

func (*Importer) URL

func (i *Importer) URL() *url.URL

type SQImportWriter

type SQImportWriter interface {
	// Begin the writer process for a destination and return a writer callback
	Begin(name, schema string, cols []string) (SQImportWriterFunc, error)

	// End the transaction with success (true) or failure (false). On failure, rollback
	End(bool) error
}

SQImportWriter is an interface for writing decoded rows to a destination

type SQImportWriterFunc

type SQImportWriterFunc func([]interface{}) error

SQWriterFunc callback invoked for each row

type SQLWriter

type SQLWriter struct {
	*sqlite3.ConnEx
	// contains filtered or unexported fields
}

func NewSQLWriter

func NewSQLWriter(c SQImportConfig, db *sqlite3.ConnEx) (*SQLWriter, error)

func (*SQLWriter) Begin

func (w *SQLWriter) Begin(name, schema string, cols []string) (SQImportWriterFunc, error)

Begin a transaction, passing a writing function back to the caller

func (*SQLWriter) Count

func (w *SQLWriter) Count() int

func (*SQLWriter) End

func (w *SQLWriter) End(success bool) error

Jump to

Keyboard shortcuts

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