Skip to content

Commit

Permalink
feat(db-ql): refactor query & document api impl;
Browse files Browse the repository at this point in the history
deprecate joins api; deprecate merge();
  • Loading branch information
maslow committed Oct 16, 2021
1 parent 536fe94 commit dbeb55a
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 611 deletions.
5 changes: 3 additions & 2 deletions packages/database-ql/src/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ActionType } from './constant'
import { Db } from './index'
import { RequestInterface } from './interface'
import { GetRes } from './result-types'
Expand All @@ -22,9 +23,9 @@ export default class Aggregation {
if (!this._collectionName || !this._db) {
throw new Error('Aggregation pipeline cannot send request')
}
const result = await this._request.send('database.aggregate', {
const result = await this._request.send(ActionType.aggregate, {
collectionName: this._collectionName,
stages: this._stages
// stages: this._stages
})
if (result && result.data && result.data.list) {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/database-ql/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CollectionReference extends Query {
/**
* 获取文档的引用
*
* @param docID - 文档ID
* @param docID - 文档 ID
*/
doc(docID: string | number): DocumentReference {
if (!docID) {
Expand Down
30 changes: 15 additions & 15 deletions packages/database-ql/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const WhereFilterOpList = ['<', '<=', '==', '>=', '>']
/**
* 操作符别名
*/
enum Opeartor {
enum Operator {
lt = '<',
gt = '>',
lte = '<=',
Expand All @@ -77,11 +77,11 @@ enum Opeartor {
* SDK => MongoDB
*/
const OperatorMap = {
[Opeartor.eq]: '$eq',
[Opeartor.lt]: '$lt',
[Opeartor.lte]: '$lte',
[Opeartor.gt]: '$gt',
[Opeartor.gte]: '$gte'
[Operator.eq]: '$eq',
[Operator.lt]: '$lt',
[Operator.lte]: '$lte',
[Operator.gt]: '$gt',
[Operator.gte]: '$gte'
}

const UpdateOperatorList = [
Expand All @@ -98,24 +98,24 @@ const UpdateOperatorList = [
'$position'
]

/**
* queryType
*/

enum QueryType {
WHERE = 'WHERE',
DOC = 'DOC'
enum ActionType {
add = 'database.addDocument',
query = 'database.queryDocument',
update = 'database.updateDocument',
count = 'database.countDocument',
remove = 'database.deleteDocument',
aggregate = 'database.aggregate'
}

export {
ErrorCode,
FieldType,
WhereFilterOp,
WhereFilterOpList,
Opeartor,
Operator,
OperatorMap,
OrderByDirection,
OrderDirectionList,
UpdateOperatorList,
QueryType
ActionType
}
Loading

0 comments on commit dbeb55a

Please sign in to comment.