shared

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OpExport 导出操作
	OpExport string = `export`
	// OpImport 导入操作
	OpImport string = `import`
)

Variables

View Source
var SQLTempDir = os.TempDir

SQLTempDir sql文件缓存目录获取函数(用于导入导出SQL)

Functions

func BackgroundExecManage

func BackgroundExecManage(ctx echo.Context, cfg driver.DbAuth, op string, cancel bool) error

func ExportMultipleTablesToWriter

func ExportMultipleTablesToWriter(w io.Writer, db *sql.DB, tables []string, quoteChar string, withStruct, withData bool, version string) error

ExportMultipleTablesToWriter exports multiple tables to a writer.

func ExportSQLFiles

func ExportSQLFiles(ctx echo.Context, cfg driver.DbAuth, dbName string, charset string, tables []string, exportExecutor ExportExecutor) (echo.Data, error)

func ExportTableToCSV

func ExportTableToCSV(ctx echo.Context, db *sql.DB, tableName, quoteChar string) error

ExportTableToCSV streams all rows from a table as CSV.

func ExportTableToSQL

func ExportTableToSQL(ctx echo.Context, db *sql.DB, tableName, quoteChar string) error

ExportTableToSQL streams all rows from a table as INSERT statements.

func FormatCSVRow

func FormatCSVRow(values []interface{}) string

FormatCSVRow formats a row values as CSV.

func FormatValues

func FormatValues(values []interface{}) string

FormatValues formats a row of values for SQL INSERT.

func GetSQLFiles

func GetSQLFiles(ctx echo.Context) ([]string, error)

func GetTableColumns

func GetTableColumns(db *sql.DB, tableName string) ([]string, error)

GetTableColumns returns column names for a table.

func GetTableDDL

func GetTableDDL(db *sql.DB, tableName, quoteChar string) (string, error)

GetTableDDL attempts to retrieve table DDL.

func ImportSQLFiles

func ImportSQLFiles(ctx echo.Context, cfg driver.DbAuth, dbName string, charset string, sqlFiles []string, async bool, importExecutor ImportExecutor) error

func IsQuerySQL

func IsQuerySQL(sql string) bool

IsQuerySQL returns true if SQL is a query.

func QueryNext

func QueryNext(rows *sql.Rows, callback func(columns []string, row map[string]*sql.NullString) error, limit int, textLength ...int) (columns []string, err error)

func QueryTable

func QueryTable(rows *sql.Rows, limit int, textLength ...int) (columns []string, r []map[string]*sql.NullString, err error)

func QuoteIdentifier

func QuoteIdentifier(name, quote string) string

QuoteIdentifier quotes a database identifier.

func QuoteValue

func QuoteValue(v string) string

QuoteValue quotes a string value for SQL.

func ReleaseResult

func ReleaseResult(r *Result)

func ResponseDropzone

func ResponseDropzone(err error, ctx echo.Context) error

func RunSQL

func RunSQL(drv *driver.BaseDriver, db *sql.DB, selectTable TableQuerier) error

func SplitHostPort

func SplitHostPort(host string) (string, string)

SplitHostPort splits host:port into separate values.

func TempDir

func TempDir(op string) string

Types

type DBConfig

type DBConfig struct {
	Driver   string
	Host     string
	Port     string
	Username string
	Password string
	Database string
}

DBConfig holds connection parameters for native tools.

type DataTable

type DataTable struct {
	Columns []string
	Values  []map[string]*sql.NullString
}

func NewDataTable

func NewDataTable() *DataTable

type ExportDriver

type ExportDriver struct {
	Name       string
	BinName    string
	BinPaths   []string
	Lookup     func() (string, error)
	ExportFunc func(ctx context.Context, cfg *DBConfig, tables []string, structWriter, dataWriter io.Writer) error
}

ExportDriver describes capabilities of a native export tool.

type ExportExecutor

type ExportExecutor func(ctx context.Context, noticer notice.Noticer,
	cfg *driver.DbAuth, tables []string, structWriter, dataWriter interface{}) error

type FileInfo

type FileInfo struct {
	Start      time.Time
	End        time.Time
	Elapsed    time.Duration
	Path       string
	Size       int64
	Compressed bool
	Error      string `json:",omitempty"`
}

FileInfo 文件信息

type FileInfos

type FileInfos []*FileInfo

FileInfos 文件信息集合

func (*FileInfos) Add

func (f *FileInfos) Add(fi *FileInfo)

type ImportDriver

type ImportDriver struct {
	Name       string
	BinName    string
	BinPaths   []string
	Lookup     func() (string, error)
	ImportFunc func(ctx context.Context, cfg *DBConfig, files []string, noticer *notice.NoticeAndProgress) error
}

ImportDriver describes capabilities of a native import tool.

type ImportExecutor

type ImportExecutor func(ctx context.Context, noticer *notice.NoticeAndProgress, cfg *driver.DbAuth, cacheDir string, files []string) error

type ImportFile

type ImportFile struct {
	StructFiles []string
	DataFiles   []string
	// contains filtered or unexported fields
}

func ParseImportFile

func ParseImportFile(cacheDir string, files []string) (*ImportFile, error)

func (*ImportFile) AllSqlFileNum

func (a *ImportFile) AllSqlFileNum() int

func (*ImportFile) AllSqlFiles

func (a *ImportFile) AllSqlFiles() []string

func (*ImportFile) Close

func (a *ImportFile) Close() error

type Result

type Result struct {
	SQL          string
	SQLs         []string
	RowsAffected int64
	TimeStart    time.Time
	TimeEnd      time.Time
	Started      string
	Elapsed      string

	ErrorString string
	// contains filtered or unexported fields
}

func AcquireResult

func AcquireResult() *Result

func (*Result) End

func (r *Result) End() *Result

func (*Result) Error

func (r *Result) Error() error

func (*Result) Exec

func (r *Result) Exec(p *factory.Param) *Result

func (*Result) Execs

func (r *Result) Execs(p *factory.Param) *Result

func (*Result) GetAffected

func (r *Result) GetAffected() int64

func (*Result) GetBeginTime

func (r *Result) GetBeginTime() string

func (*Result) GetDB

func (r *Result) GetDB(p *factory.Param) *sql.DB

func (*Result) GetElapsedTime

func (r *Result) GetElapsedTime() string

func (*Result) GetError

func (r *Result) GetError() string

func (*Result) GetSQL

func (r *Result) GetSQL() string

func (*Result) GetSQLs

func (r *Result) GetSQLs() []string

func (*Result) Queries

func (r *Result) Queries(p *factory.Param, readRows func(*sql.Rows) error) *Result

func (*Result) Query

func (r *Result) Query(p *factory.Param, readRows func(*sql.Rows) error) *Result

func (*Result) QueryRow

func (r *Result) QueryRow(p *factory.Param, recvs ...interface{}) *Result

func (*Result) Reset

func (r *Result) Reset()

func (*Result) SetDB

func (r *Result) SetDB(db *sql.DB) *Result

func (*Result) SetError

func (r *Result) SetError(err error)

func (*Result) Start

func (r *Result) Start() *Result

func (*Result) ToHTML

func (r *Result) ToHTML(urlPrefix string, sql string) template.HTML

type SQLExecutor

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

SQLExecutor executes SQL statements incrementally as they are read line by line.

func NewSQLExecutor

func NewSQLExecutor(db *sql.DB) *SQLExecutor

NewSQLExecutor creates a line-based SQL executor for use with SeekFileLines. It accumulates lines into a statement buffer and executes when a complete statement (ending with ';') is detected. Returns final stats.

func (*SQLExecutor) ExecuteSQLFiles

func (e *SQLExecutor) ExecuteSQLFiles(ctx context.Context, noticer *notice.NoticeAndProgress, sqlFiles []string, ignoreErr bool) (err error)

func (*SQLExecutor) ExecuteUploadedSQLFile

func (e *SQLExecutor) ExecuteUploadedSQLFile(file multipart.File, hdr *multipart.FileHeader) (SQLStats, error)

func (*SQLExecutor) Flush

func (e *SQLExecutor) Flush()

Flush executes any remaining un-terminated statement.

func (*SQLExecutor) ImportExecutor

func (e *SQLExecutor) ImportExecutor(ctx context.Context, noticer *notice.NoticeAndProgress, cfg *driver.DbAuth, cacheDir string, files []string) error

func (*SQLExecutor) Stats

func (e *SQLExecutor) Stats() SQLStats

Stats returns the accumulated execution statistics.

func (*SQLExecutor) WriteLine

func (e *SQLExecutor) WriteLine(line string) error

WriteLine processes one line of SQL content. If it completes a statement, the statement is executed immediately.

type SQLStats

type SQLStats struct {
	Total   int
	Success int
	Failed  int
	Errors  []string
}

SQLStats holds result of SQL execution.

type SelectData

type SelectData struct {
	Result  *Result
	Data    *DataTable
	Explain *DataTable
}

type TableQuerier

type TableQuerier func(rows *sql.Rows, limit int, textLength ...int) (columns []string, r []map[string]*sql.NullString, err error)

Jump to

Keyboard shortcuts

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