entity

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

README

Aerospike Entity

Import path: github.com/InsideGallery/core/db/aerospike/entity

This package provides entity-scoped helpers on top of the Aerospike namespace contracts. New code can use the core-owned Store; older code can keep using the SDK-shaped Operation wrapper.

Main APIs

  • NewStore(namespace, key) creates a Store from an aerospike.NamespaceStore and record key.
  • Store.Put, Store.Get, Store.GetBin, Store.Exists, and Store.Delete wrap record operations.
  • RecordStore is the core-owned interface implemented by *Store.
  • BinOptions, BinResult, and ExistsResult describe bin and existence results.
  • ErrStoreNotSet reports a nil store or namespace dependency.
  • NewOperation creates the legacy operation wrapper around aerospike.Namespace.
  • Operation.Execute, Get, GetBin, Exists, and GetNamespace expose the legacy SDK-shaped flow.
  • Operations is the legacy interface used by the generated mocks package.
  • ErrAttributeNotFound is returned by legacy Operation.GetBin when the record or bin map is missing.

Store accepts a nil context by replacing it with context.Background(). Operation errors returned by the namespace store are wrapped with the aerospike entity boundary.

Usage

package example

import (
	"context"

	aero "github.com/InsideGallery/core/db/aerospike"
	"github.com/InsideGallery/core/db/aerospike/entity"
)

func readUserName(ctx context.Context, namespace aero.NamespaceStore) (any, error) {
	store := entity.NewStore(namespace, aero.Key{Set: "users", Value: "42"})

	result, err := store.GetBin(ctx, entity.BinOptions{Name: "name"})
	if err != nil {
		return nil, err
	}
	if !result.Found {
		return nil, nil
	}

	return result.Value, nil
}

Operational Notes

The legacy Operation wrapper builds an Aerospike write policy for Execute, sets SendKey from the constructor argument, and applies Expiration only when the supplied expiration is greater than zero.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAttributeNotFound = errors.New("attribute not found")
View Source
var ErrStoreNotSet = errors.New("entity store is not set")

ErrStoreNotSet reports a nil entity store dependency.

Functions

This section is empty.

Types

type BinOptions added in v1.1.0

type BinOptions struct {
	Name string
}

BinOptions is the core-owned input for reading one entity bin.

type BinResult added in v1.1.0

type BinResult struct {
	Found bool
	Value any
}

BinResult is the core-owned result for reading one entity bin.

type ExistsResult added in v1.1.0

type ExistsResult struct {
	Exists bool
}

ExistsResult is the core-owned result for an entity existence check.

type Operation

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

func NewOperation

func NewOperation(
	client aerospike.Namespace,
	setName string,
	pk interface{},
	sendKey bool,
	expiration uint32,
) *Operation

func (*Operation) Execute

func (h *Operation) Execute(operations []*as.Operation) error

func (*Operation) Exists

func (h *Operation) Exists() (bool, as.Error)

func (*Operation) Get

func (h *Operation) Get(bins ...string) (*as.Record, error)

func (*Operation) GetBin

func (h *Operation) GetBin(binName string) (interface{}, error)

func (*Operation) GetNamespace

func (h *Operation) GetNamespace() aerospike.Namespace

type Operations

type Operations interface {
	Execute([]*as.Operation) error
	GetNamespace() aerospike.Namespace //nolint:staticcheck // legacy entity operations keep the namespace shim
	Get(bins ...string) (*as.Record, error)
	GetBin(binName string) (interface{}, error)
	Exists() (bool, as.Error)
}

type RecordStore added in v1.1.0

type RecordStore interface {
	Put(ctx context.Context, bins map[string]any) (aero.Result, error)
	Get(ctx context.Context, bins ...string) (aero.RecordResult, error)
	GetBin(ctx context.Context, options BinOptions) (BinResult, error)
	Exists(ctx context.Context) (ExistsResult, error)
	Delete(ctx context.Context) (aero.Result, error)
}

RecordStore is the core-owned contract for common Aerospike entity helpers.

type Store added in v1.1.0

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

Store wraps record-level entity helpers behind core-owned Aerospike contracts.

func NewStore added in v1.1.0

func NewStore(namespace aero.NamespaceStore, key aero.Key) *Store

NewStore creates entity helpers from a core-owned namespace store and key.

func (*Store) Delete added in v1.1.0

func (s *Store) Delete(ctx context.Context) (aero.Result, error)

Delete deletes an entity through a core-owned namespace store.

func (*Store) Exists added in v1.1.0

func (s *Store) Exists(ctx context.Context) (ExistsResult, error)

Exists checks whether an entity exists through a core-owned namespace store.

func (*Store) Get added in v1.1.0

func (s *Store) Get(ctx context.Context, bins ...string) (aero.RecordResult, error)

Get reads an entity record through a core-owned namespace store.

func (*Store) GetBin added in v1.1.0

func (s *Store) GetBin(ctx context.Context, options BinOptions) (BinResult, error)

GetBin reads one entity bin through a core-owned namespace store.

func (*Store) Put added in v1.1.0

func (s *Store) Put(ctx context.Context, bins map[string]any) (aero.Result, error)

Put writes entity bins through a core-owned namespace store.

Directories

Path Synopsis
Package mock_entity is a generated GoMock package.
Package mock_entity is a generated GoMock package.

Jump to

Keyboard shortcuts

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