github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/dfunctions/version.go (about)

     1  // Copyright 2020 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 dfunctions
    16  
    17  import "github.com/dolthub/go-mysql-server/sql"
    18  
    19  const VersionFuncName = "dolt_version"
    20  
    21  var VersionString = "SET_BY_INIT"
    22  
    23  type Version struct{}
    24  
    25  // NewVersion creates a new Version expression.
    26  func NewVersion(ctx *sql.Context) sql.Expression {
    27  	return &Version{}
    28  }
    29  
    30  // Children implements the Expression interface.
    31  func (*Version) Children() []sql.Expression {
    32  	return nil
    33  }
    34  
    35  // Eval implements the Expression interface.
    36  func (*Version) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
    37  	return VersionString, nil
    38  }
    39  
    40  // IsNullable implements the Expression interface.
    41  func (*Version) IsNullable() bool {
    42  	return false
    43  }
    44  
    45  // Resolved implements the Expression interface.
    46  func (*Version) Resolved() bool {
    47  	return true
    48  }
    49  
    50  // String implements the Stringer interface.
    51  func (*Version) String() string {
    52  	return "DOLT_VERSION"
    53  }
    54  
    55  // Type implements the Expression interface.
    56  func (*Version) Type() sql.Type {
    57  	return sql.Text
    58  }
    59  
    60  // WithChildren implements the Expression interface.
    61  func (v *Version) WithChildren(ctx *sql.Context, children ...sql.Expression) (sql.Expression, error) {
    62  	if len(children) != 0 {
    63  		return nil, sql.ErrInvalidChildrenNumber.New(v, len(children), 0)
    64  	}
    65  	return NewVersion(ctx), nil
    66  }