62 lines
1.2 KiB
Markdown
62 lines
1.2 KiB
Markdown
# InMemory Repository
|
|
|
|
Implementation of the [@apihub24/repository](https://www.npmjs.com/package/@apihub24/repository) to store the Objects in Memory.
|
|
|
|
## Install
|
|
|
|
```bash
|
|
npm i --save @apihub24/in-memory-repository
|
|
```
|
|
|
|
## Usage
|
|
|
|
```typescript
|
|
import { InMemoryRepository } from '@apihub24/in-memory-repository';
|
|
|
|
class TestModel {
|
|
id: string;
|
|
name: string;
|
|
age: number;
|
|
}
|
|
|
|
async function run() {
|
|
const repo = new InMemoryRepository<TestModel>();
|
|
|
|
// writes {id:"1",name:"Test",age:28} into console
|
|
console.info(await repo.save({
|
|
id: '1',
|
|
name: 'Test'
|
|
age: 28,
|
|
}));
|
|
|
|
// writes [{id:"1",name:"Test",age:28}] into console
|
|
console.info(await repo.getBy(x => x.name === 'Test'));
|
|
|
|
// writes true into console
|
|
console.info(await repo.deleteBy(x => x.name === 'Test'));
|
|
}
|
|
run();
|
|
```
|
|
|
|
or use it in nestjs with dependency injection
|
|
|
|
```typescript
|
|
...
|
|
{
|
|
provide: '@apihub24/organization_repository',
|
|
useClass: InMemoryRepository<IOrganization>,
|
|
},
|
|
{
|
|
provide: '@apihub24/account_repository',
|
|
useClass: InMemoryRepository<IAccount>,
|
|
},
|
|
{
|
|
provide: '@apihub24/group_repository',
|
|
useClass: InMemoryRepository<IGroup>,
|
|
},
|
|
{
|
|
provide: '@apihub24/right_repository',
|
|
useClass: InMemoryRepository<IRight>,
|
|
},
|
|
```
|