flatstorage

package module
v0.0.0-...-f7fac8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

README

FlatStorage

Go Report Card GoDoc

FlatStorage is a simple, non-relational and non-structural database which writes/reads objects to/from disk.

Documentation

Index

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

func (*FlatStorage) Write

func (fs *FlatStorage) Write(collection string, resource string, object interface{}) error

Write writes a single object into a collection from an interface instance

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL