Documentation ¶
Index ¶
- Variables
- func InitMongoClient(cfg MongoConfig) error
- type Client
- type Config
- type MongoCollection
- type MongoCollectionImp
- func (m MongoCollectionImp) InsertMany(ctx context.Context, models []interface{}) ([]interface{}, error)
- func (m MongoCollectionImp) InsertOne(ctx context.Context, model interface{}) (interface{}, error)
- func (m MongoCollectionImp) QueryList(ctx context.Context, filter interface{}, sort interface{}) ([]interface{}, error)
- func (m MongoCollectionImp) QueryOne(ctx context.Context, filter interface{}) (interface{}, error)
- type MongoConfig
- type StructColumn
- type StructTemplate
- type StructTemplateDB
Constants ¶
This section is empty.
Variables ¶
View Source
var MongoClient *mongo.Client
Functions ¶
func InitMongoClient ¶
func InitMongoClient(cfg MongoConfig) error
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GetTableColumnInfo ¶
func (c *Client) GetTableColumnInfo(dbName, tableName string) ([]*define.TableColumn, error)
GetTableColumnInfo 查询 information_schema.COLUMNS 表,获取指定表的列信息
func (*Client) GetTableDDL ¶
GetTableDDL 获取表结构
type Config ¶
type Config struct { DBType string `toml:"DBType" yaml:"db_type"` // 数据库驱动类型 Host string `toml:"Host" yaml:"host"` // 主机地址 Port int `toml:"Port" yaml:"port"` // 端口号 DBName string `toml:"DBName" yaml:"db_name"` // 数据库名 UserName string `toml:"UserName" yaml:"user_name"` // 用户名 PassWord string `toml:"PassWord" yaml:"pass_word"` // 密码 CharSet string `toml:"CharSet" yaml:"char_set"` // 字符集 MaxIdleConns int `toml:"MaxIdleConns" yaml:"max_idle_conns"` MaxOpenConns int `toml:"MaxOpenConns" yaml:"max_open_conns"` ConnMaxLifetime int `toml:"ConnMaxLifetime" yaml:"conn_max_lifetime"` LogMode bool `toml:"LogMode" yaml:"log_mode"` }
Config 数据库配置
type MongoCollection ¶
type MongoCollection interface { // QueryList 查询列表 QueryList(ctx context.Context, filter interface{}, sort interface{}) ([]interface{}, error) // QueryOne 查询单条 QueryOne(ctx context.Context, filter interface{}) (interface{}, error) // InsertOne 插入单条 InsertOne(ctx context.Context, model interface{}) (interface{}, error) // InsertMany 插入多条 InsertMany(ctx context.Context, models []interface{}) ([]interface{}, error) }
func NewMongoCollection ¶
func NewMongoCollection(database, collection string) MongoCollection
type MongoCollectionImp ¶
type MongoCollectionImp struct {
Collection *mongo.Collection
}
func (MongoCollectionImp) InsertMany ¶
func (m MongoCollectionImp) InsertMany(ctx context.Context, models []interface{}) ([]interface{}, error)
func (MongoCollectionImp) InsertOne ¶
func (m MongoCollectionImp) InsertOne(ctx context.Context, model interface{}) (interface{}, error)
type MongoConfig ¶
type MongoConfig struct { UserName string `toml:"UserName" yaml:"user_name"` // 用户名 PassWord string `toml:"PassWord" yaml:"pass_word"` // 密码 Host string `toml:"Host" yaml:"host"` // 主机地址 AuthSource string `toml:"AuthSource" yaml:"auth_source"` // 验证源 DefaultTimeout string `toml:"DefaultTimeout" yaml:"default_timeout"` // 默认超时时间 MaxPoolSize uint64 `toml:"MaxPoolSize" yaml:"max_pool_size"` // 连接池最大数 }
func (MongoConfig) GetDefaultTimeout ¶
func (cfg MongoConfig) GetDefaultTimeout() time.Duration
type StructColumn ¶
StructColumn 存储转换后的 Go 结构体中的所有字段信息
type StructTemplate ¶
type StructTemplate struct { FilePath string // 输出文件路径 // contains filtered or unexported fields }
func NewStructTemplate ¶
func NewStructTemplate() *StructTemplate
func (*StructTemplate) AssemblyColumns ¶
func (t *StructTemplate) AssemblyColumns(tbColumns []*define.TableColumn) []*StructColumn
AssemblyColumns 对通过查询 COLUMNS 表所组装得到的 tbColumns 进行进一步的分解和转换
func (*StructTemplate) Generate ¶
func (t *StructTemplate) Generate(tableName string, tmpColumns []*StructColumn) error
Generate 用转换之后的结构体去渲染模版 template.Must 方法判断返回的 *Template 是否有错误,引发panic,导致程序崩溃(如果模版解析错误,则直接让程序挂掉)
type StructTemplateDB ¶
type StructTemplateDB struct { TableName string Columns []*StructColumn }
StructTemplateDB 存储最终用于渲染的模版对象信息
Source Files ¶
Click to show internal directories.
Click to hide internal directories.