diff --git a/database/sql/ext.go b/database/sql/ext.go new file mode 100644 index 0000000..4ee3acd --- /dev/null +++ b/database/sql/ext.go @@ -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 ") +} diff --git a/database/sql/postgresql.go b/database/sql/postgresql.go index e0e6747..85391e6 100644 --- a/database/sql/postgresql.go +++ b/database/sql/postgresql.go @@ -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{ DSN: dsn, // PreferSimpleProtocol: true, disables implicit prepared statement usage }), &gorm.Config{ - Logger: newLogger, + //Logger:newLogger, DisableForeignKeyConstraintWhenMigrating: true, NamingStrategy: schema.NamingStrategy{ SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user` diff --git a/env/env.go b/env/env.go index 88d09bd..1e53608 100644 --- a/env/env.go +++ b/env/env.go @@ -14,7 +14,7 @@ var MeshEnv *types.MeshEnv = nil func NewEnv() *types.MeshEnv { if MeshEnv == nil { MeshEnv = &types.MeshEnv{ - Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"), + Workspace: GetEnvDefault("BlocksMesh_Workspace", "def"), JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"), RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")), } diff --git a/service/service.go b/service/service.go index c84de36..75fa6b8 100644 --- a/service/service.go +++ b/service/service.go @@ -34,7 +34,7 @@ func Register(srvKey string, cfg any) { // get config file. cf := fmt.Sprintf("%s_%s.yaml", srvKey, env.MeshEnv.RuntimeMode) cf = filepath.Join(env.MeshEnv.Prefix, "etc", cf) - + print.Info("[Blocks Service] %s Config File: %s", vars.ServiceKey, cf) configure.LoadYamlFile(cf, args, cfg) return