From 261aff0ee2626d8b24d481fb5db8f31790a1d1a2 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 9 Jan 2019 17:14:13 +0000 Subject: [PATCH] =?UTF-8?q?Use=20=E2=80=98access=E2=80=99=20variable=20nam?= =?UTF-8?q?e=20instead=20of=20=E2=80=98options=E2=80=99=20on=20parser=20ob?= =?UTF-8?q?ject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/{options.go => access.go} | 12 ++++++------ sql/create.go | 2 +- sql/database.go | 4 ++-- sql/delete.go | 2 +- sql/event.go | 4 ++-- sql/field.go | 4 ++-- sql/index.go | 4 ++-- sql/info.go | 10 +++++----- sql/insert.go | 2 +- sql/let.go | 2 +- sql/live.go | 4 ++-- sql/login.go | 8 ++++---- sql/namespace.go | 4 ++-- sql/parser.go | 4 ++-- sql/relate.go | 2 +- sql/return.go | 2 +- sql/scope.go | 4 ++-- sql/select.go | 2 +- sql/table.go | 4 ++-- sql/token.go | 12 ++++++------ sql/update.go | 2 +- sql/upsert.go | 2 +- sql/use.go | 4 ++-- 23 files changed, 50 insertions(+), 50 deletions(-) rename sql/{options.go => access.go} (91%) diff --git a/sql/options.go b/sql/access.go similarity index 91% rename from sql/options.go rename to sql/access.go index e330684a..2d5d43f4 100644 --- a/sql/options.go +++ b/sql/access.go @@ -33,17 +33,17 @@ const ( ) // options represents context runtime config. -type options struct { +type access struct { auth *cnf.Auth } -func newOptions(c *fibre.Context) *options { - return &options{ +func newAccess(c *fibre.Context) *access { + return &access{ auth: c.Get("auth").(*cnf.Auth), } } -func (o *options) get(kind int) (kv, ns, db string, err error) { +func (o *access) get(kind int) (kv, ns, db string, err error) { kv = cnf.Settings.DB.Base ns = o.auth.Selected.NS @@ -68,7 +68,7 @@ func (o *options) get(kind int) (kv, ns, db string, err error) { } -func (o *options) ns(ns string) (err error) { +func (o *access) ns(ns string) (err error) { // Check to see that the current user has // the necessary authentication privileges @@ -94,7 +94,7 @@ func (o *options) ns(ns string) (err error) { } -func (o *options) db(db string) (err error) { +func (o *access) db(db string) (err error) { // Check to see that the current user has // the necessary authentication privileges diff --git a/sql/create.go b/sql/create.go index 564fb5f7..8f3547d6 100644 --- a/sql/create.go +++ b/sql/create.go @@ -18,7 +18,7 @@ func (p *parser) parseCreateStatement() (stmt *CreateStatement, err error) { stmt = &CreateStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/database.go b/sql/database.go index 3f5a2b7c..ffb89c17 100644 --- a/sql/database.go +++ b/sql/database.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineDatabaseStatement() (stmt *DefineDatabaseStatement, stmt = &DefineDatabaseStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } @@ -34,7 +34,7 @@ func (p *parser) parseRemoveDatabaseStatement() (stmt *RemoveDatabaseStatement, stmt = &RemoveDatabaseStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } diff --git a/sql/delete.go b/sql/delete.go index a36849be..1e1bd3b2 100644 --- a/sql/delete.go +++ b/sql/delete.go @@ -18,7 +18,7 @@ func (p *parser) parseDeleteStatement() (stmt *DeleteStatement, err error) { stmt = &DeleteStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/event.go b/sql/event.go index c74be8f3..22fe0017 100644 --- a/sql/event.go +++ b/sql/event.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineEventStatement() (stmt *DefineEventStatement, err er stmt = &DefineEventStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } @@ -58,7 +58,7 @@ func (p *parser) parseRemoveEventStatement() (stmt *RemoveEventStatement, err er stmt = &RemoveEventStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } diff --git a/sql/field.go b/sql/field.go index c9672c87..9c5eeb75 100644 --- a/sql/field.go +++ b/sql/field.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineFieldStatement() (stmt *DefineFieldStatement, err er stmt = &DefineFieldStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } @@ -81,7 +81,7 @@ func (p *parser) parseRemoveFieldStatement() (stmt *RemoveFieldStatement, err er stmt = &RemoveFieldStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } diff --git a/sql/index.go b/sql/index.go index 7d9f9b60..72781cc9 100644 --- a/sql/index.go +++ b/sql/index.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineIndexStatement() (stmt *DefineIndexStatement, err er stmt = &DefineIndexStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } @@ -52,7 +52,7 @@ func (p *parser) parseRemoveIndexStatement() (stmt *RemoveIndexStatement, err er stmt = &RemoveIndexStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } diff --git a/sql/info.go b/sql/info.go index 6044c186..eaabbc00 100644 --- a/sql/info.go +++ b/sql/info.go @@ -27,25 +27,25 @@ func (p *parser) parseInfoStatement() (stmt *InfoStatement, err error) { } if is(stmt.Kind, ALL) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthKV); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthKV); err != nil { return nil, err } } if is(stmt.Kind, NAMESPACE, NS) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } } if is(stmt.Kind, DATABASE, DB) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } } if is(stmt.Kind, SCOPE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } if stmt.What, err = p.parseIdent(); err != nil { @@ -54,7 +54,7 @@ func (p *parser) parseInfoStatement() (stmt *InfoStatement, err error) { } if is(stmt.Kind, TABLE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } if stmt.What, err = p.parseIdent(); err != nil { diff --git a/sql/insert.go b/sql/insert.go index ecfcee65..cb275454 100644 --- a/sql/insert.go +++ b/sql/insert.go @@ -18,7 +18,7 @@ func (p *parser) parseInsertStatement() (stmt *InsertStatement, err error) { stmt = &InsertStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/let.go b/sql/let.go index cf0e1ce8..8a6c1127 100644 --- a/sql/let.go +++ b/sql/let.go @@ -18,7 +18,7 @@ func (p *parser) parseLetStatement() (stmt *LetStatement, err error) { stmt = &LetStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/live.go b/sql/live.go index ac73b3c3..51de58b2 100644 --- a/sql/live.go +++ b/sql/live.go @@ -18,7 +18,7 @@ func (p *parser) parseLiveStatement() (stmt *LiveStatement, err error) { stmt = &LiveStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } @@ -62,7 +62,7 @@ func (p *parser) parseKillStatement() (stmt *KillStatement, err error) { stmt = &KillStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/login.go b/sql/login.go index 21a06eb6..ed37947d 100644 --- a/sql/login.go +++ b/sql/login.go @@ -31,13 +31,13 @@ func (p *parser) parseDefineLoginStatement() (stmt *DefineLoginStatement, err er } if is(stmt.Kind, NAMESPACE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } } if is(stmt.Kind, DATABASE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } } @@ -80,13 +80,13 @@ func (p *parser) parseRemoveLoginStatement() (stmt *RemoveLoginStatement, err er } if is(stmt.Kind, NAMESPACE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } } if is(stmt.Kind, DATABASE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } } diff --git a/sql/namespace.go b/sql/namespace.go index be7a30cc..53647da5 100644 --- a/sql/namespace.go +++ b/sql/namespace.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineNamespaceStatement() (stmt *DefineNamespaceStatement stmt = &DefineNamespaceStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthKV); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthKV); err != nil { return nil, err } @@ -34,7 +34,7 @@ func (p *parser) parseRemoveNamespaceStatement() (stmt *RemoveNamespaceStatement stmt = &RemoveNamespaceStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthKV); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthKV); err != nil { return nil, err } diff --git a/sql/parser.go b/sql/parser.go index 435f50e5..cc27ee79 100644 --- a/sql/parser.go +++ b/sql/parser.go @@ -25,7 +25,7 @@ import ( // parser represents a parser. type parser struct { s *scanner - o *options + a *access c *fibre.Context buf struct { n int // buffer size @@ -55,7 +55,7 @@ func Parse(c *fibre.Context, i interface{}) (*Query, error) { // newParser returns a new instance of Parser. func newParser(c *fibre.Context) *parser { - return &parser{c: c, o: newOptions(c)} + return &parser{c: c, a: newAccess(c)} } // parseBytes parses a byte array. diff --git a/sql/relate.go b/sql/relate.go index 96acb368..03144828 100644 --- a/sql/relate.go +++ b/sql/relate.go @@ -18,7 +18,7 @@ func (p *parser) parseRelateStatement() (stmt *RelateStatement, err error) { stmt = &RelateStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/return.go b/sql/return.go index 7b02a7b6..18c7a6eb 100644 --- a/sql/return.go +++ b/sql/return.go @@ -18,7 +18,7 @@ func (p *parser) parseReturnStatement() (stmt *ReturnStatement, err error) { stmt = &ReturnStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/scope.go b/sql/scope.go index 56397fc4..925a17dc 100644 --- a/sql/scope.go +++ b/sql/scope.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineScopeStatement() (stmt *DefineScopeStatement, err er stmt = &DefineScopeStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } @@ -90,7 +90,7 @@ func (p *parser) parseRemoveScopeStatement() (stmt *RemoveScopeStatement, err er stmt = &RemoveScopeStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } diff --git a/sql/select.go b/sql/select.go index 9ebd5e3f..7d1c403f 100644 --- a/sql/select.go +++ b/sql/select.go @@ -18,7 +18,7 @@ func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) { stmt = &SelectStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/table.go b/sql/table.go index 4678fb09..b85c70b0 100644 --- a/sql/table.go +++ b/sql/table.go @@ -18,7 +18,7 @@ func (p *parser) parseDefineTableStatement() (stmt *DefineTableStatement, err er stmt = &DefineTableStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } @@ -109,7 +109,7 @@ func (p *parser) parseRemoveTableStatement() (stmt *RemoveTableStatement, err er stmt = &RemoveTableStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } diff --git a/sql/token.go b/sql/token.go index 049f5053..74b510d9 100644 --- a/sql/token.go +++ b/sql/token.go @@ -33,19 +33,19 @@ func (p *parser) parseDefineTokenStatement() (stmt *DefineTokenStatement, err er } if is(stmt.Kind, NAMESPACE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } } if is(stmt.Kind, DATABASE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } } if is(stmt.Kind, SCOPE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } if stmt.What, err = p.parseIdent(); err != nil { @@ -105,19 +105,19 @@ func (p *parser) parseRemoveTokenStatement() (stmt *RemoveTokenStatement, err er } if is(stmt.Kind, NAMESPACE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNS); err != nil { return nil, err } } if is(stmt.Kind, DATABASE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } } if is(stmt.Kind, SCOPE) { - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthDB); err != nil { return nil, err } if stmt.What, err = p.parseIdent(); err != nil { diff --git a/sql/update.go b/sql/update.go index da0cc7b8..35ddba52 100644 --- a/sql/update.go +++ b/sql/update.go @@ -18,7 +18,7 @@ func (p *parser) parseUpdateStatement() (stmt *UpdateStatement, err error) { stmt = &UpdateStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/upsert.go b/sql/upsert.go index 4c51e6c7..8c5f2196 100644 --- a/sql/upsert.go +++ b/sql/upsert.go @@ -18,7 +18,7 @@ func (p *parser) parseUpsertStatement() (stmt *UpsertStatement, err error) { stmt = &UpsertStatement{} - if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNO); err != nil { + if stmt.KV, stmt.NS, stmt.DB, err = p.a.get(AuthNO); err != nil { return nil, err } diff --git a/sql/use.go b/sql/use.go index 958d8520..882ef5b7 100644 --- a/sql/use.go +++ b/sql/use.go @@ -43,7 +43,7 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) { return nil, &ParseError{Expected: []string{"namespace name"}, Found: stmt.NS} } - if err = p.o.ns(stmt.NS); err != nil { + if err = p.a.ns(stmt.NS); err != nil { return nil, err } @@ -60,7 +60,7 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) { return nil, &ParseError{Expected: []string{"database name"}, Found: stmt.DB} } - if err = p.o.db(stmt.DB); err != nil { + if err = p.a.db(stmt.DB); err != nil { return nil, err }