@ihago.santos/fluentsql 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ihago.santos/fluentsql",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/fluentSQL.js CHANGED
@@ -4,7 +4,7 @@ export default class FluentSQLBuilder {
4
4
  #select = []
5
5
  #where = []
6
6
  #orderBy = ''
7
- #groupCount = ''
7
+ #countBy = ''
8
8
 
9
9
  constructor({ database }) {
10
10
  this.#database = database
@@ -43,8 +43,8 @@ export default class FluentSQLBuilder {
43
43
  return this
44
44
  }
45
45
 
46
- groupCount(field) {
47
- this.#groupCount = field
46
+ countBy(field) {
47
+ this.#countBy = field
48
48
  return this
49
49
  }
50
50
 
@@ -82,12 +82,12 @@ export default class FluentSQLBuilder {
82
82
 
83
83
  }
84
84
 
85
- #performGroupCount(results) {
86
- if(!this.#groupCount) return results
85
+ #performCount(results) {
86
+ if(!this.#countBy) return results
87
87
 
88
88
  const accumulator = {}
89
89
  for(const result of results) {
90
- const targetField = result[this.#groupCount]
90
+ const targetField = result[this.#countBy]
91
91
  accumulator[targetField] = accumulator[targetField] ?? 0
92
92
  accumulator[targetField] += 1
93
93
  }
@@ -106,7 +106,7 @@ export default class FluentSQLBuilder {
106
106
 
107
107
  }
108
108
 
109
- const grouped = this.#performGroupCount(results)
109
+ const grouped = this.#performCount(results)
110
110
  const orderedResult = this.#performOrderBy(grouped)
111
111
  return orderedResult
112
112
  }
@@ -84,9 +84,9 @@ describe('Test Suite for FluentSQL Builder', () => {
84
84
  expect(result).toStrictEqual(expected)
85
85
  })
86
86
 
87
- test('#groupCount given a collection it should group results by field', () => {
87
+ test('#countBy given a collection it should group results by field', () => {
88
88
  const result = FluentSQLBuilder.for(data)
89
- .groupCount('category')
89
+ .countBy('category')
90
90
  .build()
91
91
 
92
92
  const expected = [