feat: add cc-server-db

This commit is contained in:
2019-06-11 13:09:50 +08:00
parent 7d84393a3c
commit 73daf1e44e
18 changed files with 129 additions and 87 deletions

4
packages/cc-server-db/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@@ -0,0 +1,11 @@
# `cc-server-db`
> TODO: description
## Usage
```
const ccServerDb = require('cc-server-db');
// TODO: DEMONSTRATE API
```

View File

@@ -0,0 +1,27 @@
{
"name": "cc-server-db",
"version": "0.0.2",
"description": "Now Im the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin letters to relatives / Embellishin my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
"keywords": [],
"author": "MiaoWoo <admin@yumc.pw>",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/502647092/cc-server-parent.git"
},
"scripts": {
"build": "npx tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/502647092/cc-server-parent/issues"
},
"homepage": "https://github.com/502647092/cc-server-parent#readme",
"dependencies": {
"typescript": "^3.5.1"
}
}

View File

@@ -0,0 +1,11 @@
export const DBClient = Symbol.for('DBClient')
export interface DBClient<T = any> {
find(collection: string, filter: object): Promise<T[]>;
findOne(collection: string, filter: Object): Promise<T>;
findOneById(collection: string, objectId: string): Promise<T>;
insertOne(collection: string, model: T): Promise<T>;
updateOne(collection: string, where: any, model: any): Promise<boolean>;
updateById(collection: string, objectId: string, model: any): Promise<boolean>;
deleteOne(collection: string, where: any): Promise<boolean>;
deleteById(collection: string, objectId: string): Promise<boolean>;
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}