From 2fb4791387774308d714ae52b70b59da1fc46ea1 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 7 Sep 2016 16:58:37 +0100 Subject: [PATCH] Allow modifying whole tables with DIFFs --- db/modify.go | 14 ++++++++++++++ sql/modify.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/db/modify.go b/db/modify.go index 479c54d6..5ccf0792 100644 --- a/db/modify.go +++ b/db/modify.go @@ -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 { diff --git a/sql/modify.go b/sql/modify.go index 406e4a80..2e268743 100644 --- a/sql/modify.go +++ b/sql/modify.go @@ -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 }