feat: 完成批量插入的SQL生成功能

This commit is contained in:
2024-09-14 13:12:52 +08:00
parent adde90af93
commit 41c2b5d211
10 changed files with 790 additions and 1 deletions

40
syncmap/map.go Normal file
View File

@@ -0,0 +1,40 @@
package syncmap
import (
"sync"
)
type Map[T any, V any] struct {
sMap sync.Map
}
func (m *Map[T, V]) Store(key T, value V) {
m.sMap.Store(key, value)
}
func (m *Map[T, V]) Load(key T) (value V, ok bool) {
v, ok := m.sMap.Load(key)
if ok {
return v.(V), ok
}
return
}
func (m *Map[T, V]) Delete(key T) {
m.sMap.Delete(key)
}
func (m *Map[T, V]) Range(f func(T, V) bool) {
m.sMap.Range(func(key, value any) bool {
return f(key.(T), value.(V))
})
}
func (m *Map[T, V]) LoadOrStore(key T, value V) (actual V, loaded bool) {
_actual, loaded := m.sMap.LoadOrStore(key, value)
if loaded {
actual = _actual.(V)
}
return
}

14
syncmap/map_test.go Normal file
View File

@@ -0,0 +1,14 @@
package syncmap
import (
"log"
"testing"
)
func TestAA(t *testing.T) {
var m Map[string, int]
m.Store("a", 1234)
value, _ := m.Load("a")
log.Println("value:", value)
}