mysqltsv

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

README

mysqltsv

A simple Go library to encode values into a TSV file (tab separated values) for MySQL's LOAD DATA INFILE.

More information can be found at https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-field-line-handling

Character sets

Characters sets are the worst. Make sure to verify your data is loaded correctly before relying on this not to corrupt your data.

Documentation

Overview

Package mysqltsv encodes values for usage in LOAD DATA INFILE's tab separated values.

Index

Constants

View Source
const Escaping = `` /* 129-byte string literal not displayed */

Escaping explains the escaping this package uses for inclusion in a LOAD DATA INFILE statement.

Variables

This section is empty.

Functions

func EscapeValue

func EscapeValue(v any, cfg *EncoderOptions) ([]byte, error)

EscapeValue escapes a value for use in a MySQL CSV. It's escaped as shown in the constant Escaping. EncoderOptions is optional.

Types

type Encoder

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

Encoder encodes values into a CSV file suitable for consumption by LOAD DATA INFILE. The number of columns per row must be fixed, and it will automatically advance to the next row once all columns were appended. Any errors during appending will be stored and future calls will be ignored. The encoder must be Close()d once done to flush and to read any errors that might have occurred.

func NewEncoder

func NewEncoder(w io.Writer, numColumns int, cfg *EncoderOptions) *Encoder

NewEncoder starts a new encoder. You should write the same number of columns per line and the Encoder will decide when a row is finished. Close must be called to see if any error occurred. EncoderOptions is optional.

func (*Encoder) AppendBytes

func (e *Encoder) AppendBytes(b []byte)

func (*Encoder) AppendString

func (e *Encoder) AppendString(s string)

func (*Encoder) AppendValue

func (e *Encoder) AppendValue(v any)

func (*Encoder) Close

func (e *Encoder) Close() error

func (*Encoder) Error

func (e *Encoder) Error() error

type EncoderOptions

type EncoderOptions struct {
	// Location is the timezone each time.Time will be converted to before being serialized.
	Location *time.Location
}

EncoderOptions are settings that affect encoding.

Jump to

Keyboard shortcuts

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