Documentation
¶
Index ¶
- Constants
- Variables
- func BackgroundExecManage(ctx echo.Context, cfg driver.DbAuth, op string, cancel bool) error
- func ExportMultipleTablesToWriter(w io.Writer, db *sql.DB, tables []string, quoteChar string, ...) error
- func ExportSQLFiles(ctx echo.Context, cfg driver.DbAuth, dbName string, charset string, ...) (echo.Data, error)
- func ExportTableToCSV(ctx echo.Context, db *sql.DB, tableName, quoteChar string) error
- func ExportTableToSQL(ctx echo.Context, db *sql.DB, tableName, quoteChar string) error
- func FormatCSVRow(values []interface{}) string
- func FormatValues(values []interface{}) string
- func GetSQLFiles(ctx echo.Context) ([]string, error)
- func GetTableColumns(db *sql.DB, tableName string) ([]string, error)
- func GetTableDDL(db *sql.DB, tableName, quoteChar string) (string, error)
- func ImportSQLFiles(ctx echo.Context, cfg driver.DbAuth, dbName string, charset string, ...) error
- func IsQuerySQL(sql string) bool
- func QueryNext(rows *sql.Rows, ...) (columns []string, err error)
- func QueryTable(rows *sql.Rows, limit int, textLength ...int) (columns []string, r []map[string]*sql.NullString, err error)
- func QuoteIdentifier(name, quote string) string
- func QuoteValue(v string) string
- func ReleaseResult(r *Result)
- func ResponseDropzone(err error, ctx echo.Context) error
- func RunSQL(drv *driver.BaseDriver, db *sql.DB, selectTable TableQuerier) error
- func SplitHostPort(host string) (string, string)
- func TempDir(op string) string
- type DBConfig
- type DataTable
- type ExportDriver
- type ExportExecutor
- type FileInfo
- type FileInfos
- type ImportDriver
- type ImportExecutor
- type ImportFile
- type Result
- func (r *Result) End() *Result
- func (r *Result) Error() error
- func (r *Result) Exec(p *factory.Param) *Result
- func (r *Result) Execs(p *factory.Param) *Result
- func (r *Result) GetAffected() int64
- func (r *Result) GetBeginTime() string
- func (r *Result) GetDB(p *factory.Param) *sql.DB
- func (r *Result) GetElapsedTime() string
- func (r *Result) GetError() string
- func (r *Result) GetSQL() string
- func (r *Result) GetSQLs() []string
- func (r *Result) Queries(p *factory.Param, readRows func(*sql.Rows) error) *Result
- func (r *Result) Query(p *factory.Param, readRows func(*sql.Rows) error) *Result
- func (r *Result) QueryRow(p *factory.Param, recvs ...interface{}) *Result
- func (r *Result) Reset()
- func (r *Result) SetDB(db *sql.DB) *Result
- func (r *Result) SetError(err error)
- func (r *Result) Start() *Result
- func (r *Result) ToHTML(urlPrefix string, sql string) template.HTML
- type SQLExecutor
- func (e *SQLExecutor) ExecuteSQLFiles(ctx context.Context, noticer *notice.NoticeAndProgress, sqlFiles []string, ...) (err error)
- func (e *SQLExecutor) ExecuteUploadedSQLFile(file multipart.File, hdr *multipart.FileHeader) (SQLStats, error)
- func (e *SQLExecutor) Flush()
- func (e *SQLExecutor) ImportExecutor(ctx context.Context, noticer *notice.NoticeAndProgress, cfg *driver.DbAuth, ...) error
- func (e *SQLExecutor) Stats() SQLStats
- func (e *SQLExecutor) WriteLine(line string) error
- type SQLStats
- type SelectData
- type TableQuerier
Constants ¶
const ( // OpExport 导出操作 OpExport string = `export` // OpImport 导入操作 OpImport string = `import` )
Variables ¶
var SQLTempDir = os.TempDir
SQLTempDir sql文件缓存目录获取函数(用于导入导出SQL)
Functions ¶
func BackgroundExecManage ¶
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 ExportTableToCSV ¶
ExportTableToCSV streams all rows from a table as CSV.
func ExportTableToSQL ¶
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 GetTableColumns ¶
GetTableColumns returns column names for a table.
func GetTableDDL ¶
GetTableDDL attempts to retrieve table DDL.
func ImportSQLFiles ¶
func QueryTable ¶
func QuoteIdentifier ¶
QuoteIdentifier quotes a database identifier.
func ReleaseResult ¶
func ReleaseResult(r *Result)
func RunSQL ¶
func RunSQL(drv *driver.BaseDriver, db *sql.DB, selectTable TableQuerier) error
func SplitHostPort ¶
SplitHostPort splits host:port into separate values.
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 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 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 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) GetAffected ¶
func (*Result) GetBeginTime ¶
func (*Result) GetElapsedTime ¶
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.