diff --git a/db/resync.go b/db/resync.go deleted file mode 100644 index ab98ec8b..00000000 --- a/db/resync.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright © 2016 Abcum Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package db - -import ( - "github.com/abcum/surreal/kvs" - "github.com/abcum/surreal/sql" - "github.com/abcum/surreal/util/item" - "github.com/abcum/surreal/util/keys" -) - -func executeResyncIndexStatement(txn kvs.TX, ast *sql.ResyncIndexStatement) (out []interface{}, err error) { - - var local bool - - if ast.EX { - return append(out, ast), nil - } - - if txn == nil { - txn, err = db.Txn(true) - if err != nil { - return - } - defer txn.Rollback() - } - - for _, TB := range ast.What { - - // Remove all index data - dbeg := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, IX: keys.Prefix, FD: keys.Ignore} - dend := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, IX: keys.Suffix, FD: keys.Ignore} - if err := txn.RDel(dbeg.Encode(), dend.Encode(), 0); err != nil { - return nil, err - } - - // Fetch the items - ibeg := &keys.Thing{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, ID: keys.Prefix} - iend := &keys.Thing{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB, ID: keys.Suffix} - kvs, _ := txn.RGet(ibeg.Encode(), iend.Encode(), 0) - for _, kv := range kvs { - doc := item.New(kv, txn, nil) - if err := resync(doc, ast); err != nil { - return nil, err - } - } - - } - - if local { - txn.Commit() - } - - return - -} - -func resync(doc *item.Doc, ast *sql.ResyncIndexStatement) (err error) { - - if err = doc.StoreIndex(); err != nil { - return err - } - - return - -} diff --git a/sql/index.go b/sql/index.go index 832b5a08..a890b1dc 100644 --- a/sql/index.go +++ b/sql/index.go @@ -54,32 +54,6 @@ func (p *Parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexState } -func (p *Parser) parseResyncIndexStatement(explain bool) (stmt *ResyncIndexStatement, err error) { - - stmt = &ResyncIndexStatement{} - - stmt.EX = explain - - stmt.KV = p.c.Get("KV").(string) - stmt.NS = p.c.Get("NS").(string) - stmt.DB = p.c.Get("DB").(string) - - if _, _, err = p.shouldBe(ON); err != nil { - return nil, err - } - - if stmt.What, err = p.parseNames(); err != nil { - return nil, err - } - - if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { - return nil, err - } - - return - -} - func (p *Parser) parseRemoveIndexStatement(explain bool) (stmt *RemoveIndexStatement, err error) { stmt = &RemoveIndexStatement{} diff --git a/sql/parser.go b/sql/parser.go index c1ee278b..0182fe3a 100644 --- a/sql/parser.go +++ b/sql/parser.go @@ -116,7 +116,7 @@ func (p *Parser) ParseSingle() (Statement, error) { explain = true } - tok, _, err := p.shouldBe(USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, RESYNC, REMOVE) + tok, _, err := p.shouldBe(USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, REMOVE) switch tok { @@ -147,8 +147,6 @@ func (p *Parser) ParseSingle() (Statement, error) { case DEFINE: return p.parseDefineStatement(explain) - case RESYNC: - return p.parseResyncStatement(explain) case REMOVE: return p.parseRemoveStatement(explain) diff --git a/sql/resync.go b/sql/resync.go deleted file mode 100644 index 35aeb393..00000000 --- a/sql/resync.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright © 2016 Abcum Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package sql - -func (p *Parser) parseResyncStatement(explain bool) (Statement, error) { - - // Inspect the next token. - tok, _, err := p.shouldBe(INDEX) - - switch tok { - case INDEX: - return p.parseResyncIndexStatement(explain) - default: - return nil, err - } - -} diff --git a/sql/sql_test.go b/sql/sql_test.go index 1062d38f..2755d2e6 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -140,11 +140,11 @@ func Test_Parse_Queries_Malformed(t *testing.T) { }, { sql: `!`, - err: "Found `!` but expected `USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, RESYNC, REMOVE`", + err: "Found `!` but expected `USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, REMOVE`", }, { sql: `SELECT * FROM person;;;`, - err: "Found `;` but expected `USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, RESYNC, REMOVE`", + err: "Found `;` but expected `USE, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, REMOVE`", }, } @@ -1746,39 +1746,6 @@ func Test_Parse_Queries_Define(t *testing.T) { } -func Test_Parse_Queries_Resync(t *testing.T) { - - var tests = []tester{ - { - sql: `RESYNC`, - err: "Found `` but expected `INDEX`", - }, - { - sql: `RESYNC INDEX`, - err: "Found `` but expected `ON`", - }, - { - sql: `RESYNC INDEX ON`, - err: "Found `` but expected `name`", - }, - { - sql: `RESYNC INDEX ON person`, - res: &Query{Statements: []Statement{&ResyncIndexStatement{ - What: []string{"person"}, - }}}, - }, - { - sql: `RESYNC INDEX ON person something`, - err: "Found `something` but expected `EOF, ;`", - }, - } - - for _, test := range tests { - testsql(t, test) - } - -} - func Test_Parse_Queries_Remove(t *testing.T) { var tests = []tester{ diff --git a/sql/token.go b/sql/token.go index d3d9c859..6f48a2f9 100644 --- a/sql/token.go +++ b/sql/token.go @@ -167,7 +167,6 @@ const ( REJECT RELATE REMOVE - RESYNC RETURN ROLLBACK RULES @@ -329,7 +328,6 @@ var tokens = [...]string{ REJECT: "REJECT", RELATE: "RELATE", REMOVE: "REMOVE", - RESYNC: "RESYNC", RETURN: "RETURN", ROLLBACK: "ROLLBACK", RULES: "RULES",