Remove AND EXPUNGE
clause from DELETE expression
When deleting records, it now removes and expunges document versions based on the table definition `DEFINE TABLE test VERSIONED` or `DEFINE TABLE test UNVERSIONED`, as opposed to the query being run. This prevents non-administrators from removing historic document data.
This commit is contained in:
parent
f089dc4d7f
commit
0402d74708
10 changed files with 1373 additions and 1406 deletions
94
db/db.gen.go
94
db/db.gen.go
|
@ -11,23 +11,23 @@ import (
|
|||
|
||||
const (
|
||||
// ----- content types ----
|
||||
codecSelferCcUTF87188 = 1
|
||||
codecSelferCcRAW7188 = 0
|
||||
codecSelferCcUTF84278 = 1
|
||||
codecSelferCcRAW4278 = 0
|
||||
// ----- value types used ----
|
||||
codecSelferValueTypeArray7188 = 10
|
||||
codecSelferValueTypeMap7188 = 9
|
||||
codecSelferValueTypeString7188 = 6
|
||||
codecSelferValueTypeInt7188 = 2
|
||||
codecSelferValueTypeUint7188 = 3
|
||||
codecSelferValueTypeFloat7188 = 4
|
||||
codecSelferBitsize7188 = uint8(32 << (^uint(0) >> 63))
|
||||
codecSelferValueTypeArray4278 = 10
|
||||
codecSelferValueTypeMap4278 = 9
|
||||
codecSelferValueTypeString4278 = 6
|
||||
codecSelferValueTypeInt4278 = 2
|
||||
codecSelferValueTypeUint4278 = 3
|
||||
codecSelferValueTypeFloat4278 = 4
|
||||
codecSelferBitsize4278 = uint8(32 << (^uint(0) >> 63))
|
||||
)
|
||||
|
||||
var (
|
||||
errCodecSelferOnlyMapOrArrayEncodeToStruct7188 = errors.New(`only encoded map or array can be decoded into a struct`)
|
||||
errCodecSelferOnlyMapOrArrayEncodeToStruct4278 = errors.New(`only encoded map or array can be decoded into a struct`)
|
||||
)
|
||||
|
||||
type codecSelfer7188 struct{}
|
||||
type codecSelfer4278 struct{}
|
||||
|
||||
func init() {
|
||||
if codec1978.GenVersion != 8 {
|
||||
|
@ -39,7 +39,7 @@ func init() {
|
|||
}
|
||||
|
||||
func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperEncoder(e)
|
||||
_, _, _ = h, z, r
|
||||
if x == nil {
|
||||
|
@ -77,19 +77,19 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
if yyq2[0] {
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Time))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Time))
|
||||
}
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, "")
|
||||
r.EncodeString(codecSelferCcUTF84278, "")
|
||||
}
|
||||
} else {
|
||||
if yyq2[0] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `time`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `time`)
|
||||
r.WriteMapElemValue()
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Time))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Time))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,19 +98,19 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
if yyq2[1] {
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Status))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Status))
|
||||
}
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, "")
|
||||
r.EncodeString(codecSelferCcUTF84278, "")
|
||||
}
|
||||
} else {
|
||||
if yyq2[1] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `status`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `status`)
|
||||
r.WriteMapElemValue()
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Status))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Status))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,19 +119,19 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
if yyq2[2] {
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Detail))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Detail))
|
||||
}
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, "")
|
||||
r.EncodeString(codecSelferCcUTF84278, "")
|
||||
}
|
||||
} else {
|
||||
if yyq2[2] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `detail`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `detail`)
|
||||
r.WriteMapElemValue()
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Detail))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Detail))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
} else {
|
||||
if yyq2[3] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `result`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `result`)
|
||||
r.WriteMapElemValue()
|
||||
if x.Result == nil {
|
||||
r.EncodeNil()
|
||||
|
@ -174,7 +174,7 @@ func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
}
|
||||
|
||||
func (x *Response) CodecDecodeSelf(d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
if false {
|
||||
|
@ -182,14 +182,14 @@ func (x *Response) CodecDecodeSelf(d *codec1978.Decoder) {
|
|||
z.DecExtension(x, yyxt1)
|
||||
} else {
|
||||
yyct2 := r.ContainerType()
|
||||
if yyct2 == codecSelferValueTypeMap7188 {
|
||||
if yyct2 == codecSelferValueTypeMap4278 {
|
||||
yyl2 := r.ReadMapStart()
|
||||
if yyl2 == 0 {
|
||||
r.ReadMapEnd()
|
||||
} else {
|
||||
x.codecDecodeSelfFromMap(yyl2, d)
|
||||
}
|
||||
} else if yyct2 == codecSelferValueTypeArray7188 {
|
||||
} else if yyct2 == codecSelferValueTypeArray4278 {
|
||||
yyl2 := r.ReadArrayStart()
|
||||
if yyl2 == 0 {
|
||||
r.ReadArrayEnd()
|
||||
|
@ -197,13 +197,13 @@ func (x *Response) CodecDecodeSelf(d *codec1978.Decoder) {
|
|||
x.codecDecodeSelfFromArray(yyl2, d)
|
||||
}
|
||||
} else {
|
||||
panic(errCodecSelferOnlyMapOrArrayEncodeToStruct7188)
|
||||
panic(errCodecSelferOnlyMapOrArrayEncodeToStruct4278)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Response) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
var yyhl3 bool = l >= 0
|
||||
|
@ -256,7 +256,7 @@ func (x *Response) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
|
|||
}
|
||||
|
||||
func (x *Response) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
var yyj9 int
|
||||
|
@ -346,7 +346,7 @@ func (x *Response) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
|
|||
}
|
||||
|
||||
func (x *Dispatch) CodecEncodeSelf(e *codec1978.Encoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperEncoder(e)
|
||||
_, _, _ = h, z, r
|
||||
if x == nil {
|
||||
|
@ -383,19 +383,19 @@ func (x *Dispatch) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
if yyq2[0] {
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Query))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Query))
|
||||
}
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, "")
|
||||
r.EncodeString(codecSelferCcUTF84278, "")
|
||||
}
|
||||
} else {
|
||||
if yyq2[0] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `query`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `query`)
|
||||
r.WriteMapElemValue()
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Query))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Query))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,19 +404,19 @@ func (x *Dispatch) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
if yyq2[1] {
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Action))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Action))
|
||||
}
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, "")
|
||||
r.EncodeString(codecSelferCcUTF84278, "")
|
||||
}
|
||||
} else {
|
||||
if yyq2[1] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `action`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `action`)
|
||||
r.WriteMapElemValue()
|
||||
if false {
|
||||
} else {
|
||||
r.EncodeString(codecSelferCcUTF87188, string(x.Action))
|
||||
r.EncodeString(codecSelferCcUTF84278, string(x.Action))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ func (x *Dispatch) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
} else {
|
||||
if yyq2[2] {
|
||||
r.WriteMapElemKey()
|
||||
r.EncodeString(codecSelferCcUTF87188, `result`)
|
||||
r.EncodeString(codecSelferCcUTF84278, `result`)
|
||||
r.WriteMapElemValue()
|
||||
if x.Result == nil {
|
||||
r.EncodeNil()
|
||||
|
@ -459,7 +459,7 @@ func (x *Dispatch) CodecEncodeSelf(e *codec1978.Encoder) {
|
|||
}
|
||||
|
||||
func (x *Dispatch) CodecDecodeSelf(d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
if false {
|
||||
|
@ -467,14 +467,14 @@ func (x *Dispatch) CodecDecodeSelf(d *codec1978.Decoder) {
|
|||
z.DecExtension(x, yyxt1)
|
||||
} else {
|
||||
yyct2 := r.ContainerType()
|
||||
if yyct2 == codecSelferValueTypeMap7188 {
|
||||
if yyct2 == codecSelferValueTypeMap4278 {
|
||||
yyl2 := r.ReadMapStart()
|
||||
if yyl2 == 0 {
|
||||
r.ReadMapEnd()
|
||||
} else {
|
||||
x.codecDecodeSelfFromMap(yyl2, d)
|
||||
}
|
||||
} else if yyct2 == codecSelferValueTypeArray7188 {
|
||||
} else if yyct2 == codecSelferValueTypeArray4278 {
|
||||
yyl2 := r.ReadArrayStart()
|
||||
if yyl2 == 0 {
|
||||
r.ReadArrayEnd()
|
||||
|
@ -482,13 +482,13 @@ func (x *Dispatch) CodecDecodeSelf(d *codec1978.Decoder) {
|
|||
x.codecDecodeSelfFromArray(yyl2, d)
|
||||
}
|
||||
} else {
|
||||
panic(errCodecSelferOnlyMapOrArrayEncodeToStruct7188)
|
||||
panic(errCodecSelferOnlyMapOrArrayEncodeToStruct4278)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Dispatch) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
var yyhl3 bool = l >= 0
|
||||
|
@ -535,7 +535,7 @@ func (x *Dispatch) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
|
|||
}
|
||||
|
||||
func (x *Dispatch) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
|
||||
var h codecSelfer7188
|
||||
var h codecSelfer4278
|
||||
z, r := codec1978.GenHelperDecoder(d)
|
||||
_, _, _ = h, z, r
|
||||
var yyj8 int
|
||||
|
|
10
db/delete.go
10
db/delete.go
|
@ -149,14 +149,8 @@ func (d *document) runDelete(ctx context.Context, stm *sql.DeleteStatement) (int
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if stm.Hard {
|
||||
if err = d.eraseThing(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err = d.purgeThing(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = d.purgeThing(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = d.table(ctx, met); err != nil {
|
||||
|
|
|
@ -415,26 +415,6 @@ func (d *document) purgeThing(ctx context.Context) (err error) {
|
|||
|
||||
}
|
||||
|
||||
func (d *document) eraseThing(ctx context.Context) (err error) {
|
||||
|
||||
defer d.ulock(ctx)
|
||||
|
||||
// Check that the table should
|
||||
// drop data being written.
|
||||
|
||||
if ok, err := d.shouldDrop(ctx); ok {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete the item entirely from
|
||||
// storage, so no versions exist.
|
||||
|
||||
_, err = d.i.e.dbo.Clr(ctx, d.key.Encode())
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (d *document) storeIndex(ctx context.Context) (err error) {
|
||||
|
||||
// Check if this query has been run
|
||||
|
|
|
@ -161,7 +161,6 @@ func (d *document) tableDelete(ctx context.Context, tng *sql.Thing, exp sql.Fiel
|
|||
NS: d.key.NS,
|
||||
DB: d.key.DB,
|
||||
What: sql.Exprs{tng},
|
||||
Hard: false,
|
||||
Parallel: 1,
|
||||
}
|
||||
|
||||
|
|
2632
sql/ast.gen.go
2632
sql/ast.gen.go
File diff suppressed because it is too large
Load diff
|
@ -210,7 +210,6 @@ type DeleteStatement struct {
|
|||
KV string
|
||||
NS string
|
||||
DB string
|
||||
Hard bool
|
||||
What Exprs
|
||||
Cond Expr
|
||||
Echo Token
|
||||
|
|
|
@ -1135,7 +1135,6 @@ func (this *DeleteStatement) MarshalCORK(w *cork.Writer) (err error) {
|
|||
w.EncodeString(this.KV)
|
||||
w.EncodeString(this.NS)
|
||||
w.EncodeString(this.DB)
|
||||
w.EncodeBool(this.Hard)
|
||||
w.EncodeAny(this.What)
|
||||
w.EncodeAny(this.Cond)
|
||||
w.EncodeAny(this.Echo)
|
||||
|
@ -1147,7 +1146,6 @@ func (this *DeleteStatement) UnmarshalCORK(r *cork.Reader) (err error) {
|
|||
r.DecodeString(&this.KV)
|
||||
r.DecodeString(&this.NS)
|
||||
r.DecodeString(&this.DB)
|
||||
r.DecodeBool(&this.Hard)
|
||||
r.DecodeAny(&this.What)
|
||||
r.DecodeAny(&this.Cond)
|
||||
r.DecodeAny(&this.Echo)
|
||||
|
|
|
@ -22,13 +22,6 @@ func (p *parser) parseDeleteStatement() (stmt *DeleteStatement, err error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if _, _, exi := p.mightBe(AND); exi {
|
||||
if _, _, err = p.shouldBe(EXPUNGE); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stmt.Hard = true
|
||||
}
|
||||
|
||||
_, _, _ = p.mightBe(FROM)
|
||||
|
||||
if stmt.What, err = p.parseWhat(); err != nil {
|
||||
|
|
|
@ -1592,15 +1592,6 @@ func Test_Parse_Queries_Delete(t *testing.T) {
|
|||
Echo: NONE,
|
||||
}}},
|
||||
},
|
||||
{
|
||||
sql: `DELETE AND EXPUNGE person`,
|
||||
res: &Query{Statements: []Statement{&DeleteStatement{
|
||||
KV: "*", NS: "*", DB: "*",
|
||||
What: []Expr{&Ident{"person"}},
|
||||
Hard: true,
|
||||
Echo: NONE,
|
||||
}}},
|
||||
},
|
||||
{
|
||||
sql: `DELETE person RETURN`,
|
||||
err: "Found `` but expected `NONE, INFO, BOTH, DIFF, BEFORE, AFTER`",
|
||||
|
|
|
@ -259,8 +259,7 @@ func (this UpdateStatement) String() string {
|
|||
}
|
||||
|
||||
func (this DeleteStatement) String() string {
|
||||
return print("DELETE %v%v%v%v%v",
|
||||
maybe(this.Hard, "AND EXPUNGE "),
|
||||
return print("DELETE %v%v%v%v",
|
||||
this.What,
|
||||
maybe(this.Cond != nil, print(" WHERE %v", this.Cond)),
|
||||
maybe(this.Echo != NONE, print(" RETURN %v", this.Echo)),
|
||||
|
|
Loading…
Reference in a new issue