项目作者: BeameryHQ

项目描述 :
Create Database agnostic aggregations base on data pipelines
高级语言: TypeScript
项目地址: git://github.com/BeameryHQ/queryCraft-pipelines.git
创建时间: 2017-12-11T14:41:28Z
项目社区:https://github.com/BeameryHQ/queryCraft-pipelines

开源协议:MIT License

下载


QueryCraft-Pipelines

Database agnostic formulation for data pipelines

NPM

npm version
codecov
Known Vulnerabilities

Installation

  1. npm install --save 'querycraft-pipelines'

Examples

Suppose we have a collection of data that satisfies the interface

  1. interface contact {
  2. id: string
  3. 'list': { id: string }[]
  4. firstName: string
  5. lastName: string
  6. email: string
  7. createdAt: Date
  8. customFields: { id: string, value: number }[]
  9. assignedTo?: string
  10. }

If we want an aggregations the describes the logic:-

  1. where
  2. fistName is bob
  3. lastName is doyle OR is not set
  4. assignedTo is anything
  5. list has an item where id is item1
  6. Group by
  7. the value property of the customField where id is custom1

We can build build it as easily as:-

  1. import { FilterBuilder, eq, lt, neq, any, find, where } from 'querycraft'
  2. import { Pipeline } from 'querycraft-pipelines'
  3. const contacts: contact[] = [ ... ]
  4. const pipeline = new Pipeline()
  5. .filter(
  6. where('firstName', eq('bob'))
  7. .where('list', find(where('id', eq('item1'))))
  8. .where('lastName', any([
  9. eq('doyle'),
  10. eq(null)
  11. ]))
  12. .where('createdAt', lt({ daysAgo: 5 }))
  13. .where('assignedTo', neq(null))
  14. )
  15. .buckets({
  16. fieldId: 'CustomFields',
  17. subFieldIds: ['custom1'],
  18. subFieldProp: 'value',
  19. })