refactor
This commit is contained in:
parent
08fd76dcef
commit
f94e266d4a
61
README.md
Normal file
61
README.md
Normal file
@ -0,0 +1,61 @@
|
||||
# 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>,
|
||||
},
|
||||
```
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@ -9,16 +9,16 @@
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apihub24/repository": "^1.0.1"
|
||||
"@apihub24/repository": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@apihub24/repository": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apihub24/repository/-/repository-1.0.1.tgz",
|
||||
"integrity": "sha512-ex3Z+lxsHtVKDTolJQqLHswq9SKfXzM/hWv17zsrhKqJwuGxO7CeBFM60aiuApZX9NqBhGAkPGGj9jt+F/Y9HQ==",
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@apihub24/repository/-/repository-1.0.2.tgz",
|
||||
"integrity": "sha512-brZkSENCpC1/MJYBSHHeO+8odrKdq/q4U2z7HN5mrAvPl8GNjq0egOCZ22axQKynWuP9yimIIwJxExwp12YBzQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apihub24/in-memory-repository",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
@ -8,7 +8,7 @@
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apihub24/repository": "^1.0.1"
|
||||
"@apihub24/repository": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2"
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Repository } from '@apihub24/repository';
|
||||
import { IRepository } from "@apihub24/repository";
|
||||
|
||||
interface IdModel {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class InMemoryRepository<TModel extends IdModel>
|
||||
implements Repository<TModel>
|
||||
implements IRepository<TModel>
|
||||
{
|
||||
private source: TModel[] = [];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user