setting

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_DIR_MODE  = 0o755
	DEFAULT_FILE_MODE = 0o644
)
View Source
const (
	INIT_FILE_NAME   = "init"
	CONN_FILE_NAME   = "conn"
	SINGLE_FILE_NAME = "models"
	QUERY_FILE_NAME  = "queries"

	XORM_TAG_NAME        = "xorm"
	XORM_TAG_NOT_NULL    = "notnull"
	XORM_TAG_AUTO_INCR   = "autoincr"
	XORM_TAG_PRIMARY_KEY = "pk"
	XORM_TAG_UNIQUE      = "unique"
	XORM_TAG_INDEX       = "index"
)

Variables

This section is empty.

Functions

func GetLevelString

func GetLevelString(lvl log.LogLevel) string

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

func ReadSettingsFrom

func ReadSettingsFrom(fileName string, cfg interface{}) error

func ReverseSource2RedisDialect

func ReverseSource2RedisDialect(r *ReverseSource) *dialect.Redis

func SaveSettingsTo

func SaveSettingsTo(fileName string, cfg interface{}) error

func Settings2Bytes

func Settings2Bytes(cfg interface{}) []byte

Types

type AppConfig

type AppConfig struct {
	Debug       bool                   `json:"debug" yaml:"debug"`
	PluralTable bool                   `json:"plural_table" yaml:"plural_table"`
	Version     string                 `json:"version" yaml:"version"`
	Options     map[string]interface{} `json:"options" yaml:"options"`
}

type Configure

type Configure struct {
	Application    AppConfig             `json:"application" yaml:"application"`
	Logging        LogConfig             `json:"logging" yaml:"logging"`
	Connections    map[string]ConnConfig `json:"connections" yaml:"connections"`
	ReverseTargets []ReverseTarget       `json:"reverse_targets" yaml:"reverse_targets"`
}

func ReadSettings

func ReadSettings(fileName string) (*Configure, 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) GetReverseTargets

func (cfg Configure) GetReverseTargets() []ReverseTarget

type ConnConfig

type ConnConfig struct {
	DriverName string                          `json:"driver_name" yaml:"driver_name"`
	ReadOnly   bool                            `json:"read_only" yaml:"read_only"`
	Params     dialect.ConnParams              `json:"params" yaml:"params"`
	PartConfig `json:",inline" yaml:",inline"` // 注意逗号不能少
}

type DataSource

type DataSource struct {
	ConnKey      string
	ImporterPath string
	PartConfig
	*ReverseSource
}

func NewDataSource

func NewDataSource(c ConnConfig, name string) *DataSource

func (DataSource) GetDriverName

func (ds DataSource) GetDriverName() string

type IConnectConfig

type IConnectConfig interface {
	GetConnConfigMap(keys ...string) map[string]ConnConfig
	GetConnConfig(key string) (ConnConfig, bool)
}

type IReverseConfig

type IReverseConfig interface {
	GetReverseTargets() []ReverseTarget
	IConnectConfig
}

type LogConfig

type LogConfig struct {
	AccessFile string `json:"access_file" yaml:"access_file"`
	ErrorFile  string `json:"error_file" yaml:"error_file"`
	SqlFile    string `json:"sql_file" yaml:"sql_file"`
}

type PartConfig

type PartConfig struct {
	TablePrefix   string   `json:"table_prefix" yaml:"table_prefix"`
	IncludeTables []string `json:"include_tables" yaml:"include_tables"`
	ExcludeTables []string `json:"exclude_tables" yaml:"exclude_tables"`
}

type ReverseConfig

type ReverseConfig struct {
	Kind    string          `yaml:"kind"`
	Name    string          `yaml:"name"`
	Source  ReverseSource   `yaml:"source"`
	Targets []ReverseTarget `yaml:"targets"`
}

ReverseConfig represents a reverse configuration

type ReverseSource

type ReverseSource struct {
	Database string `yaml:"database"`
	ConnStr  string `yaml:"conn_str"`
	OptStr   string `yaml:"opt_str"`
}

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, error)

type ReverseTarget

type ReverseTarget struct {
	Type              string   `yaml:"type"`
	IncludeTables     []string `yaml:"include_tables"`
	ExcludeTables     []string `yaml:"exclude_tables"`
	TableMapper       string   `yaml:"table_mapper"`
	ColumnMapper      string   `yaml:"column_mapper"`
	TemplatePath      string   `yaml:"template_path"`
	QueryTemplatePath string   `yaml:"query_template_path"`
	InitTemplatePath  string   `yaml:"init_template_path"`
	InitNameSpace     string   `yaml:"init_name_space"`
	MultipleFiles     bool     `yaml:"multiple_files"`
	OutputDir         string   `yaml:"output_dir"`
	TablePrefix       string   `yaml:"table_prefix"`
	Language          string   `yaml:"language"`

	Funcs     map[string]string `yaml:"funcs"`
	Formatter string            `yaml:"formatter"`
	Importter string            `yaml:"importter"`
	ExtName   string            `yaml:"ext_name"`

	NameSpace       string `yaml:"name_space"`
	GenJsonTag      bool   `yaml:"gen_json_tag"`
	GenTableName    bool   `yaml:"gen_table_name"`
	GenQueryMethods bool   `yaml:"gen_query_methods"`
	ApplyMixins     bool   `yaml:"apply_mixins"`
	MixinDirPath    string `yaml:"mixin_dir_path"`
	MixinNameSpace  string `yaml:"mixin_name_space"`
}

ReverseTarget represents a reverse target

func (ReverseTarget) GetFileName

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

func (ReverseTarget) GetOutFileName

func (t ReverseTarget) GetOutFileName(name string) string

func (ReverseTarget) GetParentOutFileName

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

func (ReverseTarget) MergeOptions

func (t ReverseTarget) MergeOptions(name string, part PartConfig) 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 SqlTag

type SqlTag struct {
	reflect.StructTag
	// contains filtered or unexported fields
}

StructTag named sql or xorm

func NewSqlTag

func NewSqlTag() *SqlTag

func (*SqlTag) Delete

func (st *SqlTag) Delete(key string)

Deletes a tag

func (*SqlTag) Get

func (st *SqlTag) Get(key string) (string, bool)

Returns a tag from the tag data

func (*SqlTag) ParseTag

func (st *SqlTag) ParseTag(tag reflect.StructTag)

func (*SqlTag) Set

func (st *SqlTag) Set(key, val string)

Sets a tag in the tag data map

func (*SqlTag) String

func (st *SqlTag) String(head string) string

转为字符串格式,头通常使用sql或xorm

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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