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