perf(scan): 使用缓存减少对象扫描

抽取函数,优化变量命名
支持了传入数组类型
This commit is contained in:
2025-11-27 18:24:36 +08:00
parent 581b0b60eb
commit b9413d6c40
7 changed files with 215 additions and 197 deletions

View File

@@ -4,9 +4,9 @@ import (
"database/sql"
"encoding/json"
"fmt"
//_ "github.com/taosdata/driver-go/v3/taosWS"
"testing"
"time"
//_ "github.com/taosdata/driver-go/v3/taosWS"
)
type TaosTAG struct {
@@ -92,9 +92,9 @@ func (u *User) SuperTableName() string {
func TestSimpleInsert(t *testing.T) {
tdMapper := NewMapper()
data := []User{
{Name: "张三", Age: 18},
{Name: "李四", Age: 20},
data := []any{
&User{Name: "张三", Age: 18},
User{Name: "李四", Age: 20},
}
insertSql, err := tdMapper.ToInsertSQL(data)
@@ -109,6 +109,10 @@ type SuperDevTAG struct {
DevType string `db:"dev_type" taos:"tag"`
}
func (s *SuperDevTAG) SuperTableName() string {
return "SuperDevTAG"
}
type SuperDev struct {
SuperDevTAG
Ts time.Time `db:"ts"` // 时间戳
@@ -133,7 +137,7 @@ func TestSuperDevInsert(t *testing.T) {
SuperDevTAG: SuperDevTAG{DevId: "SN001", DevType: "模拟设备"},
Ts: time.Now().Add(time.Second), AppSn: "a0002", Ct: 2.0,
},
SuperDev{
&SuperDev{
SuperDevTAG: SuperDevTAG{DevId: "SN002", DevType: "模拟设备"},
Ts: time.Now(), AppSn: "a0003", Ct: 3.0,
},