dbms

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartRead

func StartRead(ctx context.Context, reader BatchReader, sender plugin.RecordSender) (err error)

StartRead Start reading

Types

type BaseBatchReader

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

BaseBatchReader Basic batch reader

func NewBaseBatchReader

func NewBaseBatchReader(task *Task, mode string, opts *sql.TxOptions) *BaseBatchReader

NewBaseBatchReader Get basic batch reader through task, query mode, and transaction options

func (*BaseBatchReader) JobID

func (b *BaseBatchReader) JobID() int64

JobID Job number

func (*BaseBatchReader) Parameter

func (b *BaseBatchReader) Parameter() database.Parameter

Parameter Query parameters

func (*BaseBatchReader) Read

func (b *BaseBatchReader) Read(ctx context.Context, param database.Parameter, handler database.FetchHandler) (err error)

Query through context ctx, description, and database handler

func (*BaseBatchReader) TaskGroupID

func (b *BaseBatchReader) TaskGroupID() int64

TaskGroupID Task group number

func (*BaseBatchReader) TaskID

func (b *BaseBatchReader) TaskID() int64

TaskID Task number

type BaseColumn

type BaseColumn struct {
	Name string
}

BaseColumn represents basic column information.

func (*BaseColumn) GetName

func (b *BaseColumn) GetName() string

GetName retrieves the column name.

type BaseConfig

type BaseConfig struct {
	Username   string      `json:"username"`   // Username is the user's name.
	Password   string      `json:"password"`   // Password is the user's password.
	Column     []string    `json:"column"`     // Columns is the list of column information.
	Connection ConnConfig  `json:"connection"` // ConnectionInfo is the database connection information.
	Where      string      `json:"where"`      // Where is the query condition.
	Split      SplitConfig `json:"split"`      // SplitKey is the key used for splitting.
	QuerySQL   []string    `json:"querySql"`   // QuerySQL is the SQL query.
}

BaseConfig represents the basic configuration for a relational data reader.

func NewBaseConfig

func NewBaseConfig(conf *config.JSON) (c *BaseConfig, err error)

NewBaseConfig creates a new instance of BaseConfig based on the provided JSON configuration conf.

func (*BaseConfig) GetBaseTable

func (b *BaseConfig) GetBaseTable() *database.BaseTable

GetBaseTable retrieves the table information.

func (*BaseConfig) GetColumns

func (b *BaseConfig) GetColumns() (columns []Column)

GetColumns retrieves the column information.

func (*BaseConfig) GetPassword

func (b *BaseConfig) GetPassword() string

GetPassword retrieves the password.

func (*BaseConfig) GetQuerySQL added in v0.1.4

func (b *BaseConfig) GetQuerySQL() []string

GetQuerySQL retrieves the SQL query.

func (*BaseConfig) GetSplitConfig

func (b *BaseConfig) GetSplitConfig() SplitConfig

GetSplitConfig retrieves the splitting configuration.

func (*BaseConfig) GetURL

func (b *BaseConfig) GetURL() string

GetURL retrieves the URL for connecting to the relational database.

func (*BaseConfig) GetUsername

func (b *BaseConfig) GetUsername() string

GetUsername retrieves the username.

func (*BaseConfig) GetWhere

func (b *BaseConfig) GetWhere() string

GetWhere retrieves the query conditions.

type BaseDbHandler

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

BaseDbHandler - Basic Database Handler

func NewBaseDbHandler

func NewBaseDbHandler(newQuerier func(name string, conf *config.JSON) (Querier, error), opts *sql.TxOptions) *BaseDbHandler

Create a new instance of the BasicDbHandler using the function to obtain a querier (newQuerier) and transaction options (opts)

func (*BaseDbHandler) Config

func (d *BaseDbHandler) Config(conf *config.JSON) (Config, error)

Config - Retrieve the relational database input configuration using the JSON configuration (conf)

func (*BaseDbHandler) MaxParam

func (d *BaseDbHandler) MaxParam(config Config, table database.Table) database.Parameter

MaxParam - Get the maximum split value parameter based on the relational database input configuration (config) and table querier (Table)

func (*BaseDbHandler) MinParam

func (d *BaseDbHandler) MinParam(config Config, table database.Table) database.Parameter

MinParam - Retrieve split table parameters using the relational database input configuration (config) and querier

func (*BaseDbHandler) Querier

func (d *BaseDbHandler) Querier(name string, conf *config.JSON) (Querier, error)

Querier - Acquire a querier based on the database name (name) and JSON configuration (conf)

func (*BaseDbHandler) SplitParam

func (d *BaseDbHandler) SplitParam(config Config, querier Querier) database.Parameter

SplitParam - Obtain the minimum split value parameter based on the relational database input configuration (config) and table (Table)

func (*BaseDbHandler) TableParam

func (d *BaseDbHandler) TableParam(config Config, querier Querier) database.Parameter

TableParam - Get table parameters using the relational database input configuration (config) and querier

type BatchReader

type BatchReader interface {
	JobID() int64       // Job number
	TaskGroupID() int64 // Task group number
	TaskID() int64      // Task number
	Read(ctx context.Context, param database.Parameter,
		handler database.FetchHandler) (err error) // Query through context ctx, description, and database handler
	Parameter() database.Parameter // Query parameters
}

BatchReader Batch reader

type Column

type Column interface {
	GetName() string // GetTableName retrieves the table name.
}

Column represents column information.

type Config

type Config interface {
	GetUsername() string               // GetUsername retrieves the username.
	GetPassword() string               // GetPassword retrieves the password.
	GetURL() string                    // GetURL retrieves the connection URL.
	GetColumns() []Column              // GetColumns retrieves the column information.
	GetBaseTable() *database.BaseTable // GetBaseTable retrieves the table information.
	GetWhere() string                  // GetWhere retrieves the query conditions.
	GetSplitConfig() SplitConfig       // GetSplitConfig retrieves the splitting configuration.
	GetQuerySQL() []string             // GetQuerySQL retrieves the query SQL.
}

Config represents the configuration for a relational data reader.

type ConnConfig

type ConnConfig struct {
	URL   string      `json:"url"`   // ConnectToDatabase establishes a connection to the database.
	Table TableConfig `json:"table"` // TableConfig represents the configuration for a table.
}

ConnConfig represents the configuration for connecting to a database.

type DbHandler

type DbHandler interface {
	Querier(name string, conf *config.JSON) (Querier, error)         // Obtain a querier based on the database name (name) and JSON configuration (conf)
	Config(conf *config.JSON) (Config, error)                        // Acquire the relational database input configuration using the JSON configuration (conf)
	TableParam(config Config, querier Querier) database.Parameter    // Retrieve table parameters using the relational database input configuration (config) and querier
	SplitParam(config Config, querier Querier) database.Parameter    // Obtain split table parameters using the relational database input configuration (config) and querier
	MinParam(config Config, table database.Table) database.Parameter // Get the minimum split value parameter based on the relational database input configuration (config) and table (Table)
	MaxParam(config Config, table database.Table) database.Parameter // Retrieve the maximum split value parameter using the relational database input configuration (config) and table querier (Table)
}

DbHandler - Database Handler

type Job

type Job struct {
	*plugin.BaseJob

	Querier Querier
	Config  Config
	// contains filtered or unexported fields
}

Job

func NewJob

func NewJob(handler DbHandler) *Job

NewJob Get job through database handler

func (*Job) Destroy

func (j *Job) Destroy(ctx context.Context) (err error)

Destroy Destruction

func (*Job) Init

func (j *Job) Init(ctx context.Context) (err error)

Init Initialization

func (*Job) Split

func (j *Job) Split(ctx context.Context, number int) (configs []*config.JSON, err error)

Split Division

type MaxParam

type MaxParam struct {
	*database.BaseParam

	Config Config
}

MaxParam Maximum value parameter

func NewMaxParam

func NewMaxParam(config Config, table database.Table, opts *sql.TxOptions) *MaxParam

NewMaxParam Get query parameters through relational database input configuration config, corresponding database table table, and transaction options opts

func (*MaxParam) Agrs

func (m *MaxParam) Agrs(_ []element.Record) ([]interface{}, error)

Agrs Get query parameters

func (*MaxParam) Query

func (m *MaxParam) Query(_ []element.Record) (string, error)

Query Get the query statement

type MinParam

type MinParam struct {
	*database.BaseParam

	Config Config
}

MinParam Minimum value parameter

func NewMinParam

func NewMinParam(config Config, table database.Table, opts *sql.TxOptions) *MinParam

NewMinParam Get the minimum value parameter through relational database input configuration config, corresponding database table table, and transaction options opts

func (*MinParam) Agrs

func (m *MinParam) Agrs(_ []element.Record) ([]interface{}, error)

Agrs Get query parameters

func (*MinParam) Query

func (m *MinParam) Query(_ []element.Record) (string, error)

Query Get the query statement

type Querier

type Querier interface {
	// Obtain a specific table based on basic table information.
	Table(*database.BaseTable) database.Table
	// Check connectivity.
	PingContext(ctx context.Context) error
	// Perform a query using the specified query statement.
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	// Obtain a specific table based on the provided parameters.
	FetchTableWithParam(ctx context.Context, param database.Parameter) (database.Table, error)
	// Retrieve records using the provided parameters and the handler.
	FetchRecord(ctx context.Context, param database.Parameter, handler database.FetchHandler) (err error)
	// Retrieve records using the provided parameters, the handler, and within a transaction.
	FetchRecordWithTx(ctx context.Context, param database.Parameter, handler database.FetchHandler) (err error)
	// Close resources.
	Close() error
}

Querier - Query Executor

type QueryParam

type QueryParam struct {
	*database.BaseParam

	Config Config
}

QueryParam Query parameters

func NewQueryParam

func NewQueryParam(config Config, table database.Table, opts *sql.TxOptions) *QueryParam

NewQueryParam Get query parameters through relational database input configuration config, corresponding database table table, and transaction options opts

func (*QueryParam) Agrs

func (q *QueryParam) Agrs(_ []element.Record) (a []interface{}, err error)

Agrs Get query parameters

func (*QueryParam) Query

func (q *QueryParam) Query(_ []element.Record) (string, error)

Query Get the query statement

type SplitConfig

type SplitConfig struct {
	Key string `json:"key"` // Splitting Key
	// day (Day), min (Minute), s (Second), ms (Millisecond), us (Microsecond), ns (Nanosecond)
	TimeAccuracy string     `json:"timeAccuracy"` // Splitting Time Precision (Default: day)
	Range        SplitRange `json:"range"`        // Splitting Range
}

SplitConfig - Splitting Configuration

type SplitParam

type SplitParam struct {
	*database.BaseParam

	Config Config
}

SplitParam Splitting parameters

func NewSplitParam

func NewSplitParam(config Config, table TableParamTable, opts *sql.TxOptions) *SplitParam

NewSplitParam Get table parameter configuration config, get split table parameters through table parameters of the corresponding database table and transaction options opts

func (*SplitParam) Agrs

func (s *SplitParam) Agrs(_ []element.Record) ([]interface{}, error)

Agrs Get query parameters

func (*SplitParam) Query

func (s *SplitParam) Query(_ []element.Record) (string, error)

Query Get the query statement

type SplitRange

type SplitRange struct {
	Type   string `json:"type"`   // Type: bigint, string, time
	Layout string `json:"layout"` // Time Format
	Left   string `json:"left"`   // Start Point
	Right  string `json:"right"`  // End Point
	// contains filtered or unexported fields
}

SplitRange - Splitting Range Configuration

type TableConfig

type TableConfig struct {
	Db     string `json:"db"`     // Database is the name of the database.
	Schema string `json:"schema"` // Schema is the schema name.
	Name   string `json:"name"`   // TableName is the name of the table.
}

TableConfig represents the configuration for a table.

type TableParam

type TableParam struct {
	*database.BaseParam

	Config TableParamConfig
}

TableParam Table parameters

func NewTableParam

func NewTableParam(config TableParamConfig, table TableParamTable, opts *sql.TxOptions) *TableParam

NewTableParam Get table parameter configuration config, get table parameters through table parameters of the corresponding database table and transaction options opts

func (*TableParam) Agrs

func (t *TableParam) Agrs(_ []element.Record) ([]interface{}, error)

Agrs Get query parameters

func (*TableParam) Query

func (t *TableParam) Query(_ []element.Record) (string, error)

Query Get the query statement

type TableParamConfig

type TableParamConfig interface {
	GetColumns() []Column              // Get column information
	GetBaseTable() *database.BaseTable // Get table information
}

TableParamConfig Table parameter configuration

type TableParamTable

type TableParamTable interface {
	Table(*database.BaseTable) database.Table // Get the table of the corresponding database through table parameters
}

TableParamTable Get the table of the corresponding database through table parameters

type Task

type Task struct {
	*plugin.BaseTask

	Querier Querier
	Config  Config
	Table   database.Table
	// contains filtered or unexported fields
}

Task

func NewTask

func NewTask(handler DbHandler) *Task

NewTask Get task through database handler

func (*Task) Destroy

func (t *Task) Destroy(ctx context.Context) (err error)

Destroy Destruction

func (*Task) Init

func (t *Task) Init(ctx context.Context) (err error)

Init Initialization

Jump to

Keyboard shortcuts

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