1 Star 1 Fork 0

bigbase / pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tables.go 636 Bytes
一键复制 编辑 原始数据 按行查看 历史
Anatolii Mihailenco 提交于 2016-09-14 11:38 . Add CreateTable function.
package orm
import (
"fmt"
"reflect"
"sync"
)
var Tables = newTables()
type tables struct {
inFlight map[reflect.Type]*Table
tables map[reflect.Type]*Table
mu sync.RWMutex
}
func newTables() *tables {
return &tables{
inFlight: make(map[reflect.Type]*Table),
tables: make(map[reflect.Type]*Table),
}
}
func (t *tables) Get(typ reflect.Type) *Table {
if typ.Kind() != reflect.Struct {
panic(fmt.Errorf("got %s, wanted %s", typ.Kind(), reflect.Struct))
}
t.mu.RLock()
table, ok := t.tables[typ]
t.mu.RUnlock()
if ok {
return table
}
t.mu.Lock()
table = newTable(typ)
t.mu.Unlock()
return table
}
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v6.2.2

搜索帮助