github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/releaser.go (about) 1 // Copyright 2020-2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import ( 18 "reflect" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 ) 22 23 type Releaser struct { 24 Child sql.Node 25 Release func() 26 } 27 28 var _ sql.Node = (*Releaser)(nil) 29 var _ sql.CollationCoercible = (*Releaser)(nil) 30 31 func (r *Releaser) Resolved() bool { 32 return r.Child.Resolved() 33 } 34 35 func (r *Releaser) IsReadOnly() bool { 36 return r.Child.IsReadOnly() 37 } 38 39 func (r *Releaser) Children() []sql.Node { 40 return []sql.Node{r.Child} 41 } 42 43 func (r *Releaser) Schema() sql.Schema { 44 return r.Child.Schema() 45 } 46 47 func (r *Releaser) WithChildren(children ...sql.Node) (sql.Node, error) { 48 if len(children) != 1 { 49 return nil, sql.ErrInvalidChildrenNumber.New(r, len(children), 1) 50 } 51 return &Releaser{children[0], r.Release}, nil 52 } 53 54 // CheckPrivileges implements the interface sql.Node. 55 func (r *Releaser) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 56 return r.Child.CheckPrivileges(ctx, opChecker) 57 } 58 59 // CollationCoercibility implements the interface sql.CollationCoercible. 60 func (r *Releaser) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 61 return sql.GetCoercibility(ctx, r.Child) 62 } 63 64 func (r *Releaser) String() string { 65 return r.Child.String() 66 } 67 68 func (r *Releaser) Equal(n sql.Node) bool { 69 if r2, ok := n.(*Releaser); ok { 70 return reflect.DeepEqual(r.Child, r2.Child) 71 } 72 return false 73 }