github.com/matrixorigin/matrixone@v0.7.0/pkg/util/internalExecutor/internal_executor.go (about)

     1  // Copyright 2022 Matrix Origin
     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 internalExecutor
    16  
    17  import "context"
    18  
    19  /*
    20  Define InternalExecutor interface here to avoid cycle dependency
    21  
    22  The Impl of InternalExecutor is in frontend package
    23  */
    24  
    25  type SessionOverrideOptions struct {
    26  	Database   *string
    27  	Username   *string
    28  	IsInternal *bool
    29  }
    30  
    31  type OptsBuilder struct {
    32  	opts *SessionOverrideOptions
    33  }
    34  
    35  func NewOptsBuilder() *OptsBuilder {
    36  	return &OptsBuilder{
    37  		opts: new(SessionOverrideOptions),
    38  	}
    39  }
    40  
    41  func (s *OptsBuilder) Database(db string) *OptsBuilder {
    42  	s.opts.Database = &db
    43  	return s
    44  }
    45  
    46  func (s *OptsBuilder) Username(name string) *OptsBuilder {
    47  	s.opts.Username = &name
    48  	return s
    49  }
    50  
    51  func (s *OptsBuilder) Internal(b bool) *OptsBuilder {
    52  	s.opts.IsInternal = &b
    53  	return s
    54  }
    55  
    56  func (s *OptsBuilder) Finish() SessionOverrideOptions {
    57  	return *s.opts
    58  }
    59  
    60  type InternalExecResult interface {
    61  	Error() error
    62  	ColumnCount() uint64
    63  	Column(context.Context, uint64) (string, uint8, bool, error) // type refer: pkg/defines/type.go & func convertEngineTypeToMysqlType
    64  	RowCount() uint64
    65  	Row(context.Context, uint64) ([]interface{}, error)
    66  	Value(context.Context, uint64, uint64) (interface{}, error)
    67  	ValueByName(context.Context, uint64, string) (interface{}, error)
    68  	StringValueByName(context.Context, uint64, string) (string, error)
    69  	Float64ValueByName(context.Context, uint64, string) (float64, error)
    70  }
    71  
    72  type InternalExecutor interface {
    73  	// exec sql without returning results set
    74  	Exec(context.Context, string, SessionOverrideOptions) error
    75  	// exec sql and return results set
    76  	Query(context.Context, string, SessionOverrideOptions) InternalExecResult
    77  	// override session for the executor scope
    78  	ApplySessionOverride(SessionOverrideOptions)
    79  }