Allow modifying whole tables with DIFFs

This commit is contained in:
Tobie Morgan Hitchcock 2016-09-07 16:58:37 +01:00
parent 020dbbe0c2
commit 2fb4791387
2 changed files with 15 additions and 1 deletions

View file

@ -51,6 +51,20 @@ func executeModifyStatement(txn kvs.TX, ast *sql.ModifyStatement) (out []interfa
}
}
if what, ok := w.(*sql.Table); ok {
beg := &keys.Thing{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: what.TB, ID: keys.Prefix}
end := &keys.Thing{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: what.TB, ID: keys.Suffix}
kvs, _ := txn.RGet(beg.Encode(), end.Encode(), 0)
for _, kv := range kvs {
doc := item.New(kv, txn, nil)
if ret, err := modify(doc, ast); err != nil {
return nil, err
} else if ret != nil {
out = append(out, ret)
}
}
}
}
if local {

View file

@ -24,7 +24,7 @@ func (p *Parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
if stmt.What, err = p.parseThings(); err != nil {
if stmt.What, err = p.parseWhat(); err != nil {
return nil, err
}