mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
tce add mdb.show.extras
This commit is contained in:
parent
98c1a63871
commit
42ed326eaa
@ -141,6 +141,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
yac.Cmd("train", "stm", "function", "function", "rep{", "key", "}")
|
yac.Cmd("train", "stm", "function", "function", "rep{", "key", "}")
|
||||||
yac.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
yac.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
||||||
|
|
||||||
|
yac.Cmd("train", "cmd", "echo", "rep{", "exp", "}")
|
||||||
yac.Cmd("train", "cmd", "cmd", "cache", "rep{", "word", "}")
|
yac.Cmd("train", "cmd", "cmd", "cache", "rep{", "word", "}")
|
||||||
yac.Cmd("train", "cmd", "cmd", "cache", "key", "rep{", "word", "}")
|
yac.Cmd("train", "cmd", "cmd", "cache", "key", "rep{", "word", "}")
|
||||||
yac.Cmd("train", "cmd", "cmd", "cache", "key", "opt{", "=", "exp", "}")
|
yac.Cmd("train", "cmd", "cmd", "cache", "key", "opt{", "=", "exp", "}")
|
||||||
@ -833,6 +834,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Echo("%d\n", i)
|
m.Echo("%d\n", i)
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
"echo": &ctx.Command{Name: "echo arg...", Help: "函数调用, name: 函数名, arg: 参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Echo("%s", strings.Join(arg, ""))
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
Index: map[string]*ctx.Context{
|
Index: map[string]*ctx.Context{
|
||||||
"void": &ctx.Context{Name: "void",
|
"void": &ctx.Context{Name: "void",
|
||||||
|
@ -1198,9 +1198,34 @@ func (m *Message) Table(cb func(map[string]string, []string, int) bool) *Message
|
|||||||
for _, k := range m.Meta["append"] {
|
for _, k := range m.Meta["append"] {
|
||||||
data := m.Meta[k][i]
|
data := m.Meta[k][i]
|
||||||
if m.Options("extras") && k == "extra" {
|
if m.Options("extras") && k == "extra" {
|
||||||
extra := map[string]interface{}{}
|
var extra interface{}
|
||||||
json.Unmarshal([]byte(data), &extra)
|
json.Unmarshal([]byte(data), &extra)
|
||||||
data = fmt.Sprintf("%v", extra[m.Option("extras")])
|
for _, k := range m.Meta["extras"] {
|
||||||
|
if i, e := strconv.Atoi(k); e == nil && i >= 0 {
|
||||||
|
if d, ok := extra.([]interface{}); ok && i < len(d) {
|
||||||
|
extra = d[i]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if d, ok := extra.(map[string]interface{}); ok {
|
||||||
|
extra = d[k]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
extra = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if extra == nil {
|
||||||
|
data = ""
|
||||||
|
} else {
|
||||||
|
format := m.Confx("extra_format")
|
||||||
|
if format == "" {
|
||||||
|
format = "%v"
|
||||||
|
}
|
||||||
|
data = fmt.Sprintf(format, extra)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i < len(m.Meta[k]) {
|
if i < len(m.Meta[k]) {
|
||||||
@ -1567,11 +1592,11 @@ func (m *Message) Exec(key string, arg ...string) string { // {{{
|
|||||||
n += len(arg) - i
|
n += len(arg) - i
|
||||||
}
|
}
|
||||||
|
|
||||||
if x, ok := m.Meta[arg[i]]; ok && len(x) == n {
|
// if x, ok := m.Meta[arg[i]]; ok && len(x) == n {
|
||||||
m.Add("option", "args", arg[i])
|
// m.Add("option", "args", arg[i])
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
m.Add("option", arg[i], arg[i+1:i+1+n]...)
|
m.Add("option", arg[i], arg[i+1:i+1+n]...)
|
||||||
i += n
|
i += n
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
"show": &ctx.Command{
|
"show": &ctx.Command{
|
||||||
Name: "show table fields... [where conditions] [group fields] [order fields] [limit fields] [offset fields] [save filename] [other rest...]",
|
Name: "show table fields... [where conditions] [group fields] [order fields] [limit fields] [offset fields] [save filename] [other rest...]",
|
||||||
Help: "查询数据库, table: 表名, fields: 字段, where: 查询条件, group: 聚合字段, order: 排序字段",
|
Help: "查询数据库, table: 表名, fields: 字段, where: 查询条件, group: 聚合字段, order: 排序字段",
|
||||||
Form: map[string]int{"where": 1, "group": 1, "order": 1, "limit": 1, "offset": 1, "extras": 1, "save": 1, "export": 1, "other": -1},
|
Form: map[string]int{"where": 1, "group": 1, "order": 1, "limit": 1, "offset": 1, "extras": 1, "extra_format": 1, "trans_field": 1, "trans_map": 2, "save": 1, "export": 1, "other": -1},
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) { // {{{
|
if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) { // {{{
|
||||||
table := m.Confx("table", arg, 0)
|
table := m.Confx("table", arg, 0)
|
||||||
@ -281,10 +281,21 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
m.Color(31, table).Echo(" %s %s %s %s %s %v\n", where, group, order, limit, offset, m.Meta["other"])
|
m.Color(31, table).Echo(" %s %s %s %s %s %v\n", where, group, order, limit, offset, m.Meta["other"])
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Table(func(maps map[string]string, lists []string, line int) bool {
|
m.Table(func(maps map[string]string, lists []string, line int) bool {
|
||||||
for i, v := range lists {
|
for i, v := range lists {
|
||||||
if m.Options("save") {
|
if m.Options("save") {
|
||||||
m.Echo(maps[msg.Meta["append"][i]])
|
key := m.Meta["append"][i]
|
||||||
|
value := maps[key]
|
||||||
|
if key == m.Option("trans_field") {
|
||||||
|
for i := 0; i < len(m.Meta["trans_map"])-1; i += 2 {
|
||||||
|
if value == m.Meta["trans_map"][i] {
|
||||||
|
value = m.Meta["trans_map"][i+1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Echo(value)
|
||||||
} else if line == -1 {
|
} else if line == -1 {
|
||||||
m.Color(32, v)
|
m.Color(32, v)
|
||||||
} else {
|
} else {
|
||||||
@ -305,7 +316,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
|
|
||||||
table_name := path.Base(m.Option("export"))
|
table_name := path.Base(m.Option("export"))
|
||||||
|
|
||||||
msg.Table(func(maps map[string]string, lists []string, line int) bool {
|
m.Table(func(maps map[string]string, lists []string, line int) bool {
|
||||||
if line == -1 {
|
if line == -1 {
|
||||||
f.WriteString("insert into ")
|
f.WriteString("insert into ")
|
||||||
f.WriteString(table_name)
|
f.WriteString(table_name)
|
||||||
@ -316,7 +327,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
if line != -1 {
|
if line != -1 {
|
||||||
f.WriteString("'")
|
f.WriteString("'")
|
||||||
}
|
}
|
||||||
f.WriteString(maps[msg.Meta["append"][i]])
|
f.WriteString(maps[m.Meta["append"][i]])
|
||||||
if line != -1 {
|
if line != -1 {
|
||||||
f.WriteString("'")
|
f.WriteString("'")
|
||||||
}
|
}
|
||||||
@ -384,6 +395,11 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
|
"demo": &ctx.Command{Name: "get field offset table where [parse func field]", Help: "执行查询语句",
|
||||||
|
Form: map[string]int{"parse": 1},
|
||||||
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Echo("%v", m.Meta)
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
Index: map[string]*ctx.Context{
|
Index: map[string]*ctx.Context{
|
||||||
"void": &ctx.Context{Name: "void",
|
"void": &ctx.Context{Name: "void",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user