-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
179 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package GoMybatis | ||
|
||
//表达式类型(基本类型)转换函数 | ||
type ExpressionTypeConvert interface { | ||
Convert(arg SqlArg) interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package GoMybatis | ||
|
||
import ( | ||
"reflect" | ||
"time" | ||
) | ||
|
||
const Adapter_DateType = `time.Time` | ||
|
||
//表达式类型转换器 | ||
type GoMybatisExpressionTypeConvert struct { | ||
} | ||
|
||
//表达式类型转换器 | ||
func (this GoMybatisExpressionTypeConvert) Convert(arg SqlArg) interface{} { | ||
if arg.Type.Kind() == reflect.Struct && arg.Type.String() == Adapter_DateType { | ||
return arg.Value.(time.Time).Nanosecond() | ||
} | ||
return arg.Value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package GoMybatis | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_ExpressionTypeConvert(t *testing.T) { | ||
var a = true | ||
var convertResult = GoMybatisExpressionTypeConvert{}.Convert(SqlArg{ | ||
Value: a, | ||
Type: reflect.TypeOf(a), | ||
}) | ||
if convertResult != true { | ||
t.Fatal(`Test_ExpressionTypeConvert fail`) | ||
} | ||
fmt.Println(convertResult) | ||
convertResult = GoMybatisExpressionTypeConvert{}.Convert(SqlArg{ | ||
Value: 1, | ||
Type: reflect.TypeOf(1), | ||
}) | ||
if convertResult == nil { | ||
t.Fatal(`Test_ExpressionTypeConvert fail`) | ||
} | ||
fmt.Println(convertResult) | ||
convertResult = GoMybatisExpressionTypeConvert{}.Convert(SqlArg{ | ||
Value: time.Now(), | ||
Type: reflect.TypeOf(time.Now()), | ||
}) | ||
if convertResult == nil { | ||
t.Fatal(`Test_ExpressionTypeConvert fail`) | ||
} | ||
fmt.Println(convertResult) | ||
convertResult = GoMybatisExpressionTypeConvert{}.Convert(SqlArg{ | ||
Value: "string", | ||
Type: reflect.TypeOf("string"), | ||
}) | ||
if convertResult == nil { | ||
t.Fatal(`Test_ExpressionTypeConvert fail`) | ||
} | ||
fmt.Println(convertResult) | ||
} | ||
|
||
func BenchmarkGoMybatisExpressionTypeConvert_Convert(b *testing.B) { | ||
b.StopTimer() | ||
var convertType = reflect.TypeOf(1) | ||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
var convertResult = GoMybatisExpressionTypeConvert{}.Convert(SqlArg{ | ||
Value: 1, | ||
Type: convertType, | ||
}) | ||
if convertResult == nil { | ||
b.Fatal("convert fail!") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.