Add sql functions for generating GUIDs
This commit is contained in:
parent
7fbc9feff9
commit
93d154a099
4 changed files with 37 additions and 0 deletions
|
@ -251,8 +251,10 @@ var funcs = map[string]map[int]interface{}{
|
|||
|
||||
// Random implementation
|
||||
"rand": {0: nil},
|
||||
"guid": {0: nil},
|
||||
"uuid": {0: nil},
|
||||
"rand.bool": {0: nil},
|
||||
"rand.guid": {0: nil},
|
||||
"rand.uuid": {0: nil},
|
||||
"rand.enum": {-1: nil},
|
||||
"rand.time": {0: nil, 2: nil},
|
||||
|
|
27
util/fake/guid.go
Normal file
27
util/fake/guid.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright © 2016 Abcum Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
"github.com/abcum/surreal/util/guid"
|
||||
)
|
||||
|
||||
func Guid() string {
|
||||
return guid.New().String()
|
||||
}
|
||||
|
||||
func (f *Faker) Guid() string {
|
||||
return guid.New().String()
|
||||
}
|
|
@ -252,10 +252,14 @@ func Run(ctx context.Context, name string, args ...interface{}) (interface{}, er
|
|||
// Rand implementation
|
||||
case "rand":
|
||||
return rand(ctx, args...)
|
||||
case "guid":
|
||||
return randGuid(ctx, args...)
|
||||
case "uuid":
|
||||
return randUuid(ctx, args...)
|
||||
case "rand.bool":
|
||||
return randBool(ctx, args...)
|
||||
case "rand.guid":
|
||||
return randGuid(ctx, args...)
|
||||
case "rand.uuid":
|
||||
return randUuid(ctx, args...)
|
||||
case "rand.enum":
|
||||
|
|
|
@ -29,6 +29,10 @@ func randBool(ctx context.Context, args ...interface{}) (bool, error) {
|
|||
return fake.Bool(), nil
|
||||
}
|
||||
|
||||
func randGuid(ctx context.Context, args ...interface{}) (string, error) {
|
||||
return fake.Guid(), nil
|
||||
}
|
||||
|
||||
func randUuid(ctx context.Context, args ...interface{}) (string, error) {
|
||||
return fake.Uuid(), nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue