Initial source commit

This commit is contained in:
2026-05-03 19:23:27 +02:00
parent b27b9add45
commit 106e5c3dc5
10 changed files with 511 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
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.TypeName] = table
}
func (o *OrmCache) Get(tableName string) (*Table, bool) {
o.mu.RLock()
defer o.mu.RUnlock()
table, ok := o.data[tableName]
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
}