Improve SQL DEFINE SCOPE statement

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-16 22:47:43 +00:00
parent cf79487b81
commit ee6653c289
3 changed files with 46 additions and 13 deletions

View file

@ -256,12 +256,14 @@ type RemoveTokenStatement struct {
// DefineScopeStatement represents an SQL DEFINE SCOPE statement. // DefineScopeStatement represents an SQL DEFINE SCOPE statement.
type DefineScopeStatement struct { type DefineScopeStatement struct {
KV string `cork:"-" codec:"-"` KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"` NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"` DB string `cork:"-" codec:"-"`
Name string `cork:"name" codec:"name"` Name string `cork:"name" codec:"name"`
Time time.Duration `cork:"time" codec:"time"` Time time.Duration `cork:"time" codec:"time"`
Opts interface{} `cork:"opts" codec:"opts"` Signup Expr `cork:"signup" codec:"signup"`
Signin Expr `cork:"signin" codec:"signin"`
Policy map[string]interface{} `cork:"policy" codec:"policy"`
} }
// RemoveScopeStatement represents an SQL REMOVE SCOPE statement. // RemoveScopeStatement represents an SQL REMOVE SCOPE statement.

View file

@ -1199,7 +1199,9 @@ func (this *DefineScopeStatement) MarshalCORK() (dst []byte, err error) {
e := cork.NewEncoder(b) e := cork.NewEncoder(b)
e.Encode(this.Name) e.Encode(this.Name)
e.Encode(this.Time) e.Encode(this.Time)
e.Encode(this.Opts) e.Encode(this.Signup)
e.Encode(this.Signin)
e.Encode(this.Policy)
return b.Bytes(), nil return b.Bytes(), nil
} }
@ -1208,7 +1210,9 @@ func (this *DefineScopeStatement) UnmarshalCORK(src []byte) (err error) {
d := cork.NewDecoder(b) d := cork.NewDecoder(b)
d.Decode(&this.Name) d.Decode(&this.Name)
d.Decode(&this.Time) d.Decode(&this.Time)
d.Decode(&this.Opts) d.Decode(&this.Signup)
d.Decode(&this.Signin)
d.Decode(&this.Policy)
return return
} }

View file

@ -26,12 +26,39 @@ func (p *parser) parseDefineScopeStatement() (stmt *DefineScopeStatement, err er
return nil, err return nil, err
} }
if _, _, err = p.shouldBe(SESSION); err != nil { for {
return nil, err
} tok, _, exi := p.mightBe(SESSION, POLICY, SIGNUP, SIGNIN)
if !exi {
break
}
if p.is(tok, SESSION) {
if stmt.Time, err = p.parseDuration(); err != nil {
return nil, err
}
}
if p.is(tok, POLICY) {
if stmt.Policy, err = p.parseObject(); err != nil {
return nil, err
}
}
if p.is(tok, SIGNUP) {
_, _, _ = p.mightBe(AS)
if stmt.Signup, err = p.parseExpr(); err != nil {
return nil, err
}
}
if p.is(tok, SIGNIN) {
_, _, _ = p.mightBe(AS)
if stmt.Signin, err = p.parseExpr(); err != nil {
return nil, err
}
}
if stmt.Time, err = p.parseDuration(); err != nil {
return nil, err
} }
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {