Documentation
¶
Index ¶
- Constants
- type CSVDataSource
- func (ds *CSVDataSource) Close() error
- func (ds *CSVDataSource) Connect(ctx context.Context) error
- func (ds *CSVDataSource) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
- func (ds *CSVDataSource) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
- func (ds *CSVDataSource) GetTables(ctx context.Context) ([]string, error)
- func (ds *CSVDataSource) TestConnection(ctx context.Context) error
- type ColumnSchema
- type Config
- type DBConfig
- type DataSource
- type DataSourceFactory
- type ExcelDataSource
- func (ds *ExcelDataSource) Close() error
- func (ds *ExcelDataSource) Connect(ctx context.Context) error
- func (ds *ExcelDataSource) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
- func (ds *ExcelDataSource) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
- func (ds *ExcelDataSource) GetTables(ctx context.Context) ([]string, error)
- func (ds *ExcelDataSource) TestConnection(ctx context.Context) error
- type ExcelDataSourceWithExcelize
- type ForeignKey
- type IndexSchema
- type JDBCConnector
- func (c *JDBCConnector) Close() error
- func (c *JDBCConnector) Connect(ctx context.Context) error
- func (c *JDBCConnector) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
- func (c *JDBCConnector) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
- func (c *JDBCConnector) GetTables(ctx context.Context) ([]string, error)
- func (c *JDBCConnector) SampleRows(ctx context.Context, tableName string, limit int) ([]map[string]interface{}, error)
- func (c *JDBCConnector) TestConnection(ctx context.Context) error
- type QueryResult
- type TableSchema
Constants ¶
const ExcelUsageInstructions = `` /* 874-byte string literal not displayed */
使用说明和安装步骤
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSVDataSource ¶
type CSVDataSource struct {
// contains filtered or unexported fields
}
CSVDataSource CSV数据源
func NewCSVDataSource ¶
func NewCSVDataSource(config *Config) (*CSVDataSource, error)
NewCSVDataSource 创建CSV数据源
func (*CSVDataSource) Connect ¶
func (ds *CSVDataSource) Connect(ctx context.Context) error
Connect 连接(加载CSV文件)
func (*CSVDataSource) ExecuteQuery ¶
func (ds *CSVDataSource) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
ExecuteQuery 执行查询(简化版,仅支持SELECT *)
func (*CSVDataSource) GetTableSchema ¶
func (ds *CSVDataSource) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
GetTableSchema 获取表结构
func (*CSVDataSource) GetTables ¶
func (ds *CSVDataSource) GetTables(ctx context.Context) ([]string, error)
GetTables 获取表名(CSV视为单表)
func (*CSVDataSource) TestConnection ¶
func (ds *CSVDataSource) TestConnection(ctx context.Context) error
TestConnection 测试连接
type ColumnSchema ¶
type ColumnSchema struct {
Name string
DataType string
Nullable bool
DefaultValue *string
Comment string
IsPrimaryKey bool
IsForeignKey bool
}
ColumnSchema 列结构
type Config ¶
type Config struct {
Type string // 'jdbc', 'csv', 'excel'
DBType string // 'postgresql' (for JDBC)
Settings map[string]interface{} // 具体配置
}
Config 数据源配置
type DBConfig ¶
type DBConfig struct {
DBType string `json:"db_type"` // postgresql
Host string `json:"host"`
Port int `json:"port"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
SSLMode string `json:"ssl_mode"` // disable, require
}
DBConfig 数据库连接配置
type DataSource ¶
type DataSource interface {
// Connect 连接数据源
Connect(ctx context.Context) error
// Close 关闭连接
Close() error
// GetTables 获取所有表名
GetTables(ctx context.Context) ([]string, error)
// GetTableSchema 获取表结构
GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
// ExecuteQuery 执行查询
ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
// TestConnection 测试连接
TestConnection(ctx context.Context) error
}
DataSource 数据源接口
func NewJDBCDataSource ¶
func NewJDBCDataSource(config *Config) (DataSource, error)
NewJDBCDataSource 从通用Config创建JDBC数据源(实现工厂模式)
type DataSourceFactory ¶
type DataSourceFactory struct{}
DataSourceFactory 数据源工厂
func NewDataSourceFactory ¶
func NewDataSourceFactory() *DataSourceFactory
NewDataSourceFactory 创建工厂
func (*DataSourceFactory) Create ¶
func (f *DataSourceFactory) Create(config *Config) (DataSource, error)
Create 创建数据源
type ExcelDataSource ¶
type ExcelDataSource struct {
// contains filtered or unexported fields
}
ExcelDataSource Excel数据源
func NewExcelDataSource ¶
func NewExcelDataSource(config *Config) (*ExcelDataSource, error)
NewExcelDataSource 创建Excel数据源
func (*ExcelDataSource) Connect ¶
func (ds *ExcelDataSource) Connect(ctx context.Context) error
Connect 连接(加载Excel文件)
func (*ExcelDataSource) ExecuteQuery ¶
func (ds *ExcelDataSource) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
ExecuteQuery 执行查询(简化版,仅支持SELECT *)
func (*ExcelDataSource) GetTableSchema ¶
func (ds *ExcelDataSource) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
GetTableSchema 获取表结构
func (*ExcelDataSource) GetTables ¶
func (ds *ExcelDataSource) GetTables(ctx context.Context) ([]string, error)
GetTables 获取表名(每个sheet视为一个表)
func (*ExcelDataSource) TestConnection ¶
func (ds *ExcelDataSource) TestConnection(ctx context.Context) error
TestConnection 测试连接
type ExcelDataSourceWithExcelize ¶
type ExcelDataSourceWithExcelize struct {
// contains filtered or unexported fields
}
ExcelDataSourceWithExcelize Excel数据源(使用excelize库的完整实现) 需要安装: go get github.com/xuri/excelize/v2
func NewExcelDataSourceWithExcelize ¶
func NewExcelDataSourceWithExcelize(config *Config) (*ExcelDataSourceWithExcelize, error)
NewExcelDataSourceWithExcelize 创建Excel数据源(带excelize)
func (*ExcelDataSourceWithExcelize) ConnectWithExcelize ¶
func (ds *ExcelDataSourceWithExcelize) ConnectWithExcelize(ctx context.Context) error
ConnectWithExcelize 连接并加载Excel文件
type ForeignKey ¶
type ForeignKey struct {
ColumnName string
RefTableName string
RefColumnName string
ConstraintName string
}
ForeignKey 外键关系
type IndexSchema ¶
IndexSchema 索引结构定义
type JDBCConnector ¶
type JDBCConnector struct {
// contains filtered or unexported fields
}
JDBCConnector JDBC连接器
func NewJDBCConnector ¶
func NewJDBCConnector(config *DBConfig) *JDBCConnector
NewJDBCConnector 创建JDBC连接器
func (*JDBCConnector) Connect ¶
func (c *JDBCConnector) Connect(ctx context.Context) error
Connect 连接数据库
func (*JDBCConnector) ExecuteQuery ¶
func (c *JDBCConnector) ExecuteQuery(ctx context.Context, query string) (*QueryResult, error)
ExecuteQuery 执行查询(实现DataSource接口)
func (*JDBCConnector) GetTableSchema ¶
func (c *JDBCConnector) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
GetTableSchema 获取表结构
func (*JDBCConnector) GetTables ¶
func (c *JDBCConnector) GetTables(ctx context.Context) ([]string, error)
GetTables 获取所有表名
func (*JDBCConnector) SampleRows ¶
func (c *JDBCConnector) SampleRows(ctx context.Context, tableName string, limit int) ([]map[string]interface{}, error)
SampleRows 采样数据
func (*JDBCConnector) TestConnection ¶
func (c *JDBCConnector) TestConnection(ctx context.Context) error
TestConnection 测试连接(验证只读权限)
type QueryResult ¶
QueryResult 查询结果
type TableSchema ¶
type TableSchema struct {
TableName string
Columns []ColumnSchema
PrimaryKeys []string
ForeignKeys []ForeignKey
RowCount int64
}
TableSchema 表结构