forked from x/ContextOS
tce add mdb.set
This commit is contained in:
parent
5f328b5bc7
commit
10755ac5e2
@ -57,6 +57,8 @@ let g:syntastic_quiet_messages = { "regex": [
|
|||||||
\ "defined outside __init__",
|
\ "defined outside __init__",
|
||||||
\ "Catching too general exception Exception",
|
\ "Catching too general exception Exception",
|
||||||
\ "Exactly one space required before assignment",
|
\ "Exactly one space required before assignment",
|
||||||
|
\ "Too many lines in module",
|
||||||
|
\ "Invalid constant name",
|
||||||
\ ] }
|
\ ] }
|
||||||
|
|
||||||
Plug 'Valloric/YouCompleteMe'
|
Plug 'Valloric/YouCompleteMe'
|
||||||
@ -136,6 +138,7 @@ autocmd BufReadPost * normal `"
|
|||||||
autocmd BufNewFile,BufReadPost *.shy set filetype=shy
|
autocmd BufNewFile,BufReadPost *.shy set filetype=shy
|
||||||
autocmd BufNewFile,BufReadPost *.shy set commentstring=#%s
|
autocmd BufNewFile,BufReadPost *.shy set commentstring=#%s
|
||||||
autocmd BufNewFile,BufReadPost *.conf set filetype=nginx
|
autocmd BufNewFile,BufReadPost *.conf set filetype=nginx
|
||||||
|
autocmd BufNewFile,BufReadPost *.go set foldmethod=syntax
|
||||||
|
|
||||||
command! RR wa | source ~/.vimrc |e
|
command! RR wa | source ~/.vimrc |e
|
||||||
source ~/.vim_local
|
source ~/.vim_local
|
||||||
|
@ -3013,15 +3013,17 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
save := map[string]interface{}{}
|
save := map[string]interface{}{}
|
||||||
if action == "load" {
|
if action == "load" {
|
||||||
f, e := os.Open(which)
|
f, e := os.Open(which)
|
||||||
m.Assert(e)
|
if e != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
de := json.NewDecoder(f)
|
de := json.NewDecoder(f)
|
||||||
de.Decode(&save)
|
de.Decode(&save)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_field := m.Option("sort_field")
|
// sort_field := m.Option("sort_field")
|
||||||
sort_order := m.Option("sort_order")
|
// sort_order := m.Option("sort_order")
|
||||||
m.BackTrace(func(m *Message) bool {
|
m.BackTrace(func(m *Message) bool {
|
||||||
for k, v := range m.target.Configs {
|
for k, v := range m.target.Configs {
|
||||||
switch action {
|
switch action {
|
||||||
@ -3093,17 +3095,20 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
}
|
}
|
||||||
m.Meta["append"] = append(m.Meta["append"], k)
|
m.Meta["append"] = append(m.Meta["append"], k)
|
||||||
}
|
}
|
||||||
m.Log("fuck", "what %v", fields)
|
|
||||||
|
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
m.Add("append", "index", "0")
|
m.Add("append", "index", "0")
|
||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
if len(fields) == 0 || fields[k] {
|
if len(fields) == 0 || fields[k] {
|
||||||
m.Add("append", k, v)
|
switch value := v.(type) {
|
||||||
|
case float64:
|
||||||
|
m.Add("append", k, fmt.Sprintf("%d", int(value)))
|
||||||
|
default:
|
||||||
|
m.Add("append", k, fmt.Sprintf("%v", value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Log("fuck", "what %v", m.Meta)
|
|
||||||
case map[string]string:
|
case map[string]string:
|
||||||
m.Add("append", "index", "0")
|
m.Add("append", "index", "0")
|
||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
@ -3151,16 +3156,17 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
return all
|
return all
|
||||||
})
|
})
|
||||||
|
|
||||||
if m.Sort(sort_field, sort_order); m.Has("index") {
|
m.Table()
|
||||||
for i := 0; i < len(m.Meta["index"]); i++ {
|
// if m.Sort(sort_field, sort_order); m.Has("index") {
|
||||||
m.Meta["index"][i] = fmt.Sprintf("%d", i+offset)
|
// for i := 0; i < len(m.Meta["index"]); i++ {
|
||||||
}
|
// m.Meta["index"][i] = fmt.Sprintf("%d", i+offset)
|
||||||
}
|
// }
|
||||||
if m.Has("select") {
|
// }
|
||||||
m.Echo(m.Cap(m.Meta["select"][2], m.Meta[m.Meta["select"][1]][m.Optioni("select")]))
|
// if m.Has("select") {
|
||||||
} else {
|
// m.Echo(m.Cap(m.Meta["select"][2], m.Meta[m.Meta["select"][1]][m.Optioni("select")]))
|
||||||
m.Table()
|
// } else {
|
||||||
}
|
// m.Table()
|
||||||
|
// }
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case "save":
|
case "save":
|
||||||
@ -3456,7 +3462,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
m.Echo(arg[0], values...)
|
m.Echo(arg[0], values...)
|
||||||
m.Append("format", m.Result(0))
|
m.Append("format", m.Result(0))
|
||||||
}},
|
}},
|
||||||
"select": &Command{Name: "select key value", Form: map[string]int{"order": 2, "limit": 1, "offset": 1}, Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
"select": &Command{Name: "select key value", Form: map[string]int{"order": 2, "limit": 1, "offset": 1, "vertical": 1}, Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
msg := m.Spawn()
|
msg := m.Spawn()
|
||||||
offset := 0
|
offset := 0
|
||||||
limit := 10
|
limit := 10
|
||||||
@ -3482,6 +3488,20 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
if m.Set("append").Copy(msg, "append"); m.Has("order") {
|
if m.Set("append").Copy(msg, "append"); m.Has("order") {
|
||||||
m.Sort(m.Option("order"), m.Meta["order"][1])
|
m.Sort(m.Option("order"), m.Meta["order"][1])
|
||||||
}
|
}
|
||||||
|
if m.Has("vertical") {
|
||||||
|
msg := m.Spawn()
|
||||||
|
nrow := len(m.Meta[m.Meta["append"][0]])
|
||||||
|
sort.Strings(m.Meta["append"])
|
||||||
|
for i := 0; i < nrow; i++ {
|
||||||
|
for _, k := range m.Meta["append"] {
|
||||||
|
msg.Add("append", "field", k)
|
||||||
|
msg.Add("append", "value", m.Meta[k][i])
|
||||||
|
}
|
||||||
|
msg.Add("append", "field", "")
|
||||||
|
msg.Add("append", "value", "")
|
||||||
|
}
|
||||||
|
m.Set("append").Copy(msg, "append")
|
||||||
|
}
|
||||||
m.Table()
|
m.Table()
|
||||||
}},
|
}},
|
||||||
"import": &Command{Name: "import filename", Help: "导入数据", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
"import": &Command{Name: "import filename", Help: "导入数据", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
|
@ -274,6 +274,21 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
"set": &ctx.Command{Name: "set table [field value] where condition", Help: "查看或选择数据库信息", Form: map[string]int{"where": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) && mdb.DB != nil {
|
||||||
|
sql := []string{"update", arg[0], "set"}
|
||||||
|
for i := 1; i < len(arg)-1; i += 2 {
|
||||||
|
sql = append(sql, fmt.Sprintf("%s='%s'", arg[i], arg[i+1]))
|
||||||
|
if i < len(arg)-2 {
|
||||||
|
sql = append(sql, ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sql = append(sql, fmt.Sprintf("where %s", m.Option("where")))
|
||||||
|
m.Spawn().Cmd("exec", strings.Join(sql, " "))
|
||||||
|
msg := m.Spawn().Cmd("show", arg[0], "where", m.Option("where"))
|
||||||
|
m.Copy(msg, "result").Copy(msg, "append")
|
||||||
|
}
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user