record

package
Version: v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: GPL-3.0 Imports: 12 Imported by: 12

Documentation

Index

Constants

View Source
const (
	AUTO    = dsd.AUTO
	STRING  = dsd.STRING  // S
	BYTES   = dsd.BYTES   // X
	JSON    = dsd.JSON    // J
	BSON    = dsd.BSON    // B
	GenCode = dsd.GenCode // G
)

Reimport DSD storage types

Variables

This section is empty.

Functions

func ParseKey

func ParseKey(key string) (dbName, dbKey string)

ParseKey splits a key into it's database name and key parts.

func Unwrap

func Unwrap(wrapped, new Record) error

Unwrap unwraps data into a record.

Types

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base provides a quick way to comply with the Model interface.

func (*Base) CreateMeta

func (b *Base) CreateMeta()

CreateMeta sets a default metadata object for this record.

func (*Base) DatabaseKey

func (b *Base) DatabaseKey() string

DatabaseKey returns the database key of the database record. As the key must be set before any usage and can only be set once, this function may be used without locking the record.

func (*Base) DatabaseName

func (b *Base) DatabaseName() string

DatabaseName returns the name of the database. As the key must be set before any usage and can only be set once, this function may be used without locking the record.

func (*Base) GetAccessor

func (b *Base) GetAccessor(self Record) accessor.Accessor

GetAccessor returns an accessor for this record, if available.

func (*Base) IsWrapped

func (b *Base) IsWrapped() bool

IsWrapped returns whether the record is a Wrapper.

func (*Base) Key

func (b *Base) Key() string

Key returns the key of the database record. As the key must be set before any usage and can only be set once, this function may be used without locking the record.

func (*Base) KeyIsSet

func (b *Base) KeyIsSet() bool

KeyIsSet returns true if the database key is set. As the key must be set before any usage and can only be set once, this function may be used without locking the record.

func (*Base) Marshal

func (b *Base) Marshal(self Record, format uint8) ([]byte, error)

Marshal marshals the object, without the database key or metadata. It returns nil if the record is deleted.

func (*Base) MarshalRecord

func (b *Base) MarshalRecord(self Record) ([]byte, error)

MarshalRecord packs the object, including metadata, into a byte array for saving in a database.

func (*Base) Meta

func (b *Base) Meta() *Meta

Meta returns the metadata object for this record.

func (*Base) SetKey

func (b *Base) SetKey(key string)

SetKey sets the key on the database record. The key may only be set once and future calls to SetKey will be ignored. If you want to copy/move the record to another database key, you will need to create a copy and assign a new key. A key must be set before the record is used in any database operation.

func (*Base) SetMeta

func (b *Base) SetMeta(meta *Meta)

SetMeta sets the metadata on the database record, it should only be called after loading the record. Use MoveTo to save the record with another key.

func (*Base) UpdateMeta

func (b *Base) UpdateMeta()

UpdateMeta creates the metadata if it does not exist and updates it.

type Meta

type Meta struct {
	Created  int64
	Modified int64
	Expires  int64
	Deleted  int64
	// contains filtered or unexported fields
}

Meta holds

func (*Meta) CheckPermission

func (m *Meta) CheckPermission(local, internal bool) (permitted bool)

CheckPermission checks whether the database record may be accessed with the following scope.

func (*Meta) CheckValidity

func (m *Meta) CheckValidity() (valid bool)

CheckValidity checks whether the database record is valid.

func (*Meta) Delete

func (m *Meta) Delete()

Delete marks the record as deleted.

func (*Meta) Duplicate

func (m *Meta) Duplicate() *Meta

Duplicate returns a new copy of Meta.

func (*Meta) GenCodeMarshal

func (m *Meta) GenCodeMarshal(buf []byte) ([]byte, error)

GenCodeMarshal gencode marshalls Meta into the given byte array, or a new one if its too small.

func (*Meta) GenCodeSize

func (m *Meta) GenCodeSize() (s int)

GenCodeSize returns the size of the gencode marshalled byte slice

func (*Meta) GenCodeUnmarshal

func (m *Meta) GenCodeUnmarshal(buf []byte) (uint64, error)

GenCodeUnmarshal gencode unmarshalls Meta and returns the bytes read.

func (*Meta) GetAbsoluteExpiry

func (m *Meta) GetAbsoluteExpiry() int64

GetAbsoluteExpiry returns the absolute expiry time.

func (*Meta) GetRelativeExpiry

func (m *Meta) GetRelativeExpiry() int64

GetRelativeExpiry returns the current relative expiry time - ie. seconds until expiry. A negative value signifies that the record does not expire.

func (*Meta) IsDeleted

func (m *Meta) IsDeleted() bool

IsDeleted returns whether the record is deleted.

func (*Meta) MakeCrownJewel

func (m *Meta) MakeCrownJewel()

MakeCrownJewel marks the database records as a crownjewel, meaning that it will not be sent/synced to other devices.

func (*Meta) MakeSecret

func (m *Meta) MakeSecret()

MakeSecret sets the database record as secret, meaning that it may only be used internally, and not by interfacing processes, such as the UI.

func (*Meta) Reset

func (m *Meta) Reset()

Reset resets all metadata, except for the secret and crownjewel status.

func (*Meta) SetAbsoluteExpiry

func (m *Meta) SetAbsoluteExpiry(seconds int64)

SetAbsoluteExpiry sets an absolute expiry time (in seconds), that is not affected when the record is updated.

func (*Meta) SetRelativateExpiry

func (m *Meta) SetRelativateExpiry(seconds int64)

SetRelativateExpiry sets a relative expiry time (ie. TTL in seconds) that is automatically updated whenever the record is updated/saved.

func (*Meta) Update

func (m *Meta) Update()

Update updates the internal meta states and should be called before writing the record to the database.

type Record

type Record interface {
	SetKey(key string) // test:config
	Key() string       // test:config
	KeyIsSet() bool
	DatabaseName() string // test
	DatabaseKey() string  // config

	Meta() *Meta
	SetMeta(meta *Meta)
	CreateMeta()
	UpdateMeta()

	Marshal(self Record, format uint8) ([]byte, error)
	MarshalRecord(self Record) ([]byte, error)
	GetAccessor(self Record) accessor.Accessor

	Lock()
	Unlock()

	IsWrapped() bool
}

Record provides an interface for uniformally handling database records.

type Wrapper

type Wrapper struct {
	Base
	sync.Mutex

	Format uint8
	Data   []byte
}

Wrapper wraps raw data and implements the Record interface.

func NewRawWrapper

func NewRawWrapper(database, key string, data []byte) (*Wrapper, error)

NewRawWrapper returns a record wrapper for the given data, including metadata. This is normally only used by storage backends when loading records.

func NewWrapper

func NewWrapper(key string, meta *Meta, format uint8, data []byte) (*Wrapper, error)

NewWrapper returns a new record wrapper for the given data.

func (*Wrapper) GetAccessor

func (w *Wrapper) GetAccessor(self Record) accessor.Accessor

GetAccessor returns an accessor for this record, if available.

func (*Wrapper) IsWrapped

func (w *Wrapper) IsWrapped() bool

IsWrapped returns whether the record is a Wrapper.

func (*Wrapper) Marshal

func (w *Wrapper) Marshal(r Record, format uint8) ([]byte, error)

Marshal marshals the object, without the database key or metadata

func (*Wrapper) MarshalRecord

func (w *Wrapper) MarshalRecord(r Record) ([]byte, error)

MarshalRecord packs the object, including metadata, into a byte array for saving in a database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto