Entity Storage Connector Memory Examples
Use these snippets to perform fast in-memory storage operations during development and unit testing.
MemoryEntityStorageConnector
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
import {
ComparisonOperator,
LogicalOperator,
SortDirection,
type EntityCondition
} from '@twin.org/entity';
interface Profile {
id: string;
email: string;
status: 'active' | 'inactive';
createdAt: string;
}
const connector = new MemoryEntityStorageConnector<Profile>({
entitySchema: 'Profile',
partitionContextIds: ['tenantId']
});
const className = connector.className();
const schema = connector.getSchema();
await connector.set({
id: 'profile-1',
email: '[email protected]',
status: 'active',
createdAt: '2026-03-09T10:30:00.000Z'
});
const byPrimaryKey = await connector.get('profile-1');
const bySecondaryIndex = await connector.get('[email protected]', 'email');
const activeCondition: EntityCondition<Profile> = {
logicalOperator: LogicalOperator.And,
conditions: [
{
property: 'status',
comparison: ComparisonOperator.Equals,
value: 'active'
}
]
};
const result = await connector.query(
activeCondition,
[{ property: 'createdAt', sortDirection: SortDirection.Descending }],
['id', 'email', 'status'],
undefined,
25
);
await connector.remove('profile-1');
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
interface Profile {
id: string;
email: string;
status: 'active' | 'inactive';
createdAt: string;
}
const connector = new MemoryEntityStorageConnector<Profile>({
entitySchema: 'Profile'
});
const store = connector.getStore();