Skip to main content
The Memory adapter provides an in-memory service implementation for testing and rapid prototyping. Data is stored in memory and will be lost when the process exits.

Installation

MemoryService

The main service class for in-memory operations.

Constructor

MemoryServiceOptions
Configuration options for the Memory adapter
string
default:"id"
Name of the id field property
MemoryServiceStore<T>
Initial data store object with id as keys. Default is {}
number
default:"0"
Starting value for auto-generated ids
PaginationParams
Pagination settings with default and max page size
boolean | string[]
Allow multiple updates. Can be true, false, or an array of method names
(query: any) => any
Custom query matcher function. Default uses sift
(sort: any) => any
Custom sorting function. Default uses built-in sorter

Service Methods

find

Retrieve multiple records from memory.
ServiceParams
AdapterQuery
Query filters including $limit, $skip, $sort, $select, and comparison operators
PaginationOptions | false
Override pagination settings
Paginated<Result> | Result[]
Paginated results or array depending on settings

get

Retrieve a single record by id.
Id
required
The record id to retrieve
ServiceParams
Additional query filters to match
Result
The found record

create

Create one or more new records.
Data | Data[]
required
Record data to create. If id is not provided, it will be auto-generated
Result | Result[]
The created record(s)

update

Completely replace a record.
Id
required
The record id to update
Data
required
Complete record data to replace with
Result
The updated record

patch

Partially update one or multiple records.
Id | null
required
The record id to patch, or null to patch multiple records matching the query
PatchData
required
Partial data to merge with existing record(s)
ServiceParams
AdapterQuery
Query to filter which records to patch (when id is null)
Result | Result[]
The patched record(s)

remove

Remove one or multiple records.
Id | null
required
The record id to remove, or null to remove multiple records
ServiceParams
AdapterQuery
Query to filter which records to remove (when id is null)
Result | Result[]
The removed record(s)

MemoryAdapter

The base adapter class that MemoryService extends.

Properties

store

Direct access to the in-memory data store.

Methods

getEntries

Retrieve all entries matching a query.
Result[]
Array of all matching entries

Query Syntax

The Memory adapter supports MongoDB-style query syntax via the sift library.

Comparison Operators

Array Operators

Logical Operators

Element Operators

Special Query Parameters

Regular Expressions

Custom Matcher and Sorter

Provide custom query matching and sorting logic:

Example

Testing

The Memory adapter is ideal for testing: