etlsql

package
v0.0.18-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnGoTypeDef

func ColumnGoTypeDef(ct *sql.ColumnType) (reflect.Type, error)

func WithBatchSize

func WithBatchSize(n int) insertOptFunc

WithBatchSize sets the number of rows to insert in a single batch. might still execute multiple inserts.

func WithDDLSync

func WithDDLSync(ddlSync DDLSync) insertOptFunc

WithDDLSync sets the DDL sync mode.

func WithNullables

func WithNullables(nullables ...string) insertOptFunc

WithNullables sets the columns that can be null.

func WithTypeOverride

func WithTypeOverride(fn func(t ColDef) string) insertOptFunc

WithTypeOverride uses the sql type returned by the func for col if the func returns an empty string, the default type is used.

Types

type ColDef

type ColDef struct {
	Name string
	// Type     reflect.Type // RAW? ScanType
	Type     Type
	Nullable bool
	Length   int64 // for varchar and maybe other types
	Scale    int   // Precision int ...
	// Overrides for sql types
	SQLType string // override
}

ColDef represets a column in a table

func (ColDef) Eq

func (c ColDef) Eq(c2 ColDef) bool

Eq compares two columns by name and type.

func (ColDef) Zero

func (c ColDef) Zero() any

Zero returns the zero value for the column type.

type DB

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

func New

func New(d Dialect, db Q) DB

New returns a new DB iterator with the given dialect and database.

func Open

func Open(d Dialect, driver, dsn string) DB

Open opens a DB connection similar to sql.Open and returns a db Iterator.

func (DB) Err

func (d DB) Err() error

func (DB) Insert

func (d DB) Insert(it Iter, schema, table string, opts ...insertOptFunc) error

func (DB) Q

func (d DB) Q() Q

func (DB) Query

func (d DB) Query(query string, args ...any) Iter

Query executes the given query and returns an iterator that produces drow.Row.

func (DB) String

func (d DB) String() string

type DDLSync

type DDLSync int
const (
	DDLNone DDLSync = iota
	DDLCreate
	DDLAddColumns
)

type Dialect

type Dialect interface {
	ColumnGoType(ct *sql.ColumnType) (reflect.Type, error)
	TableDef(ctx context.Context, db SQLQuery, schema, name string) (TableDef, error)
	CreateTable(ctx context.Context, db SQLExec, schema, name string, table TableDef) error
	AddColumns(ctx context.Context, db SQLExec, schema, name string, table TableDef) error
	Insert(ctx context.Context, db SQLExec, schema, name string, table TableDef, rows []Row) error
}

type Iter

type Iter = etl.Iter

type Q

type Q interface {
	SQLQuery
	SQLExec
	Begin() (*sql.Tx, error)
}

type Row

type Row = drow.Row

type SQLExec

type SQLExec interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

type SQLQuery

type SQLQuery interface {
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

type TableDef

type TableDef struct {
	Columns []ColDef
}

TableDef represents an sql table definition.

func DefFromIterRows

func DefFromIterRows(it etl.Iter) (TableDef, error)

func DefFromRows

func DefFromRows(rows []Row) (TableDef, error)

DefFromRows scans a slice of rows and returns a TableDef with the columns.

func DefFromSQLTypes

func DefFromSQLTypes(typs []*sql.ColumnType, solverOpt ...sqlTypeSolver) (TableDef, error)

func NewTableDef

func NewTableDef(cols ...ColDef) TableDef

func (TableDef) Get

func (d TableDef) Get(colName string) (ColDef, bool)

Get returns the column with the given name or an empty col if non existent.

func (TableDef) IndexOf

func (d TableDef) IndexOf(k string) int

func (TableDef) Len

func (d TableDef) Len() int

Len returns the number of columns in the table.

func (TableDef) MissingOn

func (d TableDef) MissingOn(d2 TableDef) TableDef

MissingOn returns a TableDef with missing columns from d2

func (TableDef) NormalizeRows

func (d TableDef) NormalizeRows(rows []Row) []Row

NormalizeRows returns a slice of rows based on definition d.

func (TableDef) RowValues

func (d TableDef) RowValues(rows []Row) []any

RowValues returns a slice of values from the given rows. |row1|row2|row3| => |row1[0]|row1[1]|row2[0]|row2[1]|row3[0]|row3[1]|

func (TableDef) StrJoin

func (d TableDef) StrJoin(sep string) string

StrJoin returns a string with all column names joined by sep.

func (TableDef) String

func (d TableDef) String() string

func (TableDef) WithColumns

func (d TableDef) WithColumns(col ...ColDef) TableDef

type Type

type Type int
const (
	TypeUnknown          Type = iota
	TypeSmallInt              // int8
	TypeUnsignedSmallInt      // uint8
	TypeInteger               // int32
	TypeUnsignedInteger       // uint32
	TypeBigInt                // int64
	TypeUnsignedBigInt        // uint64
	TypeDecimal               // apd.Decimal
	TypeReal                  // float32
	TypeDouble                // float64
	TypeVarchar               // string
	TypeTimestamp             // time.Time
	TypeBoolean               // bool

)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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