config

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INIT_FILE_NAME   = "init"
	CONN_FILE_NAME   = "conn"
	SINGLE_FILE_NAME = "models"
	QUERY_FILE_NAME  = "queries"
)

Variables

This section is empty.

Functions

func GetExtName

func GetExtName(fileName string) string

GetExtName 获取文件扩展名

func GetLevelString

func GetLevelString(lvl log.LogLevel) string

将 xorm 的日志级别转为字符串

func GetPresetTemplate added in v2.0.3

func GetPresetTemplate(name string) *template.Template

func LoadDataFile

func LoadDataFile(data interface{}, fileName string) error

LoadDataFile 加载配置文件

func MarshalFile

func MarshalFile(marshal MarshalFunc, data interface{}, fileName string) error

func NewTemplate added in v2.0.3

func NewTemplate(name, content string, funcs template.FuncMap) *template.Template

func RegisterLanguage added in v2.0.3

func RegisterLanguage(l *Language)

RegisterLanguage registers a language

func SaveDataFile

func SaveDataFile(data interface{}, fileName string) error

SaveDataFile 保存配置文件

func UnmarshalFile

func UnmarshalFile(unmarshal UnmarshalFunc, data interface{}, fileName string) error

Types

type Configure

type Configure struct {
	Connections   map[string]ConnConfig  `json:"connections" yaml:"connections" toml:"connections"`
	ReverseTarget ReverseTarget          `json:"reverse_target" yaml:"reverse_target" toml:"reverse_target"`
	Extras        map[string]interface{} `json:"extras,omitempty" yaml:"extras,omitempty" toml:"extras"`
}

func ReadSettings

func ReadSettings(fileName, nameSpace string) (*Configure, error)

func (*Configure) Autofix added in v2.0.4

func (cfg *Configure) Autofix(params map[string]interface{}, err error) error

func (Configure) GetConnConfig

func (cfg Configure) GetConnConfig(key string) (ConnConfig, bool)

func (Configure) GetConnConfigMap

func (cfg Configure) GetConnConfigMap(keys ...string) map[string]ConnConfig

func (Configure) GetReverseTarget

func (cfg Configure) GetReverseTarget(name string) ReverseTarget

func (*Configure) RemovePrivates

func (cfg *Configure) RemovePrivates()

type ConnConfig

type ConnConfig struct {
	DriverName  string             `json:"driver_name" yaml:"driver_name" toml:"driver_name"`
	TablePrefix string             `json:"table_prefix,omitempty" yaml:"table_prefix,omitempty" toml:"table_prefix"`
	LogFile     string             `json:"log_file,omitempty" yaml:"log_file,omitempty" toml:"log_file"`
	Params      dialect.ConnParams `json:"params" yaml:"params" toml:"params"`
}

func (ConnConfig) ConnectRedis

func (c ConnConfig) ConnectRedis(verbose bool) (redis.Conn, error)

func (ConnConfig) ConnectXorm

func (c ConnConfig) ConnectXorm(verbose bool) (*xorm.Engine, error)

type Formatter added in v2.0.3

type Formatter func(fileName string, sourceCode []byte) ([]byte, error)

type IConfigure added in v2.0.4

type IConfigure interface {
	Autofix(params map[string]interface{}, err error) error
}

type IReverseConfig

type IReverseConfig interface {
	GetReverseTarget(name string) ReverseTarget
	GetConnConfigMap(keys ...string) map[string]ConnConfig
	GetConnConfig(key string) (ConnConfig, bool)
}

type Importter added in v2.0.3

type Importter func(tables map[string]*schemas.Table) map[string]string

type Language added in v2.0.3

type Language struct {
	Name      string
	ExtName   string
	Template  string
	Types     map[string]string
	Funcs     template.FuncMap
	Formatter Formatter
	Importter Importter
	Packager  Packager
}

Language represents a languages supported when reverse codes

func GetLanguage added in v2.0.3

func GetLanguage(name string) *Language

GetLanguage returns a language if exists

func (*Language) FixTarget added in v2.0.3

func (l *Language) FixTarget(target *ReverseTarget)

type MarshalFunc

type MarshalFunc func(in interface{}) (out []byte, err error)

type Packager added in v2.0.3

type Packager func(targetDir string) string

type ReverseSource

type ReverseSource struct {
	DriverName   string `json:"driver_name" yaml:"driver_name" toml:"driver_name"`
	TablePrefix  string `json:"table_prefix,omitempty" yaml:"table_prefix,omitempty" toml:"table_prefix"`
	ImporterPath string `json:"importer_path,omitempty" yaml:"importer_path,omitempty" toml:"importer_path"`
	ConnStr      string `json:"conn_str" yaml:"conn_str" toml:"conn_str"`
	OptStr       string `json:"opt_str,omitempty" yaml:"opt_str,omitempty" toml:"opt_str"`
	// contains filtered or unexported fields
}

ReverseSource represents a reverse source which should be a database connection

func NewReverseSource

func NewReverseSource(c ConnConfig) (*ReverseSource, dialect.Dialect)

func (ReverseSource) Connect

func (r ReverseSource) Connect(verbose bool) (*xorm.Engine, redis.Conn, error)

type ReverseTarget

type ReverseTarget struct {
	Language          string   `json:"language" yaml:"language" toml:"language"`
	IncludeTables     []string `json:"include_tables" yaml:"include_tables" toml:"include_tables"`
	ExcludeTables     []string `json:"exclude_tables" yaml:"exclude_tables" toml:"exclude_tables"`
	InitNameSpace     string   `json:"init_name_space" yaml:"init_name_space" toml:"init_name_space"`
	OutputDir         string   `json:"output_dir" yaml:"output_dir" toml:"output_dir"`
	TemplatePath      string   `json:"template_path" yaml:"template_path" toml:"template_path"`
	QueryTemplatePath string   `json:"query_template_path,omitempty" yaml:"query_template_path,omitempty" toml:"query_template_path"`
	InitTemplatePath  string   `json:"init_template_path,omitempty" yaml:"init_template_path,omitempty" toml:"init_template_path"`

	TableMapper  string            `json:"table_mapper,omitempty" yaml:"table_mapper,omitempty" toml:"table_mapper"`
	ColumnMapper string            `json:"column_mapper,omitempty" yaml:"column_mapper,omitempty" toml:"column_mapper"`
	Funcs        map[string]string `json:"funcs,omitempty" yaml:"funcs,omitempty" toml:"funcs"`
	Formatter    string            `json:"formatter,omitempty" yaml:"formatter,omitempty,omitempty" toml:"formatter"`
	Importter    string            `json:"importter,omitempty" yaml:"importter,omitempty,omitempty" toml:"importter"`
	ExtName      string            `json:"-" yaml:"-" toml:"-"`
	NameSpace    string            `json:"-" yaml:"-" toml:"-"`

	MultipleFiles  bool   `json:"multiple_files" yaml:"multiple_files" toml:"multiple_files"`
	ApplyMixins    bool   `json:"apply_mixins" yaml:"apply_mixins" toml:"apply_mixins"`
	MixinDirPath   string `json:"mixin_dir_path,omitempty" yaml:"mixin_dir_path,omitempty" toml:"mixin_dir_path"`
	MixinNameSpace string `json:"mixin_name_space,omitempty" yaml:"mixin_name_space,omitempty" toml:"mixin_name_space"`
}

ReverseTarget represents a reverse target

func DefaultMixinReverseTarget

func DefaultMixinReverseTarget(nameSpace string) ReverseTarget

func DefaultReverseTarget

func DefaultReverseTarget(nameSpace string) ReverseTarget

func (ReverseTarget) GetFileName

func (t ReverseTarget) GetFileName(dir, name string) string

func (ReverseTarget) GetOutFileName

func (t ReverseTarget) GetOutFileName(name string) string

func (ReverseTarget) GetParentOutDir

func (t ReverseTarget) GetParentOutDir(backward int) string

func (ReverseTarget) GetParentOutFileName

func (t ReverseTarget) GetParentOutFileName(name string, backward int) string

func (ReverseTarget) RegularizeOptions

func (t ReverseTarget) RegularizeOptions(key string, src *ReverseSource) ReverseTarget

type SqlLogger

type SqlLogger struct {
	*logging.Logger
	// contains filtered or unexported fields
}

func NewSqlLogger

func NewSqlLogger(filename string) *SqlLogger

func (*SqlLogger) IsShowSQL

func (s *SqlLogger) IsShowSQL() bool

IsShowSQL implement ILogger

func (*SqlLogger) Level

func (s *SqlLogger) Level() log.LogLevel

Level implement ILogger

func (*SqlLogger) SetLevel

func (s *SqlLogger) SetLevel(l log.LogLevel)

SetLevel implement ILogger

func (*SqlLogger) ShowSQL

func (s *SqlLogger) ShowSQL(show ...bool)

ShowSQL implement ILogger

type UnmarshalFunc

type UnmarshalFunc func(in []byte, out interface{}) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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