dbutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MYSQL_NO_SUCH_TABLE = 1146
)

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(params BuildTableSchemaParams) string

func DBValueType added in v0.0.4

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

func DeserializeByValueType added in v0.1.0

func DeserializeByValueType(i interface{}, valueType types.ValueType, backend types.BackendType) (interface{}, error)

func DropTable added in v0.1.0

func DropTable(ctx context.Context, dbOpt DBOpt, tableName string) error

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, error)

func LoadDataFromSource added in v0.0.4

func LoadDataFromSource(backend types.BackendType, batchSize int) func(tx *sqlx.Tx, ctx context.Context, opt LoadDataFromSourceOpt) error

Currying

func OfflineBatchSnapshotTableName added in v0.1.0

func OfflineBatchSnapshotTableName(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 OnlineBatchTableName added in v0.1.0

func OnlineBatchTableName(revisionID int) string

func OnlineStreamTableName added in v0.1.0

func OnlineStreamTableName(groupID int) 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(opt ReadLineOpt) ([]interface{}, error)

ReadLine read a line from data source

func SerializeByValue added in v0.1.0

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

func SerializeByValueType added in v0.1.0

func SerializeByValueType(i interface{}, valueType types.ValueType, 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 BuildTableSchemaParams added in v0.1.0

type BuildTableSchemaParams struct {
	TableName    string
	EntityName   string
	HasUnixMilli bool
	Features     types.FeatureList
	PrimaryKeys  []string
	Backend      types.BackendType
}

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

	// Cassandra
	CassandraDB *gocql.Session
}

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 LoadDataFromSourceOpt added in v0.1.0

type LoadDataFromSourceOpt struct {
	Source     *offline.CSVSource
	EntityName string
	TableName  string
	Header     []string
	Features   types.FeatureList
	Backend    types.BackendType
}

type ReadLineOpt added in v0.1.0

type ReadLineOpt struct {
	Source     *offline.CSVSource
	EntityName string
	Header     []string
	Features   types.FeatureList
}

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