-
Notifications
You must be signed in to change notification settings - Fork 12
/
sql.tmpl.go
36 lines (29 loc) · 981 Bytes
/
sql.tmpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "strings"
// SqlJsonType: NullJson type name
// ValueType: value type name
// NilValue: nil value of map type
type SqlRender struct {
SqlJsonType string // NullJson type name
valueImport string // import path of the atomic.Value's value.
ValueType string // value type name
NilValue string // nil value of map type
ProtoJson bool // generate codec of proto by protojson, instead of json
CanAlias bool // use type {{.SqlJsonType}} = {{.ValueType}} instead of type {{.SqlJsonType}} {{.ValueType}}
}
func (r *SqlRender) ResetCanAlias() {
if strings.HasPrefix(strings.TrimSpace(r.ValueType), "map") ||
strings.HasPrefix(strings.TrimSpace(r.ValueType), "[") {
r.CanAlias = false
return
}
if r.valueImport != "" {
r.CanAlias = false
return
}
r.CanAlias = true
return
}