memory

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package memory provides an in-memory implementation of adapter.Adapter.

It executes schema-driven generic CRUD operations with indexing and unique constraint checking in memory. It is ideal for unit tests, local development, and CI environments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter is an in-memory adapter.Adapter implementation.

func New

func New() *Adapter

New creates an empty in-memory generic Adapter.

func (*Adapter) Count

func (a *Adapter) Count(ctx context.Context, model string, where []adapter.Condition) (int64, error)

Count returns the number of records matching the conditions.

func (*Adapter) Create

func (a *Adapter) Create(ctx context.Context, model string, data map[string]any) (map[string]any, error)

Create inserts a record into the specified model.

func (*Adapter) Delete

func (a *Adapter) Delete(ctx context.Context, model string, where []adapter.Condition) (int64, error)

Delete removes matching records.

func (*Adapter) FindMany

func (a *Adapter) FindMany(ctx context.Context, q adapter.Query) ([]map[string]any, error)

FindMany returns all records matching query conditions, supporting sorting and pagination.

func (*Adapter) FindOne

func (a *Adapter) FindOne(ctx context.Context, model string, where []adapter.Condition) (map[string]any, error)

FindOne returns the first record matching all given conditions.

func (*Adapter) RegisterSchema

func (a *Adapter) RegisterSchema(ctx context.Context, s *schema.Schema) error

RegisterSchema registers the compiled schema into the in-memory adapter.

func (*Adapter) Transaction

func (a *Adapter) Transaction(ctx context.Context, fn func(ctx context.Context, tx adapter.Adapter) error) error

Transaction executes fn atomically, rolling back if fn returns an error. Nested transactions join the parent transaction.

func (*Adapter) Update

func (a *Adapter) Update(ctx context.Context, model string, where []adapter.Condition, update map[string]any) (int64, error)

Update modifies matching records in place.

Jump to

Keyboard shortcuts

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