Documentation
¶
Index ¶
- Variables
- func ErrAPICall(details string) error
- func ErrAuth(details string) error
- func ErrDataMapping(details string) error
- func ErrInvalidConfig(details string) error
- func ErrSQLParsing(details string) error
- func GetFieldTypeName(fieldType FieldType) string
- func GetStringFromMap(m map[string]interface{}, key string) string
- func IsPermissionError(err error) bool
- func IsValidFieldType(fieldType FieldType) bool
- func Open(config *Config) gorm.Dialector
- func RegisterCallbacks(db *gorm.DB, dialector *Dialector)
- type APIError
- type APIRequest
- type APIResponse
- type AuthType
- type BaseError
- type BaseValue
- type BatchCreateRecordsRequest
- type BatchCreateRecordsResponse
- type BatchDeleteRecordsRequest
- type BatchDeleteRecordsResponse
- type BatchUpdateRecord
- type BatchUpdateRecordsRequest
- type BatchUpdateRecordsResponse
- type Client
- func (c *Client) Close() error
- func (c *Client) DoRequest(ctx context.Context, req *APIRequest) (*APIResponse, error)
- func (c *Client) GetStabilityStats() map[string]interface{}
- func (c *Client) HealthCheck(ctx context.Context) (bool, error)
- func (c *Client) ResetStabilityComponents() error
- func (c *Client) SetRetryConfig(config *RetryConfig)
- func (c *Client) UpdateConnectionPoolConfig(config *common.ConnectionPoolConfig) error
- func (c *Client) UpdateRateLimiterConfig(config *common.RateLimiterConfig) error
- type Config
- type ConnPool
- func (c *ConnPool) BeginTx(ctx context.Context, opt *sql.TxOptions) (gorm.ConnPool, error)
- func (c *ConnPool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (c *ConnPool) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (c *ConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (c *ConnPool) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (c *ConnPool) RollbackTo(ctx context.Context, name string) error
- func (c *ConnPool) SavePoint(ctx context.Context, name string) error
- type CreateDefaultViewRequest
- type CreateFieldRequest
- type CreateFieldResponse
- type CreateRecordAPIResponse
- type CreateRecordRequest
- type CreateRecordResponse
- type CreateTableRequest
- type CreateTableResponse
- type Dialector
- func (d *Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{})
- func (d *Dialector) DataTypeOf(field *schema.Field) string
- func (d *Dialector) DefaultValueOf(field *schema.Field) clause.Expression
- func (d *Dialector) Explain(sql string, vars ...interface{}) string
- func (d *Dialector) Initialize(db *gorm.DB) error
- func (d *Dialector) Migrator(db *gorm.DB) gorm.Migrator
- func (d *Dialector) Name() string
- func (d *Dialector) QuoteTo(writer clause.Writer, str string)
- type Field
- func (f *Field) ConvertFromGoValue(value interface{}) interface{}
- func (f *Field) ConvertToGoValue(value interface{}) interface{}
- func (f *Field) IsReadOnly() bool
- func (f *Field) IsSystemField() bool
- func (f *Field) MarshalJSON() ([]byte, error)
- func (f *Field) UnmarshalJSON(data []byte) error
- func (f *Field) Validate() error
- type FieldType
- type FilterCondition
- type FilterRequest
- type ListFieldsAPIResponse
- type ListFieldsResponse
- type ListRecordsAPIResponse
- type ListRecordsRequest
- type ListRecordsResponse
- type ListTablesAPIResponse
- type ListTablesResponse
- type Migrator
- func (m Migrator) AutoMigrate(values ...interface{}) error
- func (m Migrator) CreateTable(values ...interface{}) error
- func (m Migrator) DropTable(values ...interface{}) error
- func (m Migrator) HasTable(table interface{}) bool
- func (m Migrator) RunAutoMigrate(value interface{}) error
- func (m Migrator) UpdateColumns(value interface{}) error
- type Option
- type Record
- type RetryConfig
- type SQLCommand
- type SQLConverter
- func (c *SQLConverter) ConvertCreate(ctx context.Context, stmt *gorm.Statement) error
- func (c *SQLConverter) ConvertDelete(ctx context.Context, stmt *gorm.Statement) error
- func (c *SQLConverter) ConvertQuery(ctx context.Context, stmt *gorm.Statement) error
- func (c *SQLConverter) ConvertUpdate(ctx context.Context, stmt *gorm.Statement) error
- type Table
- type TableRequest
- type TokenResponse
- type Transaction
- func (tx *Transaction) Commit() error
- func (tx *Transaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Transaction) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (tx *Transaction) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Transaction) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (tx *Transaction) Rollback() error
- type UpdateRecordRequest
- type UpdateRecordResponse
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnectionFailed = errors.New("basesql: connection failed") ErrInvalidCredentials = errors.New("basesql: invalid credentials") ErrTableNotFound = errors.New("basesql: table not found") ErrFieldNotFound = errors.New("basesql: field not found") ErrRecordNotFound = errors.New("basesql: record not found") ErrUnsupportedType = errors.New("basesql: unsupported data type") ErrRateLimitExceeded = errors.New("basesql: rate limit exceeded") ErrBatchSizeExceeded = errors.New("basesql: batch size exceeded") ErrInvalidQuery = errors.New("basesql: invalid query") ErrPermissionDenied = errors.New("basesql: permission denied") ErrInvalidOperation = errors.New("basesql: invalid operation") )
预定义错误
var DefaultRetryConfig = RetryConfig{ MaxRetries: 3, InitialDelay: time.Second, MaxDelay: 30 * time.Second, Multiplier: 2.0, }
DefaultRetryConfig 默认重试配置
var FieldTypeMapping = map[FieldType]string{ FieldTypeText: "1", FieldTypeNumber: "2", FieldTypeSingleSelect: "3", FieldTypeMultiSelect: "4", FieldTypeDate: "5", FieldTypeCheckbox: "7", FieldTypeUser: "11", FieldTypePhone: "13", FieldTypeURL: "15", FieldTypeAttachment: "17", FieldTypeBarcode: "18", FieldTypeProgress: "19", FieldTypeCurrency: "20", FieldTypeRating: "21", FieldTypeFormula: "22", FieldTypeLookup: "23", FieldTypeCreatedTime: "1001", FieldTypeModifiedTime: "1002", FieldTypeCreatedUser: "1003", FieldTypeModifiedUser: "1004", FieldTypeAutoNumber: "1005", }
FieldTypeMapping 字段类型到字符串的映射表 用于 JSON 序列化时将字段类型枚举转换为对应的字符串表示
Functions ¶
func ErrAPICall ¶
func ErrDataMapping ¶
func ErrSQLParsing ¶
func GetStringFromMap ¶
GetStringFromMap 安全地从 map 中获取字符串值
func IsValidFieldType ¶
IsValidFieldType 检查字段类型是否有效 参数:
- fieldType: 要检查的字段类型
返回:
- bool: 如果字段类型有效返回 true,否则返回 false
func Open ¶
Open 创建并返回一个新的 BaseSQL 方言器实例 该函数会合并用户配置和默认配置,确保所有必要的配置项都有合理的默认值 参数:
- config: 用户提供的配置,可以为 nil 或部分配置
返回:
- gorm.Dialector: GORM 方言器接口实例
func RegisterCallbacks ¶
RegisterCallbacks 注册 GORM 回调函数 这个函数会替换 GORM 的默认回调处理器,将 SQL 操作转换为飞书多维表格 API 调用 参数:
- db: GORM 数据库实例
- dialector: BaseSQL 的方言器实例
Types ¶
type APIResponse ¶
type APIResponse = common.APIResponse
type BaseError ¶
type BaseError struct {
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
BaseError 基础错误类型
type BaseValue ¶
type BaseValue struct {
Val interface{} // 存储的值,可以是任意类型
}
BaseValue 实现了 GORM 和 SQL 相关的值接口 用于在 GORM 和飞书多维表格之间进行值的转换和传递
func NewBaseValue ¶
func NewBaseValue(val interface{}) *BaseValue
NewBaseValue 创建一个新的 BaseValue 实例 参数:
- val: 要存储的值
返回:
- *BaseValue: BaseValue 实例
func (BaseValue) GormValue ¶
GormValue 实现 gorm.Valuer 接口 将值转换为 GORM 可以处理的表达式 参数:
- ctx: 上下文
- db: GORM 数据库实例
返回:
- clause.Expr: GORM 表达式
type BatchCreateRecordsRequest ¶
type BatchCreateRecordsRequest struct {
Records []*CreateRecordRequest `json:"records"` // 要创建的记录列表
}
BatchCreateRecordsRequest 批量创建记录的请求结构 用于一次性创建多条记录,提高操作效率
func (*BatchCreateRecordsRequest) Validate ¶
func (req *BatchCreateRecordsRequest) Validate() error
Validate 验证批量创建记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type BatchCreateRecordsResponse ¶
type BatchCreateRecordsResponse struct {
Records []*Record `json:"records"` // 创建的记录列表
}
BatchCreateRecordsResponse 批量创建记录的响应结构 包含批量创建操作的结果和新创建的记录列表
func (*BatchCreateRecordsResponse) GetRecordCount ¶
func (resp *BatchCreateRecordsResponse) GetRecordCount() int
GetRecordCount 获取成功创建的记录数量 返回:
- int: 成功创建的记录数量
func (*BatchCreateRecordsResponse) GetRecords ¶
func (resp *BatchCreateRecordsResponse) GetRecords() []*Record
GetRecords 获取创建的记录列表 返回:
- []*Record: 创建的记录列表,如果操作失败返回空切片
func (*BatchCreateRecordsResponse) IsSuccess ¶
func (resp *BatchCreateRecordsResponse) IsSuccess() bool
IsSuccess 判断批量创建记录操作是否成功 返回:
- bool: 操作是否成功
type BatchDeleteRecordsRequest ¶
type BatchDeleteRecordsRequest struct {
Records []string `json:"records"` // 要删除的记录 ID 列表
}
BatchDeleteRecordsRequest 批量删除记录的请求结构 用于一次性删除多条记录
func (*BatchDeleteRecordsRequest) Validate ¶
func (req *BatchDeleteRecordsRequest) Validate() error
Validate 验证批量删除记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type BatchDeleteRecordsResponse ¶
type BatchDeleteRecordsResponse struct {
Records []string `json:"records"` // 成功删除的记录 ID 列表
}
BatchDeleteRecordsResponse 批量删除记录的响应结构 包含批量删除操作的结果
func (*BatchDeleteRecordsResponse) GetDeletedCount ¶
func (resp *BatchDeleteRecordsResponse) GetDeletedCount() int
GetDeletedCount 获取成功删除的记录数量 返回:
- int: 成功删除的记录数量
func (*BatchDeleteRecordsResponse) GetDeletedRecords ¶
func (resp *BatchDeleteRecordsResponse) GetDeletedRecords() []string
GetDeletedRecords 获取成功删除的记录 ID 列表 返回:
- []string: 成功删除的记录 ID 列表
func (*BatchDeleteRecordsResponse) IsSuccess ¶
func (resp *BatchDeleteRecordsResponse) IsSuccess() bool
IsSuccess 判断批量删除记录操作是否成功 返回:
- bool: 操作是否成功
type BatchUpdateRecord ¶
type BatchUpdateRecord struct {
RecordID string `json:"record_id"` // 要更新的记录 ID
Fields map[string]interface{} `json:"fields"` // 要更新的字段值映射
}
BatchUpdateRecord 批量更新记录项 表示单个要更新的记录及其新的字段值
func (*BatchUpdateRecord) Validate ¶
func (r *BatchUpdateRecord) Validate() error
Validate 验证批量更新记录项的有效性 返回:
- error: 如果记录项无效,返回相应的错误信息
type BatchUpdateRecordsRequest ¶
type BatchUpdateRecordsRequest struct {
Records []*BatchUpdateRecord `json:"records"` // 要更新的记录列表
}
BatchUpdateRecordsRequest 批量更新记录的请求结构 用于一次性更新多条记录,提高操作效率
func (*BatchUpdateRecordsRequest) Validate ¶
func (req *BatchUpdateRecordsRequest) Validate() error
Validate 验证批量更新记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type BatchUpdateRecordsResponse ¶
type BatchUpdateRecordsResponse struct {
Records []*Record `json:"records"` // 更新后的记录列表
}
BatchUpdateRecordsResponse 批量更新记录的响应结构 包含批量更新操作的结果和更新后的记录列表
func (*BatchUpdateRecordsResponse) GetRecordCount ¶
func (resp *BatchUpdateRecordsResponse) GetRecordCount() int
GetRecordCount 获取成功更新的记录数量 返回:
- int: 成功更新的记录数量
func (*BatchUpdateRecordsResponse) GetRecords ¶
func (resp *BatchUpdateRecordsResponse) GetRecords() []*Record
GetRecords 获取更新后的记录列表 返回:
- []*Record: 更新后的记录列表,如果操作失败返回空切片
func (*BatchUpdateRecordsResponse) IsSuccess ¶
func (resp *BatchUpdateRecordsResponse) IsSuccess() bool
IsSuccess 判断批量更新记录操作是否成功 返回:
- bool: 操作是否成功
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 飞书 API 客户端,负责处理与飞书多维表格 API 的所有通信 包括认证、令牌管理、请求发送等核心功能
func NewClient ¶
NewClient 创建新的飞书 API 客户端 参数:
- config: 客户端配置,包含认证信息和其他设置
返回:
- *Client: 初始化完成的客户端实例
- error: 创建过程中的错误
func (*Client) DoRequest ¶
func (c *Client) DoRequest(ctx context.Context, req *APIRequest) (*APIResponse, error)
DoRequest 执行飞书 API 请求 这是所有 API 调用的核心方法,处理认证、请求构建、发送和响应解析 支持自动重试机制,提高请求的稳定性 参数:
- ctx: 上下文,用于控制请求超时和取消
- req: API 请求结构,包含请求的所有信息
返回:
- *APIResponse: API 响应结构
- error: 请求过程中的错误
func (*Client) SetRetryConfig ¶
func (c *Client) SetRetryConfig(config *RetryConfig)
SetRetryConfig 设置重试配置 参数:
- config: 重试配置
func (*Client) UpdateConnectionPoolConfig ¶
func (c *Client) UpdateConnectionPoolConfig(config *common.ConnectionPoolConfig) error
UpdateConnectionPoolConfig 更新连接池配置 参数:
- config: 新的连接池配置
返回:
- error: 更新错误
func (*Client) UpdateRateLimiterConfig ¶
func (c *Client) UpdateRateLimiterConfig(config *common.RateLimiterConfig) error
UpdateRateLimiterConfig 更新限流器配置 参数:
- config: 新的限流器配置
返回:
- error: 更新错误
type Config ¶
type Config struct {
// 飞书应用配置
AppID string `json:"app_id"` // 应用 ID
AppSecret string `json:"app_secret"` // 应用密钥
BaseURL string `json:"base_url"` // API 基础 URL,默认 https://open.feishu.cn
// 认证配置
AuthType AuthType `json:"auth_type"` // 认证类型
AccessToken string `json:"access_token"` // 用户访问令牌(AuthTypeUser 时使用)
// 多维表格配置
AppToken string `json:"app_token"` // 多维表格的 app_token
TableID string `json:"table_id"` // 默认表 ID(可选)
// 连接配置
Timeout time.Duration `json:"timeout"` // 请求超时时间
MaxRetries int `json:"max_retries"` // 最大重试次数
RetryInterval time.Duration `json:"retry_interval"` // 重试间隔
RateLimitQPS int `json:"rate_limit_qps"` // 每秒请求限制
BatchSize int `json:"batch_size"` // 批量操作大小
CacheEnabled bool `json:"cache_enabled"` // 是否启用缓存
CacheTTL time.Duration `json:"cache_ttl"` // 缓存过期时间
DebugMode bool `json:"debug_mode"` // 调试模式
ConsistencyMode bool `json:"consistency_mode"` // 一致性模式
}
Config 飞书多维表格配置
type ConnPool ¶
type ConnPool struct {
Dialector *Dialector // 关联的方言器实例
}
ConnPool 实现 gorm.ConnPool 接口 用于拦截 GORM 的数据库操作,将其转换为飞书多维表格 API 调用 注意:由于飞书多维表格不是传统的 SQL 数据库,大部分方法返回不支持的错误
func (*ConnPool) BeginTx ¶
BeginTx 开始事务 实现 gorm.ConnPoolBeginner 接口 由于飞书多维表格不支持事务,此方法返回一个Transaction实例 参数:
- ctx: 上下文
- opt: 事务选项
返回:
- gorm.ConnPool: Transaction实例(实现了gorm.ConnPool接口)
- error: 错误信息(始终为 nil)
func (*ConnPool) ExecContext ¶
func (c *ConnPool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext 执行 SQL 语句 由于飞书多维表格不支持直接 SQL 执行,此方法返回不支持错误 实际的操作通过 GORM 回调函数处理 参数:
- ctx: 上下文
- query: SQL 查询语句
- args: 查询参数
返回:
- sql.Result: 执行结果(始终为 nil)
- error: 不支持错误
func (*ConnPool) PrepareContext ¶
PrepareContext 准备 SQL 语句 由于飞书多维表格不支持预编译语句,此方法返回不支持错误 参数:
- ctx: 上下文
- query: SQL 查询语句
返回:
- *sql.Stmt: 预编译语句(始终为 nil)
- error: 不支持错误
func (*ConnPool) QueryContext ¶
func (c *ConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext 执行查询语句 由于飞书多维表格不支持直接 SQL 查询,此方法返回不支持错误 实际的查询通过 GORM 回调函数处理 参数:
- ctx: 上下文
- query: SQL 查询语句
- args: 查询参数
返回:
- *sql.Rows: 查询结果(始终为 nil)
- error: 不支持错误
func (*ConnPool) QueryRowContext ¶
QueryRowContext 执行单行查询 由于飞书多维表格不支持直接 SQL 查询,此方法返回空行 实际的查询通过 GORM 回调函数处理 参数:
- ctx: 上下文
- query: SQL 查询语句
- args: 查询参数
返回:
- *sql.Row: 查询结果行(空行)
func (*ConnPool) RollbackTo ¶
RollbackTo 回滚到保存点 实现 gorm.SavePointer 接口 由于飞书多维表格不支持事务回滚,此方法为空实现 参数:
- ctx: 上下文
- name: 保存点名称
返回:
- error: 错误信息(始终为 nil)
type CreateDefaultViewRequest ¶
type CreateDefaultViewRequest struct {
Name string `json:"name"` // 视图名称
ViewType string `json:"view_type"` // 视图类型(如 grid、kanban 等)
}
CreateDefaultViewRequest 创建默认视图的请求结构 用于为新创建的表设置默认视图
func (*CreateDefaultViewRequest) Validate ¶
func (req *CreateDefaultViewRequest) Validate() error
Validate 验证创建默认视图请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type CreateFieldRequest ¶
type CreateFieldRequest struct {
FieldName string `json:"field_name"` // 字段名称
Type FieldType `json:"type"` // 字段类型
Property map[string]interface{} `json:"property,omitempty"` // 字段属性配置
Description string `json:"description,omitempty"` // 字段描述
}
CreateFieldRequest 创建字段的请求结构 用于在飞书多维表格中创建新字段
func (*CreateFieldRequest) MarshalJSON ¶
func (r *CreateFieldRequest) MarshalJSON() ([]byte, error)
MarshalJSON 自定义 JSON 序列化 将 FieldType 枚举转换为整数类型以符合 API 要求
func (*CreateFieldRequest) Validate ¶
func (req *CreateFieldRequest) Validate() error
Validate 验证创建字段请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type CreateFieldResponse ¶
type CreateFieldResponse struct {
Field *Field `json:"field"` // 创建的字段信息
}
CreateFieldResponse 创建字段的响应结构 包含创建操作的结果和新创建的字段信息
func (*CreateFieldResponse) GetField ¶
func (resp *CreateFieldResponse) GetField() *Field
GetField 获取创建的字段 返回:
- *Field: 创建的字段,如果操作失败返回 nil
func (*CreateFieldResponse) IsSuccess ¶
func (resp *CreateFieldResponse) IsSuccess() bool
IsSuccess 判断创建字段操作是否成功 返回:
- bool: 操作是否成功
type CreateRecordAPIResponse ¶
type CreateRecordAPIResponse struct {
Code int `json:"code"` // 响应码
Msg string `json:"msg"` // 响应消息
Data *CreateRecordResponse `json:"data"` // 实际数据
}
CreateRecordAPIResponse 飞书API创建记录的完整响应结构 包含飞书API标准的code、data、msg字段
type CreateRecordRequest ¶
type CreateRecordRequest struct {
Fields map[string]interface{} `json:"fields"` // 记录的字段值映射
}
CreateRecordRequest 创建记录的请求结构 用于向飞书多维表格创建新记录
func (*CreateRecordRequest) Validate ¶
func (req *CreateRecordRequest) Validate() error
Validate 验证创建记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type CreateRecordResponse ¶
type CreateRecordResponse struct {
Record *Record `json:"record"` // 创建的记录信息
}
CreateRecordResponse 创建记录的响应结构 包含创建操作的结果和新创建的记录信息
type CreateTableRequest ¶
type CreateTableRequest struct {
Table *TableRequest `json:"table"` // 表的详细信息
}
CreateTableRequest 创建表的请求结构 用于在飞书多维表格中创建新的数据表
func (*CreateTableRequest) Validate ¶
func (req *CreateTableRequest) Validate() error
Validate 验证创建表请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type CreateTableResponse ¶
type CreateTableResponse struct {
TableID string `json:"table_id"` // 创建的表 ID
DefaultViewID string `json:"default_view_id"` // 默认视图 ID
}
CreateTableResponse 创建数据表的响应结构 包含创建操作的结果和新创建的表信息
func (*CreateTableResponse) GetDefaultViewID ¶
func (resp *CreateTableResponse) GetDefaultViewID() string
GetDefaultViewID 获取默认视图 ID 返回:
- string: 默认视图 ID
func (*CreateTableResponse) GetTableID ¶
func (resp *CreateTableResponse) GetTableID() string
GetTableID 获取创建的表 ID 返回:
- string: 表 ID
func (*CreateTableResponse) IsSuccess ¶
func (resp *CreateTableResponse) IsSuccess() bool
IsSuccess 判断创建表操作是否成功 返回:
- bool: 操作是否成功
type Dialector ¶
Dialector 实现了 GORM 的方言器接口,用于将 GORM 操作转换为飞书多维表格 API 调用 它包含了配置信息和客户端实例,是整个驱动的核心组件
func (*Dialector) BindVarTo ¶
BindVarTo 写入绑定变量占位符 实现 gorm.Dialector 接口的 BindVarTo 方法 参数:
- writer: 子句写入器
- stmt: GORM 语句
- v: 绑定的值
func (*Dialector) DataTypeOf ¶
DataTypeOf 将 GORM 字段类型转换为飞书多维表格字段类型 实现 gorm.Dialector 接口的 DataTypeOf 方法 参数:
- field: GORM 字段定义
返回:
- string: 对应的飞书多维表格字段类型
func (*Dialector) DefaultValueOf ¶
func (d *Dialector) DefaultValueOf(field *schema.Field) clause.Expression
DefaultValueOf 返回字段的默认值表达式 实现 gorm.Dialector 接口的 DefaultValueOf 方法 参数:
- field: GORM 字段定义
返回:
- clause.Expression: 默认值表达式
func (*Dialector) Explain ¶
Explain 解释 SQL 语句,用于调试和日志记录 实现 gorm.Dialector 接口的 Explain 方法 参数:
- sql: SQL 语句
- vars: 绑定变量
返回:
- string: 解释后的 SQL 语句
func (*Dialector) Initialize ¶
Initialize 初始化方言器 该方法会创建飞书 API 客户端、设置连接池并注册回调函数 参数:
- db: GORM 数据库实例
返回:
- error: 初始化过程中的错误
func (*Dialector) Migrator ¶
Migrator 返回数据库迁移器实例 实现 gorm.Dialector 接口的 Migrator 方法 参数:
- db: GORM 数据库实例
返回:
- gorm.Migrator: 迁移器实例
type Field ¶
type Field struct {
FieldID string `json:"field_id"` // 字段的唯一标识符
FieldName string `json:"field_name"` // 字段名称
Type FieldType `json:"type"` // 字段类型
Property map[string]interface{} `json:"property"` // 字段属性配置(如选项列表、格式设置等)
Description string `json:"description"` // 字段描述
IsPrimary bool `json:"is_primary"` // 是否为主键字段
}
Field 飞书多维表格的字段结构 表示表中的一个字段,包含字段的所有属性和配置信息
func (*Field) ConvertFromGoValue ¶
func (f *Field) ConvertFromGoValue(value interface{}) interface{}
ConvertFromGoValue 将 Go 语言标准类型转换为飞书多维表格字段值 该方法将 Go 类型转换为飞书 API 期望的格式,确保数据能正确提交到飞书 参数:
- value: Go 语言类型的值
返回:
- interface{}: 转换后的飞书 API 格式值,转换失败时返回 nil 或对应类型的零值
func (*Field) ConvertToGoValue ¶
func (f *Field) ConvertToGoValue(value interface{}) interface{}
ConvertToGoValue 将飞书多维表格字段值转换为 Go 语言标准类型 该方法提供了类型安全的转换,支持多种数据类型的智能转换 参数:
- value: 来自飞书 API 的原始字段值
返回:
- interface{}: 转换后的 Go 语言类型值,转换失败时返回对应类型的零值
func (*Field) UnmarshalJSON ¶
UnmarshalJSON 自定义 JSON 反序列化
type FieldType ¶
type FieldType int
FieldType 飞书多维表格字段类型枚举 定义了飞书多维表格支持的所有字段类型,每个类型对应一个唯一的数字标识
const ( FieldTypeText FieldType = 1 // 多行文本字段 FieldTypeNumber FieldType = 2 // 数字字段 FieldTypeSingleSelect FieldType = 3 // 单选字段 FieldTypeMultiSelect FieldType = 4 // 多选字段 FieldTypeDate FieldType = 5 // 日期字段 FieldTypeCheckbox FieldType = 7 // 复选框字段 FieldTypeUser FieldType = 11 // 人员字段 FieldTypePhone FieldType = 13 // 电话号码字段 FieldTypeURL FieldType = 15 // 超链接字段 FieldTypeAttachment FieldType = 17 // 附件字段 FieldTypeBarcode FieldType = 18 // 条码字段 FieldTypeProgress FieldType = 19 // 进度字段 FieldTypeCurrency FieldType = 20 // 货币字段 FieldTypeRating FieldType = 21 // 评分字段 FieldTypeFormula FieldType = 22 // 公式字段 FieldTypeLookup FieldType = 23 // 查找引用字段 FieldTypeCreatedTime FieldType = 1001 // 创建时间字段(系统字段) FieldTypeModifiedTime FieldType = 1002 // 最后更新时间字段(系统字段) FieldTypeCreatedUser FieldType = 1003 // 创建人字段(系统字段) FieldTypeModifiedUser FieldType = 1004 // 修改人字段(系统字段) FieldTypeAutoNumber FieldType = 1005 // 自动编号字段(系统字段) )
飞书多维表格支持的字段类型常量定义 这些常量与飞书 API 文档中的字段类型编号保持一致
type FilterCondition ¶
type FilterCondition struct {
FieldName string `json:"field_name"` // 字段名称
Operator string `json:"operator"` // 操作符(如 is、contains、isEmpty 等)
Value []interface{} `json:"value"` // 过滤值列表,支持不同类型
}
FilterCondition 过滤条件结构 用于定义记录查询时的过滤条件
func (*FilterCondition) Validate ¶
func (fc *FilterCondition) Validate() error
Validate 验证过滤条件的有效性 返回:
- error: 如果过滤条件无效,返回相应的错误信息
type FilterRequest ¶
type FilterRequest struct {
Conjunction string `json:"conjunction"` // 连接符(and 或 or)
Conditions []*FilterCondition `json:"conditions"` // 过滤条件列表
}
FilterRequest 过滤请求结构 用于组合多个过滤条件进行复杂查询
func (*FilterRequest) Validate ¶
func (fr *FilterRequest) Validate() error
Validate 验证过滤请求的有效性 返回:
- error: 如果过滤请求无效,返回相应的错误信息
type ListFieldsAPIResponse ¶
type ListFieldsAPIResponse struct {
Code int `json:"code"` // 响应码
Msg string `json:"msg"` // 响应消息
Data *ListFieldsResponse `json:"data"` // 实际数据
}
ListFieldsAPIResponse 飞书API查询字段的完整响应结构 包含飞书API标准的code、data、msg字段
type ListFieldsResponse ¶
type ListFieldsResponse struct {
Items []*Field `json:"items"` // 字段列表
}
ListFieldsResponse 查询字段的响应结构 包含表中所有字段的列表
func (*ListFieldsResponse) GetFieldByID ¶
func (resp *ListFieldsResponse) GetFieldByID(fieldID string) *Field
GetFieldByID 根据字段 ID 获取字段 参数:
- fieldID: 字段 ID
返回:
- *Field: 找到的字段,如果未找到返回 nil
func (*ListFieldsResponse) GetFieldByName ¶
func (resp *ListFieldsResponse) GetFieldByName(fieldName string) *Field
GetFieldByName 根据字段名称获取字段 参数:
- fieldName: 字段名称
返回:
- *Field: 找到的字段,如果未找到返回 nil
func (*ListFieldsResponse) GetFieldCount ¶
func (resp *ListFieldsResponse) GetFieldCount() int
GetFieldCount 获取字段数量 返回:
- int: 字段数量
func (*ListFieldsResponse) GetFields ¶
func (resp *ListFieldsResponse) GetFields() []*Field
GetFields 获取字段列表 返回:
- []*Field: 字段列表,如果操作失败返回空切片
func (*ListFieldsResponse) IsSuccess ¶
func (resp *ListFieldsResponse) IsSuccess() bool
IsSuccess 判断查询字段操作是否成功 返回:
- bool: 操作是否成功
type ListRecordsAPIResponse ¶
type ListRecordsAPIResponse struct {
Code int `json:"code"` // 响应码
Msg string `json:"msg"` // 响应消息
Data *ListRecordsResponse `json:"data"` // 实际数据
}
ListRecordsAPIResponse 飞书API列表记录的完整响应结构 包含飞书API标准的code、data、msg字段
type ListRecordsRequest ¶
type ListRecordsRequest struct {
ViewID string `json:"view_id,omitempty"` // 视图 ID,指定查询的视图
Filter *FilterRequest `json:"filter,omitempty"` // 过滤条件
Sort []string `json:"sort,omitempty"` // 排序条件
FieldNames []string `json:"field_names,omitempty"` // 指定返回的字段名列表
TextFieldAsArray bool `json:"text_field_as_array,omitempty"` // 文本字段是否以数组形式返回
UserIDType string `json:"user_id_type,omitempty"` // 用户 ID 类型
DisplayFormula bool `json:"display_formula,omitempty"` // 是否显示公式
AutomaticFields bool `json:"automatic_fields,omitempty"` // 是否包含自动字段
PageToken string `json:"page_token,omitempty"` // 分页标记
PageSize int `json:"page_size,omitempty"` // 每页记录数,最大 500
}
ListRecordsRequest 列表记录的请求结构 用于查询飞书多维表格中的记录列表
func (*ListRecordsRequest) Validate ¶
func (req *ListRecordsRequest) Validate() error
Validate 验证列表记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type ListRecordsResponse ¶
type ListRecordsResponse struct {
HasMore bool `json:"has_more"` // 是否还有更多数据
PageToken string `json:"page_token"` // 下一页的分页标记
Total int `json:"total"` // 总记录数
Items []*Record `json:"items"` // 记录列表
}
ListRecordsResponse 列表记录的响应结构 包含查询到的记录列表和分页信息
func (*ListRecordsResponse) GetRecords ¶
func (resp *ListRecordsResponse) GetRecords() []*Record
GetRecords 获取记录列表 返回:
- []*Record: 记录列表,如果没有数据返回空切片
func (*ListRecordsResponse) IsSuccess ¶
func (resp *ListRecordsResponse) IsSuccess() bool
IsSuccess 判断列表记录操作是否成功 返回:
- bool: 操作是否成功
type ListTablesAPIResponse ¶
type ListTablesAPIResponse struct {
Code int `json:"code"` // 响应码
Msg string `json:"msg"` // 响应消息
Data *ListTablesResponse `json:"data"` // 实际数据
}
ListTablesAPIResponse 飞书API查询数据表的完整响应结构 包含飞书API标准的code、data、msg字段
type ListTablesResponse ¶
type ListTablesResponse struct {
HasMore bool `json:"has_more"` // 是否还有更多数据
PageToken string `json:"page_token"` // 下一页的分页标记
Total int `json:"total"` // 总记录数
Items []*Table `json:"items"` // 表列表
}
ListTablesResponse 查询数据表的响应结构 包含多维表格中所有表的列表
func (*ListTablesResponse) GetTableByID ¶
func (resp *ListTablesResponse) GetTableByID(tableID string) *Table
GetTableByID 根据表 ID 获取表 参数:
- tableID: 表 ID
返回:
- *Table: 找到的表,如果未找到返回 nil
func (*ListTablesResponse) GetTableByName ¶
func (resp *ListTablesResponse) GetTableByName(tableName string) *Table
GetTableByName 根据表名称获取表 参数:
- tableName: 表名称
返回:
- *Table: 找到的表,如果未找到返回 nil
func (*ListTablesResponse) GetTableCount ¶
func (resp *ListTablesResponse) GetTableCount() int
GetTableCount 获取表数量 返回:
- int: 表数量
func (*ListTablesResponse) GetTables ¶
func (resp *ListTablesResponse) GetTables() []*Table
GetTables 获取表列表 返回:
- []*Table: 表列表,如果操作失败返回空切片
func (*ListTablesResponse) IsSuccess ¶
func (resp *ListTablesResponse) IsSuccess() bool
IsSuccess 判断查询表操作是否成功 返回:
- bool: 操作是否成功
type Migrator ¶
func (Migrator) AutoMigrate ¶
AutoMigrate 自动迁移表结构
func (Migrator) CreateTable ¶
CreateTable 创建表
func (Migrator) RunAutoMigrate ¶
RunAutoMigrate 执行自动迁移
func (Migrator) UpdateColumns ¶
UpdateColumns 更新列
type Option ¶
type Option struct {
ID string `json:"id"` // 选项的唯一标识符
Name string `json:"name"` // 选项名称
Color int `json:"color"` // 选项颜色代码
}
Option 飞书多维表格的选项结构 用于单选、多选等字段类型的选项定义
type Record ¶
type Record struct {
RecordID string `json:"record_id"` // 记录的唯一标识符
Fields map[string]interface{} `json:"fields"` // 记录的字段值映射,key 为字段名,value 为字段值
CreatedTime int64 `json:"created_time"` // 记录创建时间(毫秒时间戳)
LastModified int64 `json:"last_modified"` // 记录最后修改时间(毫秒时间戳)
CreatedBy *User `json:"created_by"` // 记录创建者信息
LastModifiedBy *User `json:"last_modified_by"` // 记录最后修改者信息
}
Record 飞书多维表格的记录结构 表示表中的一条数据记录,包含记录的所有字段值和元数据信息
func (*Record) GetFieldValue ¶
GetFieldValue 获取指定字段的值 参数:
- fieldName: 字段名称
返回:
- interface{}: 字段值,如果字段不存在返回 nil
- bool: 字段是否存在
type SQLConverter ¶
type SQLConverter struct {
// contains filtered or unexported fields
}
SQLConverter SQL 转换器 负责将 GORM 的 SQL 语句转换为飞书多维表格 API 调用 支持 CREATE、SELECT、UPDATE、DELETE 等基本操作
func NewSQLConverter ¶
func NewSQLConverter(client *Client, config *Config) *SQLConverter
NewSQLConverter 创建 SQL 转换器实例 参数:
- client: 已初始化的飞书 API 客户端
- config: 配置信息
返回:
- *SQLConverter: SQL 转换器实例
func (*SQLConverter) ConvertCreate ¶
ConvertCreate 转换 CREATE 语句为飞书多维表格的创建记录 API 调用 参数:
- ctx: 上下文,用于控制请求超时和取消
- stmt: GORM 语句对象,包含要创建的数据信息
返回:
- error: 转换或执行过程中的错误
func (*SQLConverter) ConvertDelete ¶
ConvertDelete 转换 DELETE 语句为飞书多维表格的删除记录 API 调用 参数:
- ctx: 上下文,用于控制请求超时和取消
- stmt: GORM 语句对象,包含删除条件信息
返回:
- error: 转换或执行过程中的错误
func (*SQLConverter) ConvertQuery ¶
ConvertQuery 转换 SELECT 语句为飞书多维表格的查询记录 API 调用 支持字段选择、WHERE 条件过滤、ORDER BY 排序等功能 参数:
- ctx: 上下文,用于控制请求超时和取消
- stmt: GORM 语句对象,包含查询条件和字段信息
返回:
- error: 转换或执行过程中的错误
func (*SQLConverter) ConvertUpdate ¶
ConvertUpdate 转换 UPDATE 语句为飞书多维表格的更新记录 API 调用 参数:
- ctx: 上下文,用于控制请求超时和取消
- stmt: GORM 语句对象,包含更新条件和字段信息
返回:
- error: 转换或执行过程中的错误
type Table ¶
type Table struct {
TableID string `json:"table_id"` // 表的唯一标识符
Name string `json:"name"` // 表名称
Revision int64 `json:"revision"` // 表的版本号,用于并发控制
Fields []*Field `json:"fields"` // 表中的所有字段列表
}
Table 飞书多维表格的数据表结构 表示一个完整的数据表,包含表的基本信息和所有字段定义
func (*Table) GetFieldByID ¶
GetFieldByID 根据字段 ID 获取字段 参数:
- fieldID: 字段 ID
返回:
- *Field: 找到的字段,如果未找到返回 nil
func (*Table) GetFieldByName ¶
GetFieldByName 根据字段名称获取字段 参数:
- fieldName: 字段名称
返回:
- *Field: 找到的字段,如果未找到返回 nil
type TableRequest ¶
type TableRequest struct {
Name string `json:"name"` // 表名称
DefaultViewName string `json:"default_view_name,omitempty"` // 默认视图名称
Fields []*CreateFieldRequest `json:"fields"` // 字段列表
}
TableRequest 表请求结构 包含创建表所需的所有信息
func (*TableRequest) Validate ¶
func (req *TableRequest) Validate() error
Validate 验证表请求的有效性 返回:
- error: 如果表请求无效,返回相应的错误信息
type TokenResponse ¶
type TokenResponse struct {
Code int `json:"code"` // 响应状态码,0 表示成功
Msg string `json:"msg"` // 响应消息
Expire int64 `json:"expire"` // 令牌有效期(秒)
Token string `json:"tenant_access_token"` // 租户访问令牌
}
TokenResponse 飞书 API 令牌响应结构
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction 实现 sql.driver.Tx 接口的事务结构体 用于兼容 GORM 的事务处理机制
func (*Transaction) ExecContext ¶
func (tx *Transaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext 执行语句 实现 gorm.ConnPool 接口
func (*Transaction) PrepareContext ¶
PrepareContext 准备语句 实现 gorm.ConnPool 接口
func (*Transaction) QueryContext ¶
func (tx *Transaction) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext 执行查询 实现 gorm.ConnPool 接口
func (*Transaction) QueryRowContext ¶
func (tx *Transaction) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryRowContext 执行单行查询 实现 gorm.ConnPool 接口
func (*Transaction) Rollback ¶
func (tx *Transaction) Rollback() error
Rollback 回滚事务 实现 sql.driver.Tx 接口
type UpdateRecordRequest ¶
type UpdateRecordRequest struct {
Fields map[string]interface{} `json:"fields"` // 要更新的字段值映射
}
UpdateRecordRequest 更新记录的请求结构 用于更新飞书多维表格中的现有记录
func (*UpdateRecordRequest) Validate ¶
func (req *UpdateRecordRequest) Validate() error
Validate 验证更新记录请求的有效性 返回:
- error: 如果请求结构无效,返回相应的错误信息
type UpdateRecordResponse ¶
type UpdateRecordResponse struct {
Record *Record `json:"record"` // 更新后的记录信息
}
UpdateRecordResponse 更新记录的响应结构 包含更新操作的结果和更新后的记录信息
func (*UpdateRecordResponse) GetRecord ¶
func (resp *UpdateRecordResponse) GetRecord() *Record
GetRecord 获取更新后的记录 返回:
- *Record: 更新后的记录,如果操作失败返回 nil
func (*UpdateRecordResponse) IsSuccess ¶
func (resp *UpdateRecordResponse) IsSuccess() bool
IsSuccess 判断更新记录操作是否成功 返回:
- bool: 操作是否成功
type User ¶
type User struct {
ID string `json:"id"` // 用户的唯一标识符
Name string `json:"name"` // 用户的中文名称
EnName string `json:"en_name"` // 用户的英文名称
Email string `json:"email"` // 用户的邮箱地址
}
User 飞书用户信息结构 表示飞书系统中的用户基本信息