-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: splited logic beеween couchdb and nest contexts * feat(repository): updated repositiry factory * test(couchdb): added repository factory coverage * refactor: changed ts asserts to generics * test(module): added inject decorators coverage * refactor(couchdb): added repository mixin and Repository interface * test(couchdb): added repository methods coverage * docs: added README
- Loading branch information
1 parent
f39499c
commit 2c4c95d
Showing
50 changed files
with
5,897 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,7 @@ typings/ | |
.next | ||
|
||
# Build | ||
dist/ | ||
dist/* | ||
!dist/package.json | ||
!dist/README.md | ||
!dist/LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2019 Scal.io, LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,114 @@ | ||
# nest-couchdb | ||
CouchDB module for Nest framework | ||
## Description | ||
|
||
The [CouchDB](http://couchdb.apache.org/) module for Nest framework | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm i @scalio/nest-couchdb nano | ||
``` | ||
|
||
## Usage | ||
|
||
`@scalio/nest-couchdb` uses [nano](https://www.npmjs.com/package/nano) as a data provider for CouchDB and the `Repository` pattern to handle all documents related operations. | ||
|
||
First, let's create an `Entity`: | ||
|
||
```typescript | ||
import { Entity, CouchDbEntity } from '@scalio/nest-couchdb'; | ||
|
||
@Entity('cats') | ||
export class Cat extends CouchDbEntity { | ||
name: string; | ||
} | ||
``` | ||
|
||
Where `cats` is the CouchDB database name. | ||
|
||
The `CouchDbEntity` is a base class which has some common properties: | ||
|
||
```typescript | ||
class CouchDbEntity { | ||
_id: string; | ||
_rev: string; | ||
} | ||
``` | ||
|
||
Then, we need to import `CouchDbModule` in our `ApplicationModule`: | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { CouchDbModule } from '@scalio/nest-couchdb'; | ||
|
||
@Module({ | ||
imports: [ | ||
CouchDbModule.forRoot({ | ||
url: 'http://localhost:5984', | ||
username: 'couchdb', | ||
userpass: 'password', | ||
requestDefaults: { jar: true }, | ||
}), | ||
], | ||
}) | ||
export class ApplicationModule {} | ||
``` | ||
|
||
In our `CatsModule` we need to initiate repository for our `Cat` entity: | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { CouchDbModule } from '@scalio/nest-couchdb'; | ||
import { CatsService } from './cats.service'; | ||
import { CatsController } from './cats.controller'; | ||
import { Cat } from './cat.entity'; | ||
|
||
@Module({ | ||
imports: [CouchDbModule.forFeature([Cat])], | ||
providers: [CatsService], | ||
controllers: [CatsController], | ||
}) | ||
export class CatsModule {} | ||
``` | ||
|
||
And here is the usage of the repository in the service: | ||
|
||
```typescript | ||
import { DocumentListResponse } from 'nano'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository, Repository } from '@scalio/nest-couchdb'; | ||
import { Cat } from './cat.entity'; | ||
|
||
@Injectable() | ||
export class CatsService { | ||
constructor( | ||
@InjectRepository(Cat) | ||
private readonly catsRepository: Repository<Cat>, | ||
) {} | ||
|
||
findAll(): Promise<DocumentListResponse<Cat> { | ||
return this.catsRepository.list(); | ||
} | ||
} | ||
``` | ||
## Test | ||
```bash | ||
$ docker-compose up -d | ||
$ npm test | ||
``` | ||
## License | ||
[MIT](LICENSE) | ||
## Credits | ||
Created by [@zMotivat0r](https://github.com/zMotivat0r) @ [Scalio](https://scal.io/) | ||
<p align="center"> | ||
<br/> | ||
<a href="https://scal.io/"> | ||
<img src="https://raw.githubusercontent.com/scalio/bazel-nestjs-starter/master/readme-assets/scalio.png"/> | ||
</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2019 Scal.io, LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
## Description | ||
|
||
The [CouchDB](http://couchdb.apache.org/) module for Nest framework | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm i @scalio/nest-couchdb nano | ||
``` | ||
|
||
## Usage | ||
|
||
`@scalio/nest-couchdb` uses [nano](https://www.npmjs.com/package/nano) as a data provider for CouchDB and the `Repository` pattern to handle all documents related operations. | ||
|
||
First, let's create an `Entity`: | ||
|
||
```typescript | ||
import { Entity, CouchDbEntity } from '@scalio/nest-couchdb'; | ||
|
||
@Entity('cats') | ||
export class Cat extends CouchDbEntity { | ||
name: string; | ||
} | ||
``` | ||
|
||
Where `cats` is the CouchDB database name. | ||
|
||
The `CouchDbEntity` is a base class which has some common properties: | ||
|
||
```typescript | ||
class CouchDbEntity { | ||
_id: string; | ||
_rev: string; | ||
} | ||
``` | ||
|
||
Then, we need to import `CouchDbModule` in our `ApplicationModule`: | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { CouchDbModule } from '@scalio/nest-couchdb'; | ||
|
||
@Module({ | ||
imports: [ | ||
CouchDbModule.forRoot({ | ||
url: 'http://localhost:5984', | ||
username: 'couchdb', | ||
userpass: 'password', | ||
requestDefaults: { jar: true }, | ||
}), | ||
], | ||
}) | ||
export class ApplicationModule {} | ||
``` | ||
|
||
In our `CatsModule` we need to initiate repository for our `Cat` entity: | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { CouchDbModule } from '@scalio/nest-couchdb'; | ||
import { CatsService } from './cats.service'; | ||
import { CatsController } from './cats.controller'; | ||
import { Cat } from './cat.entity'; | ||
|
||
@Module({ | ||
imports: [CouchDbModule.forFeature([Cat])], | ||
providers: [CatsService], | ||
controllers: [CatsController], | ||
}) | ||
export class CatsModule {} | ||
``` | ||
|
||
And here is the usage of the repository in the service: | ||
|
||
```typescript | ||
import { DocumentListResponse } from 'nano'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository, Repository } from '@scalio/nest-couchdb'; | ||
import { Cat } from './cat.entity'; | ||
|
||
@Injectable() | ||
export class CatsService { | ||
constructor( | ||
@InjectRepository(Cat) | ||
private readonly catsRepository: Repository<Cat>, | ||
) {} | ||
|
||
findAll(): Promise<DocumentListResponse<Cat> { | ||
return this.catsRepository.list(); | ||
} | ||
} | ||
``` | ||
## Test | ||
```bash | ||
$ docker-compose up -d | ||
$ npm test | ||
``` | ||
## License | ||
[MIT](LICENSE) | ||
## Credits | ||
Created by [@zMotivat0r](https://github.com/zMotivat0r) @ [Scalio](https://scal.io/) | ||
<p align="center"> | ||
<br/> | ||
<a href="https://scal.io/"> | ||
<img src="https://raw.githubusercontent.com/scalio/bazel-nestjs-starter/master/readme-assets/scalio.png"/> | ||
</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@scalio/nest-couchdb", | ||
"description": "CouchDB module for Nest framework", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"typings": "index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/scalio/nest-couchdb.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/scalio/nest-couchdb/issues" | ||
}, | ||
"keywords": [ | ||
"typescript", | ||
"couchdb", | ||
"orm", | ||
"nest", | ||
"nestjs", | ||
"api", | ||
"backend", | ||
"frameworks" | ||
], | ||
"author": { | ||
"name": "Michael Yali", | ||
"email": "mihon4ik@gmail.com" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('reflect-metadata'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.