dbutil

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpenRedshiftDB = OpenPostgresDB

Functions

func BuildConditions

func BuildConditions(equal map[string]interface{}, in map[string]interface{}) ([]string, []interface{}, error)

func BuildIndexDDL added in v0.0.4

func BuildIndexDDL(tableName string, indexName string, fields []string, backend types.BackendType) string

func BuildTableSchema added in v0.0.4

func BuildTableSchema(
	tableName string,
	entity *types.Entity,
	isCDC bool,
	features types.FeatureList,
	pkFields []string,
	backend types.BackendType,
) string

func DBValueType added in v0.0.4

func DBValueType(backend types.BackendType, valueType types.ValueType) (string, error)

func DeserializeString added in v0.0.4

func DeserializeString(i interface{}, backend types.BackendType) string

func Fill added in v0.0.4

func Fill(size int, elem string, sep string) string

func GetColumnFormat added in v0.0.4

func GetColumnFormat(backendType types.BackendType) (string, error)

func InsertRecordsToTable added in v0.0.2

func InsertRecordsToTable(ctx context.Context, dbOpt DBOpt, tableName string, records []interface{}, columns []string) error

func InsertRecordsToTableTx added in v0.0.2

func InsertRecordsToTableTx(tx *sqlx.Tx, ctx context.Context, tableName string, records []interface{}, columns []string, backendType types.BackendType) error

func IsTableNotFoundError added in v0.0.4

func IsTableNotFoundError(err error, backend types.BackendType) bool

TODO: Should return an error when bakcend is not supported ?

func LoadDataFromSource added in v0.0.4

func LoadDataFromSource(backendType types.BackendType, batchSize int) func(tx *sqlx.Tx, ctx context.Context, source *offline.CSVSource, tableName string, header []string, features types.FeatureList) error

Currying

func OfflineBatchTableName added in v0.0.4

func OfflineBatchTableName(groupID int, revisionID int64) string

func OfflineStreamCdcTableName added in v0.0.4

func OfflineStreamCdcTableName(groupID int, revision int64) string

func OfflineStreamSnapshotTableName added in v0.0.4

func OfflineStreamSnapshotTableName(groupID int, revision int64) string

func OpenMysqlDB added in v0.0.4

func OpenMysqlDB(host, port, user, password, database string) (*sqlx.DB, error)

func OpenPostgresDB added in v0.0.4

func OpenPostgresDB(host, port, user, password, database string) (*sqlx.DB, error)

func OpenSQLite added in v0.0.4

func OpenSQLite(dbFile string) (*sqlx.DB, error)

func QuoteFn added in v0.0.4

func QuoteFn(backendType types.BackendType) func(...string) string

func RandString added in v0.0.4

func RandString(n int) string

func ReadLine added in v0.0.4

func ReadLine(reader *bufio.Reader, delimiter string, features types.FeatureList, backend types.BackendType) ([]interface{}, error)

func TempTable added in v0.0.2

func TempTable(prefix string) string

func ValueType added in v0.0.4

func ValueType(backend types.BackendType, dbValueType string) (types.ValueType, error)

Used for inferring feature value type from a supported offline db value type

func WithTransaction

func WithTransaction(db *sqlx.DB, ctx context.Context, fn TxFn) (err error)

Types

type Column added in v0.0.4

type Column struct {
	Name      string
	DbType    string
	ValueType types.ValueType
}

type ColumnList added in v0.0.4

type ColumnList []Column

func (ColumnList) Names added in v0.0.4

func (c ColumnList) Names() []string

type DBOpt added in v0.0.4

type DBOpt struct {
	Backend types.BackendType

	// Sqlx
	SqlxDB *sqlx.DB

	// BigQuery
	BigQueryDB *bigquery.Client
	DatasetID  *string
}

func (*DBOpt) BuildInsertQuery added in v0.0.4

func (d *DBOpt) BuildInsertQuery(tableName string, records []interface{}, columns []string) (string, []interface{}, error)

func (*DBOpt) ExecContext added in v0.0.4

func (d *DBOpt) ExecContext(ctx context.Context, query string, args []interface{}) error

type RowMap

type RowMap = map[string]interface{}

type TxFn

type TxFn func(ctx context.Context, tx *sqlx.Tx) error

A Txfn is a function that will be called with an initialized `Transaction` object that can be used for executing statements and queries against a database.

Jump to

Keyboard shortcuts

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