github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/noarg_funcs.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 function 16 17 import ( 18 "strings" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 ) 22 23 // NoArgFunc is a helper type to reduce boilerplate in functions that take no arguments. Implements most of 24 // sql.FunctionExpression. 25 type NoArgFunc struct { 26 Name string 27 SQLType sql.Type 28 } 29 30 // FunctionName implements sql.FunctionExpression 31 func (fn NoArgFunc) FunctionName() string { 32 return strings.ToLower(fn.Name) 33 } 34 35 // Type implements the Expression interface. 36 func (fn NoArgFunc) Type() sql.Type { return fn.SQLType } 37 38 func (fn NoArgFunc) String() string { return fn.FunctionName() + "()" } 39 40 // IsNullable implements the Expression interface. 41 func (fn NoArgFunc) IsNullable() bool { return false } 42 43 // Resolved implements the Expression interface. 44 func (fn NoArgFunc) Resolved() bool { return true } 45 46 // Children implements the Expression interface. 47 func (fn NoArgFunc) Children() []sql.Expression { return nil } 48 49 // WithChildren implements the Expression interface. 50 func NoArgFuncWithChildren(fn sql.Expression, children []sql.Expression) (sql.Expression, error) { 51 if len(children) != 0 { 52 return nil, sql.ErrInvalidChildrenNumber.New(fn, len(children), 0) 53 } 54 return fn, nil 55 }