fix,upd module
This commit is contained in:
parent
3dfadd7a30
commit
fe3e02370c
|
@ -0,0 +1,30 @@
|
||||||
|
package sql
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// key,value To like sql
|
||||||
|
func Like(key, val string) string {
|
||||||
|
if val == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
key = strings.TrimSpace(key)
|
||||||
|
val = strings.TrimSpace(val)
|
||||||
|
return key + " LIKE '%" + val + "%'"
|
||||||
|
}
|
||||||
|
|
||||||
|
// map strings to like sqls
|
||||||
|
func Likes(in map[string]string) string {
|
||||||
|
var ar []string
|
||||||
|
for key, val := range in {
|
||||||
|
sql := Like(key, val)
|
||||||
|
if sql != "" {
|
||||||
|
ar = append(ar, sql)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ar) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(ar, " AND ")
|
||||||
|
}
|
|
@ -24,14 +24,14 @@ func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//控制台和文件同时输出日志
|
//控制台和文件同时输出日志
|
||||||
var newLogger = setLogger(vars.ServiceKey, options.LogStdout)
|
//var newLogger = setLogger(vars.ServiceKey, options.LogStdout)
|
||||||
|
|
||||||
gormDb, err := gorm.Open(postgres.New(postgres.Config{
|
gormDb, err := gorm.Open(postgres.New(postgres.Config{
|
||||||
DSN: dsn,
|
DSN: dsn,
|
||||||
// PreferSimpleProtocol: true, disables implicit prepared statement usage
|
// PreferSimpleProtocol: true, disables implicit prepared statement usage
|
||||||
|
|
||||||
}), &gorm.Config{
|
}), &gorm.Config{
|
||||||
Logger: newLogger,
|
//Logger:newLogger,
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
NamingStrategy: schema.NamingStrategy{
|
NamingStrategy: schema.NamingStrategy{
|
||||||
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
|
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
|
||||||
|
|
|
@ -14,7 +14,7 @@ var MeshEnv *types.MeshEnv = nil
|
||||||
func NewEnv() *types.MeshEnv {
|
func NewEnv() *types.MeshEnv {
|
||||||
if MeshEnv == nil {
|
if MeshEnv == nil {
|
||||||
MeshEnv = &types.MeshEnv{
|
MeshEnv = &types.MeshEnv{
|
||||||
Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"),
|
Workspace: GetEnvDefault("BlocksMesh_Workspace", "def"),
|
||||||
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
|
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
|
||||||
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Register(srvKey string, cfg any) {
|
||||||
// get config file.
|
// get config file.
|
||||||
cf := fmt.Sprintf("%s_%s.yaml", srvKey, env.MeshEnv.RuntimeMode)
|
cf := fmt.Sprintf("%s_%s.yaml", srvKey, env.MeshEnv.RuntimeMode)
|
||||||
cf = filepath.Join(env.MeshEnv.Prefix, "etc", cf)
|
cf = filepath.Join(env.MeshEnv.Prefix, "etc", cf)
|
||||||
|
print.Info("[Blocks Service] %s Config File: %s", vars.ServiceKey, cf)
|
||||||
configure.LoadYamlFile(cf, args, cfg)
|
configure.LoadYamlFile(cf, args, cfg)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue