Documentation ¶
Index ¶
- type FlatStorage
- func (fs *FlatStorage) CollectionExists(collection string) bool
- func (fs *FlatStorage) Delete(collection string, resource string) error
- func (fs *FlatStorage) DeleteAll(collection string) error
- func (fs *FlatStorage) Exists(collection string, resource string) bool
- func (fs *FlatStorage) LockCollection(collection string)
- func (fs *FlatStorage) Read(collection string, resource string, out interface{}) error
- func (fs *FlatStorage) ReadAll(collection string, resourceType interface{}) ([]interface{}, error)
- func (fs *FlatStorage) UnlockCollection(collection string)
- func (fs *FlatStorage) Write(collection string, resource string, object interface{}) error
- type GenericRepository
- func (r *GenericRepository[T]) Collection() string
- func (r *GenericRepository[T]) Count() int
- func (r *GenericRepository[T]) Delete(resourceId string) error
- func (r *GenericRepository[T]) DeleteAll() error
- func (r *GenericRepository[T]) Exists(resourceId string) bool
- func (r *GenericRepository[T]) Get(resourceId string) (val *T, err error)
- func (r *GenericRepository[T]) GetAll() (val []T, err error)
- func (r *GenericRepository[T]) Type() reflect.Type
- func (r *GenericRepository[T]) Write(resourceId string, val T) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FlatStorage ¶
type FlatStorage struct {
// contains filtered or unexported fields
}
FlatStorage is the interface to manage a flatstorage
Example (Delete) ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } fs.Delete("test", "test") if err != nil { panic(err) }
Output:
Example (Deleteall) ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } fs.DeleteAll("test") if err != nil { panic(err) }
Output:
Example (Read) ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } type Test struct { Name string } // File: /var/db/test/test.json // // { // "name": "Hello World" // } // test := Test{} fs.Read("test", "test", &test) if err != nil { panic(err) } print(test.Name)
Output: Hello World
Example (Readall) ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } type Test struct { Name string } // File: /var/db/test/test.json // // { // "name": "Hello World" // } // test := Test{} resources, err := fs.ReadAll("test", &test) if err != nil { panic(err) } print(resources[0])
Output: { Name: "Hello World" }
Example (Write) ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } type Test struct { Name string } test := Test{ Name: "Hello World", } fs.Write("test", "test", &test) if err != nil { panic(err) }
Output:
func NewFlatStorage ¶
func NewFlatStorage(path string) (*FlatStorage, error)
NewFlatStorage opens a flatstorage at specified path
Example ¶
fs, err := NewFlatStorage("/tmp/db") if err != nil { panic(err) } print(fs.CollectionExists("test"))
Output: false
func (*FlatStorage) CollectionExists ¶
func (fs *FlatStorage) CollectionExists(collection string) bool
CollectionExists checks if a collection exists
func (*FlatStorage) Delete ¶
func (fs *FlatStorage) Delete(collection string, resource string) error
Delete removes a single resource from a collection
func (*FlatStorage) DeleteAll ¶
func (fs *FlatStorage) DeleteAll(collection string) error
DeleteAll removes an entire collection from the filesystem
func (*FlatStorage) Exists ¶
func (fs *FlatStorage) Exists(collection string, resource string) bool
Exists checks if a resource is present in a collection
func (*FlatStorage) LockCollection ¶
func (fs *FlatStorage) LockCollection(collection string)
LockCollection locks down a specific collection to thread-safe behaviour
func (*FlatStorage) Read ¶
func (fs *FlatStorage) Read(collection string, resource string, out interface{}) error
Read reads a single resource from a collection into an interface instance
func (*FlatStorage) ReadAll ¶
func (fs *FlatStorage) ReadAll(collection string, resourceType interface{}) ([]interface{}, error)
ReadAll reads all resources from a collection into an interface array of resourceType
func (*FlatStorage) UnlockCollection ¶
func (fs *FlatStorage) UnlockCollection(collection string)
UnlockCollection unlocks a locked collection to be accessible by threads again
type GenericRepository ¶
type GenericRepository[T any] struct { *FlatStorage // contains filtered or unexported fields }
func NamedRepository ¶
func NamedRepository[T any](fs *FlatStorage, collection string) *GenericRepository[T]
func Repository ¶
func Repository[T any](fs *FlatStorage) *GenericRepository[T]
func (*GenericRepository[T]) Collection ¶
func (r *GenericRepository[T]) Collection() string
func (*GenericRepository[T]) Count ¶
func (r *GenericRepository[T]) Count() int
func (*GenericRepository[T]) Delete ¶
func (r *GenericRepository[T]) Delete(resourceId string) error
func (*GenericRepository[T]) DeleteAll ¶
func (r *GenericRepository[T]) DeleteAll() error
func (*GenericRepository[T]) Exists ¶
func (r *GenericRepository[T]) Exists(resourceId string) bool
func (*GenericRepository[T]) Get ¶
func (r *GenericRepository[T]) Get(resourceId string) (val *T, err error)
func (*GenericRepository[T]) GetAll ¶
func (r *GenericRepository[T]) GetAll() (val []T, err error)
func (*GenericRepository[T]) Type ¶
func (r *GenericRepository[T]) Type() reflect.Type
func (*GenericRepository[T]) Write ¶
func (r *GenericRepository[T]) Write(resourceId string, val T) error