package simpleorm import ( "sync" ) type OrmCache struct { mu sync.RWMutex data map[string]*Table } func NewOrmCache(tables []*Table) *OrmCache { cache := &OrmCache{ data: make(map[string]*Table), } for _, table := range tables { cache.add(table) } return cache } func (o *OrmCache) add(table *Table) { o.mu.Lock() defer o.mu.Unlock() o.data[table.Type.Name()] = table } func (o *OrmCache) Get(typeName string) (*Table, bool) { o.mu.RLock() defer o.mu.RUnlock() table, ok := o.data[typeName] return table, ok } func (o *OrmCache) GetAll() []*Table { o.mu.RLock() defer o.mu.RUnlock() var result []*Table for _, v := range o.data { result = append(result, v) } return result }