json-fs-query 0.1.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/.browserslistrc +1 -0
- package/.nvmrc +1 -0
- package/LICENSE +674 -0
- package/MAIN.md +15 -0
- package/README.md +63 -0
- package/babel.config.js +3 -0
- package/build-tools.config.json +30 -0
- package/dist/data/introspect/create.d.ts +11 -0
- package/dist/data/introspect/create.js +45 -0
- package/dist/data/introspect/create.min.js +1 -0
- package/dist/data/introspect/definitions/field.d.ts +28 -0
- package/dist/data/introspect/definitions/field.js +36 -0
- package/dist/data/introspect/definitions/field.min.js +1 -0
- package/dist/data/introspect/definitions/key.d.ts +26 -0
- package/dist/data/introspect/definitions/key.js +53 -0
- package/dist/data/introspect/definitions/key.min.js +1 -0
- package/dist/data/introspect/definitions/keyReference.d.ts +18 -0
- package/dist/data/introspect/definitions/keyReference.js +20 -0
- package/dist/data/introspect/definitions/keyReference.min.js +1 -0
- package/dist/data/introspect/definitions/record.d.ts +26 -0
- package/dist/data/introspect/definitions/record.js +32 -0
- package/dist/data/introspect/definitions/record.min.js +1 -0
- package/dist/data/introspect/describe.d.ts +2 -0
- package/dist/data/introspect/describe.js +15 -0
- package/dist/data/introspect/describe.min.js +1 -0
- package/dist/data/introspect/drop.d.ts +2 -0
- package/dist/data/introspect/drop.js +37 -0
- package/dist/data/introspect/drop.min.js +1 -0
- package/dist/data/introspect/index.d.ts +8 -0
- package/dist/data/introspect/index.js +30 -0
- package/dist/data/introspect/index.min.js +1 -0
- package/dist/data/introspect/policies/foreignKeyExists.d.ts +9 -0
- package/dist/data/introspect/policies/foreignKeyExists.js +25 -0
- package/dist/data/introspect/policies/foreignKeyExists.min.js +1 -0
- package/dist/data/introspect/policies/keyGenerate.d.ts +2 -0
- package/dist/data/introspect/policies/keyGenerate.js +17 -0
- package/dist/data/introspect/policies/keyGenerate.min.js +1 -0
- package/dist/data/introspect/policies/keyUnique.d.ts +2 -0
- package/dist/data/introspect/policies/keyUnique.js +21 -0
- package/dist/data/introspect/policies/keyUnique.min.js +1 -0
- package/dist/data/introspect/policies/typeCheck.d.ts +12 -0
- package/dist/data/introspect/policies/typeCheck.js +57 -0
- package/dist/data/introspect/policies/typeCheck.min.js +1 -0
- package/dist/data/introspect/policies/typeEnum.d.ts +2 -0
- package/dist/data/introspect/policies/typeEnum.js +14 -0
- package/dist/data/introspect/policies/typeEnum.min.js +1 -0
- package/dist/data/introspect/policies/useDefault.d.ts +2 -0
- package/dist/data/introspect/policies/useDefault.js +13 -0
- package/dist/data/introspect/policies/useDefault.min.js +1 -0
- package/dist/data/queries/deleteEntity.d.ts +2 -0
- package/dist/data/queries/deleteEntity.js +79 -0
- package/dist/data/queries/deleteEntity.min.js +1 -0
- package/dist/data/queries/groupBy.d.ts +2 -0
- package/dist/data/queries/groupBy.js +22 -0
- package/dist/data/queries/groupBy.min.js +1 -0
- package/dist/data/queries/insertEntity.d.ts +2 -0
- package/dist/data/queries/insertEntity.js +115 -0
- package/dist/data/queries/insertEntity.min.js +1 -0
- package/dist/data/queries/joinEntity.d.ts +2 -0
- package/dist/data/queries/joinEntity.js +27 -0
- package/dist/data/queries/joinEntity.min.js +1 -0
- package/dist/data/queries/mergeJoins.d.ts +2 -0
- package/dist/data/queries/mergeJoins.js +19 -0
- package/dist/data/queries/mergeJoins.min.js +1 -0
- package/dist/data/queries/parser.d.ts +2 -0
- package/dist/data/queries/parser.js +30 -0
- package/dist/data/queries/parser.min.js +1 -0
- package/dist/data/queries/query.d.ts +2 -0
- package/dist/data/queries/query.js +18 -0
- package/dist/data/queries/query.min.js +1 -0
- package/dist/data/queries/readEntity.d.ts +2 -0
- package/dist/data/queries/readEntity.js +14 -0
- package/dist/data/queries/readEntity.min.js +1 -0
- package/dist/data/queries/sortBy.d.ts +2 -0
- package/dist/data/queries/sortBy.js +25 -0
- package/dist/data/queries/sortBy.min.js +1 -0
- package/dist/data/queries/updateEntity.d.ts +2 -0
- package/dist/data/queries/updateEntity.js +164 -0
- package/dist/data/queries/updateEntity.min.js +1 -0
- package/dist/data/queries/where.d.ts +7 -0
- package/dist/data/queries/where.js +56 -0
- package/dist/data/queries/where.min.js +1 -0
- package/dist/data/utilities/deregisterRecord.d.ts +8 -0
- package/dist/data/utilities/deregisterRecord.js +34 -0
- package/dist/data/utilities/deregisterRecord.min.js +1 -0
- package/dist/data/utilities/getConditionIndexedList.d.ts +3 -0
- package/dist/data/utilities/getConditionIndexedList.js +47 -0
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -0
- package/dist/data/utilities/getJoinIndexedList.d.ts +3 -0
- package/dist/data/utilities/getJoinIndexedList.js +59 -0
- package/dist/data/utilities/getJoinIndexedList.min.js +1 -0
- package/dist/data/utilities/getMatchingIndexes.d.ts +2 -0
- package/dist/data/utilities/getMatchingIndexes.js +28 -0
- package/dist/data/utilities/getMatchingIndexes.min.js +1 -0
- package/dist/data/utilities/matchIndexedJoins.d.ts +2 -0
- package/dist/data/utilities/matchIndexedJoins.js +61 -0
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -0
- package/dist/data/utilities/mergeJoin.d.ts +2 -0
- package/dist/data/utilities/mergeJoin.js +44 -0
- package/dist/data/utilities/mergeJoin.min.js +1 -0
- package/dist/data/utilities/parsers/findCommand.d.ts +10 -0
- package/dist/data/utilities/parsers/findCommand.js +25 -0
- package/dist/data/utilities/parsers/findCommand.min.js +1 -0
- package/dist/data/utilities/parsers/findConditions.d.ts +15 -0
- package/dist/data/utilities/parsers/findConditions.js +28 -0
- package/dist/data/utilities/parsers/findConditions.min.js +1 -0
- package/dist/data/utilities/parsers/findGroupBy.d.ts +9 -0
- package/dist/data/utilities/parsers/findGroupBy.js +22 -0
- package/dist/data/utilities/parsers/findGroupBy.min.js +1 -0
- package/dist/data/utilities/parsers/findInsertValues.d.ts +13 -0
- package/dist/data/utilities/parsers/findInsertValues.js +34 -0
- package/dist/data/utilities/parsers/findInsertValues.min.js +1 -0
- package/dist/data/utilities/parsers/findJoinClauses.d.ts +13 -0
- package/dist/data/utilities/parsers/findJoinClauses.js +27 -0
- package/dist/data/utilities/parsers/findJoinClauses.min.js +1 -0
- package/dist/data/utilities/parsers/findJoinEntity.d.ts +9 -0
- package/dist/data/utilities/parsers/findJoinEntity.js +22 -0
- package/dist/data/utilities/parsers/findJoinEntity.min.js +1 -0
- package/dist/data/utilities/parsers/findLimit.d.ts +9 -0
- package/dist/data/utilities/parsers/findLimit.js +22 -0
- package/dist/data/utilities/parsers/findLimit.min.js +1 -0
- package/dist/data/utilities/parsers/findMergeJoins.d.ts +12 -0
- package/dist/data/utilities/parsers/findMergeJoins.js +26 -0
- package/dist/data/utilities/parsers/findMergeJoins.min.js +1 -0
- package/dist/data/utilities/parsers/findOffset.d.ts +9 -0
- package/dist/data/utilities/parsers/findOffset.js +22 -0
- package/dist/data/utilities/parsers/findOffset.min.js +1 -0
- package/dist/data/utilities/parsers/findSelects.d.ts +12 -0
- package/dist/data/utilities/parsers/findSelects.js +30 -0
- package/dist/data/utilities/parsers/findSelects.min.js +1 -0
- package/dist/data/utilities/parsers/findSortClauses.d.ts +12 -0
- package/dist/data/utilities/parsers/findSortClauses.js +30 -0
- package/dist/data/utilities/parsers/findSortClauses.min.js +1 -0
- package/dist/data/utilities/parsers/findUpdateValues.d.ts +15 -0
- package/dist/data/utilities/parsers/findUpdateValues.js +34 -0
- package/dist/data/utilities/parsers/findUpdateValues.min.js +1 -0
- package/dist/data/utilities/parsers/isEntityProperty.d.ts +2 -0
- package/dist/data/utilities/parsers/isEntityProperty.js +8 -0
- package/dist/data/utilities/parsers/isEntityProperty.min.js +1 -0
- package/dist/data/utilities/parsers/parseLiteralValue.d.ts +12 -0
- package/dist/data/utilities/parsers/parseLiteralValue.js +34 -0
- package/dist/data/utilities/parsers/parseLiteralValue.min.js +1 -0
- package/dist/data/utilities/parsers/parseQuery.d.ts +33 -0
- package/dist/data/utilities/parsers/parseQuery.js +51 -0
- package/dist/data/utilities/parsers/parseQuery.min.js +1 -0
- package/dist/data/utilities/parsers/removeFromQuery.d.ts +2 -0
- package/dist/data/utilities/parsers/removeFromQuery.js +8 -0
- package/dist/data/utilities/parsers/removeFromQuery.min.js +1 -0
- package/dist/data/utilities/parsers/splitEntityProperty.d.ts +5 -0
- package/dist/data/utilities/parsers/splitEntityProperty.js +23 -0
- package/dist/data/utilities/parsers/splitEntityProperty.min.js +1 -0
- package/dist/data/utilities/parsers/splitQueries.d.ts +2 -0
- package/dist/data/utilities/parsers/splitQueries.js +11 -0
- package/dist/data/utilities/parsers/splitQueries.min.js +1 -0
- package/dist/data/utilities/reconcileJoin.d.ts +2 -0
- package/dist/data/utilities/reconcileJoin.js +26 -0
- package/dist/data/utilities/reconcileJoin.min.js +1 -0
- package/dist/data/utilities/reconcileJoins.d.ts +2 -0
- package/dist/data/utilities/reconcileJoins.js +27 -0
- package/dist/data/utilities/reconcileJoins.min.js +1 -0
- package/dist/data/utilities/registerRecord.d.ts +8 -0
- package/dist/data/utilities/registerRecord.js +67 -0
- package/dist/data/utilities/registerRecord.min.js +1 -0
- package/dist/data/utilities/removeFromIndex.d.ts +14 -0
- package/dist/data/utilities/removeFromIndex.js +46 -0
- package/dist/data/utilities/removeFromIndex.min.js +1 -0
- package/dist/data/utilities/restrictIndexedList.d.ts +2 -0
- package/dist/data/utilities/restrictIndexedList.js +45 -0
- package/dist/data/utilities/restrictIndexedList.min.js +1 -0
- package/dist/data/utilities/retrieveFile.d.ts +2 -0
- package/dist/data/utilities/retrieveFile.js +28 -0
- package/dist/data/utilities/retrieveFile.min.js +1 -0
- package/dist/data/utilities/retrieveIndexes.d.ts +2 -0
- package/dist/data/utilities/retrieveIndexes.js +24 -0
- package/dist/data/utilities/retrieveIndexes.min.js +1 -0
- package/dist/data/utilities/retrieveRecord.d.ts +2 -0
- package/dist/data/utilities/retrieveRecord.js +9 -0
- package/dist/data/utilities/retrieveRecord.min.js +1 -0
- package/dist/data/utilities/retrieveRecords.d.ts +2 -0
- package/dist/data/utilities/retrieveRecords.js +21 -0
- package/dist/data/utilities/retrieveRecords.min.js +1 -0
- package/dist/data/utilities/runQuery.d.ts +2 -0
- package/dist/data/utilities/runQuery.js +72 -0
- package/dist/data/utilities/runQuery.min.js +1 -0
- package/dist/data/utilities/updateIndex.d.ts +17 -0
- package/dist/data/utilities/updateIndex.js +56 -0
- package/dist/data/utilities/updateIndex.min.js +1 -0
- package/dist/data/utilities/useJoinClause.d.ts +6 -0
- package/dist/data/utilities/useJoinClause.js +51 -0
- package/dist/data/utilities/useJoinClause.min.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -0
- package/dist/index.min.js +1 -0
- package/gulpfile.mjs +15 -0
- package/package.json +44 -0
- package/src/data/introspect/create.test.js +67 -0
- package/src/data/introspect/create.ts +29 -0
- package/src/data/introspect/definitions/field.test.js +23 -0
- package/src/data/introspect/definitions/field.ts +48 -0
- package/src/data/introspect/definitions/key.test.js +100 -0
- package/src/data/introspect/definitions/key.ts +64 -0
- package/src/data/introspect/definitions/keyReference.test.js +8 -0
- package/src/data/introspect/definitions/keyReference.ts +23 -0
- package/src/data/introspect/definitions/record.ts +42 -0
- package/src/data/introspect/describe.test.js +36 -0
- package/src/data/introspect/describe.ts +9 -0
- package/src/data/introspect/drop.test.js +77 -0
- package/src/data/introspect/drop.ts +20 -0
- package/src/data/introspect/index.ts +8 -0
- package/src/data/introspect/policies/foreignKeyExists.test.js +44 -0
- package/src/data/introspect/policies/foreignKeyExists.ts +15 -0
- package/src/data/introspect/policies/keyGenerate.ts +11 -0
- package/src/data/introspect/policies/keyUnique.ts +11 -0
- package/src/data/introspect/policies/typeCheck.test.js +84 -0
- package/src/data/introspect/policies/typeCheck.ts +49 -0
- package/src/data/introspect/policies/typeEnum.ts +6 -0
- package/src/data/introspect/policies/useDefault.ts +6 -0
- package/src/data/queries/deleteEntity.test.js +86 -0
- package/src/data/queries/deleteEntity.ts +56 -0
- package/src/data/queries/groupBy.test.js +135 -0
- package/src/data/queries/groupBy.ts +16 -0
- package/src/data/queries/insertEntity.test.js +156 -0
- package/src/data/queries/insertEntity.ts +113 -0
- package/src/data/queries/joinEntity.test.js +109 -0
- package/src/data/queries/joinEntity.ts +20 -0
- package/src/data/queries/mergeJoins.test.js +174 -0
- package/src/data/queries/mergeJoins.ts +13 -0
- package/src/data/queries/parser.test.js +343 -0
- package/src/data/queries/parser.ts +24 -0
- package/src/data/queries/query.test.js +233 -0
- package/src/data/queries/query.ts +12 -0
- package/src/data/queries/readEntity.test.js +85 -0
- package/src/data/queries/readEntity.ts +8 -0
- package/src/data/queries/sortBy.test.js +131 -0
- package/src/data/queries/sortBy.ts +18 -0
- package/src/data/queries/updateEntity.test.js +228 -0
- package/src/data/queries/updateEntity.ts +162 -0
- package/src/data/queries/where.test.js +129 -0
- package/src/data/queries/where.ts +54 -0
- package/src/data/utilities/deregisterRecord.test.js +26 -0
- package/src/data/utilities/deregisterRecord.ts +24 -0
- package/src/data/utilities/getConditionIndexedList.ts +43 -0
- package/src/data/utilities/getJoinIndexedList.ts +53 -0
- package/src/data/utilities/getMatchingIndexes.ts +21 -0
- package/src/data/utilities/matchIndexedJoins.ts +45 -0
- package/src/data/utilities/mergeJoin.test.js +102 -0
- package/src/data/utilities/mergeJoin.ts +28 -0
- package/src/data/utilities/parsers/findCommand.ts +25 -0
- package/src/data/utilities/parsers/findConditions.test.js +38 -0
- package/src/data/utilities/parsers/findConditions.ts +32 -0
- package/src/data/utilities/parsers/findGroupBy.ts +20 -0
- package/src/data/utilities/parsers/findInsertValues.test.js +26 -0
- package/src/data/utilities/parsers/findInsertValues.ts +32 -0
- package/src/data/utilities/parsers/findJoinClauses.ts +29 -0
- package/src/data/utilities/parsers/findJoinEntity.ts +20 -0
- package/src/data/utilities/parsers/findLimit.ts +20 -0
- package/src/data/utilities/parsers/findMergeJoins.ts +27 -0
- package/src/data/utilities/parsers/findOffset.ts +20 -0
- package/src/data/utilities/parsers/findSelects.ts +31 -0
- package/src/data/utilities/parsers/findSortClauses.ts +31 -0
- package/src/data/utilities/parsers/findUpdateValues.test.js +37 -0
- package/src/data/utilities/parsers/findUpdateValues.ts +32 -0
- package/src/data/utilities/parsers/isEntityProperty.ts +1 -0
- package/src/data/utilities/parsers/parseLiteralValue.test.js +41 -0
- package/src/data/utilities/parsers/parseLiteralValue.ts +29 -0
- package/src/data/utilities/parsers/parseQuery.ts +73 -0
- package/src/data/utilities/parsers/removeFromQuery.ts +1 -0
- package/src/data/utilities/parsers/splitEntityProperty.test.js +8 -0
- package/src/data/utilities/parsers/splitEntityProperty.ts +17 -0
- package/src/data/utilities/parsers/splitQueries.test.js +33 -0
- package/src/data/utilities/parsers/splitQueries.ts +4 -0
- package/src/data/utilities/reconcileJoin.test.js +38 -0
- package/src/data/utilities/reconcileJoin.ts +23 -0
- package/src/data/utilities/reconcileJoins.test.js +160 -0
- package/src/data/utilities/reconcileJoins.ts +15 -0
- package/src/data/utilities/registerRecord.test.js +44 -0
- package/src/data/utilities/registerRecord.ts +44 -0
- package/src/data/utilities/removeFromIndex.test.js +44 -0
- package/src/data/utilities/removeFromIndex.ts +34 -0
- package/src/data/utilities/restrictIndexedList.ts +38 -0
- package/src/data/utilities/retrieveFile.test.js +49 -0
- package/src/data/utilities/retrieveFile.ts +19 -0
- package/src/data/utilities/retrieveIndexes.ts +17 -0
- package/src/data/utilities/retrieveRecord.ts +3 -0
- package/src/data/utilities/retrieveRecords.test.js +223 -0
- package/src/data/utilities/retrieveRecords.ts +16 -0
- package/src/data/utilities/runQuery.test.js +88 -0
- package/src/data/utilities/runQuery.ts +75 -0
- package/src/data/utilities/updateIndex.test.js +44 -0
- package/src/data/utilities/updateIndex.ts +45 -0
- package/src/data/utilities/useJoinClause.test.js +94 -0
- package/src/data/utilities/useJoinClause.ts +44 -0
- package/src/global.d.ts +1 -0
- package/src/index.test.js +52 -0
- package/src/index.ts +17 -0
- package/test-data/__RECORDS.json +32 -0
- package/test-data/__indexes/exercise_muscle/fk_exercise_id.json +14 -0
- package/test-data/__indexes/exercise_muscle/fk_muscle_id.json +14 -0
- package/test-data/__indexes/exercise_muscle/pk__id.json +14 -0
- package/test-data/__indexes/exercises/pk__id.json +14 -0
- package/test-data/__indexes/muscles/pk__id.json +58 -0
- package/test-data/__indexes/workouts/fk_exercise_id.json +23 -0
- package/test-data/__indexes/workouts/index_date.json +18 -0
- package/test-data/__indexes/workouts/pk__id.json +26 -0
- package/test-data/copyDatabase.ts +64 -0
- package/test-data/exercise_muscle/bench_press_pectorals.json +6 -0
- package/test-data/exercise_muscle/deadlift_hamstrings.json +6 -0
- package/test-data/exercise_muscle/squat_quadriceps.json +6 -0
- package/test-data/exercise_muscle.json +69 -0
- package/test-data/exercises/bench_press.json +5 -0
- package/test-data/exercises/deadlift.json +5 -0
- package/test-data/exercises/squat.json +5 -0
- package/test-data/exercises.json +34 -0
- package/test-data/muscles/abdominal.json +6 -0
- package/test-data/muscles/biceps.json +6 -0
- package/test-data/muscles/calves.json +6 -0
- package/test-data/muscles/deltoids.json +6 -0
- package/test-data/muscles/erector_spinae.json +6 -0
- package/test-data/muscles/forearms.json +6 -0
- package/test-data/muscles/gluteus_maximus.json +6 -0
- package/test-data/muscles/hamstrings.json +6 -0
- package/test-data/muscles/latissimus_dorsi.json +6 -0
- package/test-data/muscles/obliques.json +6 -0
- package/test-data/muscles/pectorals.json +6 -0
- package/test-data/muscles/quadriceps.json +6 -0
- package/test-data/muscles/trapezius.json +6 -0
- package/test-data/muscles/triceps.json +6 -0
- package/test-data/muscles.json +50 -0
- package/test-data/workouts/2024-06-02-001.json +10 -0
- package/test-data/workouts/2024-06-02-002.json +10 -0
- package/test-data/workouts/2024-06-02-003.json +10 -0
- package/test-data/workouts/2024-06-05-001.json +10 -0
- package/test-data/workouts/2024-06-05-002.json +10 -0
- package/test-data/workouts/2024-06-05-003.json +10 -0
- package/test-data/workouts.json +84 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findConditions = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const _parseLiteralValue = require('./parseLiteralValue')
|
|
9
|
+
const conditionMatch = /(and|or)?\s*(where)\s+([a-z0-9_-]+\.?[a-z0-9_-]*)\s+(=|!=|>|<|>=|<=|in|between|like)\s+(["'](.*)['"]|([0-9]+)|(\[.*])|(null)|(true)|(false))/ig
|
|
10
|
+
/**
|
|
11
|
+
* Extract condition clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
const findConditions = (parsed, query) => {
|
|
16
|
+
const conditionsFound = query.matchAll(conditionMatch)
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
for (const condition of conditionsFound) {
|
|
19
|
+
parsed.conditions.push({
|
|
20
|
+
property: condition[3],
|
|
21
|
+
comparator: condition[4],
|
|
22
|
+
value: (0, _parseLiteralValue.parseLiteralValue)(condition, 6)
|
|
23
|
+
})
|
|
24
|
+
query = (0, _removeFromQuery.removeFromQuery)(condition[0], query)
|
|
25
|
+
}
|
|
26
|
+
return query
|
|
27
|
+
}
|
|
28
|
+
exports.findConditions = findConditions
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findConditions=void 0;var _removeFromQuery=require("./removeFromQuery"),_parseLiteralValue=require("./parseLiteralValue");const conditionMatch=/(and|or)?\s*(where)\s+([a-z0-9_-]+\.?[a-z0-9_-]*)\s+(=|!=|>|<|>=|<=|in|between|like)\s+(["'](.*)['"]|([0-9]+)|(\[.*])|(null)|(true)|(false))/gi,findConditions=(e,r)=>{const o=r.matchAll(conditionMatch);for(let i of o)e.conditions.push({property:i[3],comparator:i[4],value:(0,_parseLiteralValue.parseLiteralValue)(i,6)}),r=(0,_removeFromQuery.removeFromQuery)(i[0],r);return r};exports.findConditions=findConditions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedGroupBy = string;
|
|
3
|
+
/**
|
|
4
|
+
* Extract the group by clauses from the query.
|
|
5
|
+
* @param parsed
|
|
6
|
+
* @param query
|
|
7
|
+
*/
|
|
8
|
+
export declare const findGroupBy: (parsed: ParsedQuery, query: string) => string;
|
|
9
|
+
//# sourceMappingURL=findGroupBy.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findGroupBy = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const groupMatch = /group\s+by\s+(,?[a-z0-9._-]+)+/i
|
|
9
|
+
/**
|
|
10
|
+
* Extract the group by clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findGroupBy = (parsed, query) => {
|
|
15
|
+
const groupFound = query.match(groupMatch)
|
|
16
|
+
if (groupFound) {
|
|
17
|
+
parsed.groupBy = groupFound ? groupFound[1] : undefined
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(groupFound[0], query)
|
|
19
|
+
}
|
|
20
|
+
return query
|
|
21
|
+
}
|
|
22
|
+
exports.findGroupBy = findGroupBy
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findGroupBy=void 0;var _removeFromQuery=require("./removeFromQuery");const groupMatch=/group\s+by\s+(,?[a-z0-9._-]+)+/i,findGroupBy=(r,e)=>{const o=e.match(groupMatch);return o?(r.groupBy=o?o[1]:void 0,(0,_removeFromQuery.removeFromQuery)(o[0],e)):e};exports.findGroupBy=findGroupBy;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedInsertRow = {
|
|
3
|
+
[field: string]: any;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Extract an insert's "values field = value, field2 = value2" clause from the query, the same way
|
|
7
|
+
* findUpdateValues() does for "set". insertEntity() accepts an array of rows for bulk inserts, but
|
|
8
|
+
* a query string only describes a single row for now - wrapped in a one-element array to match.
|
|
9
|
+
* @param parsed
|
|
10
|
+
* @param query
|
|
11
|
+
*/
|
|
12
|
+
export declare const findInsertValues: (parsed: ParsedQuery, query: string) => string;
|
|
13
|
+
//# sourceMappingURL=findInsertValues.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findInsertValues = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const _parseLiteralValue = require('./parseLiteralValue')
|
|
9
|
+
const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)'
|
|
10
|
+
const valuesClauseMatch = new RegExp(`(values)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i')
|
|
11
|
+
const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig
|
|
12
|
+
/**
|
|
13
|
+
* Extract an insert's "values field = value, field2 = value2" clause from the query, the same way
|
|
14
|
+
* findUpdateValues() does for "set". insertEntity() accepts an array of rows for bulk inserts, but
|
|
15
|
+
* a query string only describes a single row for now - wrapped in a one-element array to match.
|
|
16
|
+
* @param parsed
|
|
17
|
+
* @param query
|
|
18
|
+
*/
|
|
19
|
+
const findInsertValues = (parsed, query) => {
|
|
20
|
+
const clauseFound = query.match(valuesClauseMatch)
|
|
21
|
+
parsed.insertValues = []
|
|
22
|
+
if (!clauseFound) {
|
|
23
|
+
return query
|
|
24
|
+
}
|
|
25
|
+
const row = {}
|
|
26
|
+
const assignmentsFound = clauseFound[2].matchAll(assignmentMatch)
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
for (const assignment of assignmentsFound) {
|
|
29
|
+
row[assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3)
|
|
30
|
+
}
|
|
31
|
+
parsed.insertValues = [row]
|
|
32
|
+
return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query)
|
|
33
|
+
}
|
|
34
|
+
exports.findInsertValues = findInsertValues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findInsertValues=void 0;var _removeFromQuery=require("./removeFromQuery"),_parseLiteralValue=require("./parseLiteralValue");const literal="(?:[\"'][^\"']*['\"]|[0-9]+|\\[.*?]|null|true|false)",valuesClauseMatch=new RegExp(`(values)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`,"i"),assignmentMatch=/([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/gi,findInsertValues=(e,r)=>{const s=r.match(valuesClauseMatch);if(e.insertValues=[],!s)return r;const a={},t=s[2].matchAll(assignmentMatch);for(const e of t)a[e[1]]=(0,_parseLiteralValue.parseLiteralValue)(e,3);return e.insertValues=[a],(0,_removeFromQuery.removeFromQuery)(s[0],r)};exports.findInsertValues=findInsertValues;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedJoinClause = {
|
|
3
|
+
propertyA: string;
|
|
4
|
+
comparator: string;
|
|
5
|
+
propertyB: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Extract condition clauses from the query.
|
|
9
|
+
* @param parsed
|
|
10
|
+
* @param query
|
|
11
|
+
*/
|
|
12
|
+
export declare const findJoinClauses: (parsed: ParsedQuery, query: string) => string;
|
|
13
|
+
//# sourceMappingURL=findJoinClauses.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findJoinClauses = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const joinClauseMatch = /(and)?\s*on\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+(=|!=|>|<|>=|<=|in|between|like)\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig
|
|
9
|
+
/**
|
|
10
|
+
* Extract condition clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findJoinClauses = (parsed, query) => {
|
|
15
|
+
const joinClausesFound = query.matchAll(joinClauseMatch)
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
for (const joinClause of joinClausesFound) {
|
|
18
|
+
parsed.joinClauses.push({
|
|
19
|
+
propertyA: joinClause[2],
|
|
20
|
+
comparator: joinClause[3],
|
|
21
|
+
propertyB: joinClause[4]
|
|
22
|
+
})
|
|
23
|
+
query = (0, _removeFromQuery.removeFromQuery)(joinClause[0], query)
|
|
24
|
+
}
|
|
25
|
+
return query
|
|
26
|
+
}
|
|
27
|
+
exports.findJoinClauses = findJoinClauses
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findJoinClauses=void 0;var _removeFromQuery=require("./removeFromQuery");const joinClauseMatch=/(and)?\s*on\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+(=|!=|>|<|>=|<=|in|between|like)\s+([a-z0-9_-]+\.[a-z0-9_-]+)/gi,findJoinClauses=(e,o)=>{const r=o.matchAll(joinClauseMatch);for(let s of r)e.joinClauses.push({propertyA:s[2],comparator:s[3],propertyB:s[4]}),o=(0,_removeFromQuery.removeFromQuery)(s[0],o);return o};exports.findJoinClauses=findJoinClauses;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedJoinEntity = string;
|
|
3
|
+
/**
|
|
4
|
+
* Extract the main join entity from the query.
|
|
5
|
+
* @param parsed
|
|
6
|
+
* @param query
|
|
7
|
+
*/
|
|
8
|
+
export declare const findJoinEntity: (parsed: ParsedQuery, query: string) => string;
|
|
9
|
+
//# sourceMappingURL=findJoinEntity.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findJoinEntity = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const joinEntityMatch = /\.([a-z0-9_-]+)/i
|
|
9
|
+
/**
|
|
10
|
+
* Extract the main join entity from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findJoinEntity = (parsed, query) => {
|
|
15
|
+
const joinEntityFound = query.match(joinEntityMatch)
|
|
16
|
+
if (joinEntityFound) {
|
|
17
|
+
parsed.joinEntity = joinEntityFound ? joinEntityFound[1] : undefined
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(joinEntityFound[0], query)
|
|
19
|
+
}
|
|
20
|
+
return query
|
|
21
|
+
}
|
|
22
|
+
exports.findJoinEntity = findJoinEntity
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findJoinEntity=void 0;var _removeFromQuery=require("./removeFromQuery");const joinEntityMatch=/\.([a-z0-9_-]+)/i,findJoinEntity=(t,e)=>{const i=e.match(joinEntityMatch);return i?(t.joinEntity=i?i[1]:void 0,(0,_removeFromQuery.removeFromQuery)(i[0],e)):e};exports.findJoinEntity=findJoinEntity;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedLimit = number;
|
|
3
|
+
/**
|
|
4
|
+
* Extract the limit clauses from the query.
|
|
5
|
+
* @param parsed
|
|
6
|
+
* @param query
|
|
7
|
+
*/
|
|
8
|
+
export declare const findLimit: (parsed: ParsedQuery, query: string) => string;
|
|
9
|
+
//# sourceMappingURL=findLimit.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findLimit = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const limitMatch = /limit\s*(\d+)/i
|
|
9
|
+
/**
|
|
10
|
+
* Extract the limit clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findLimit = (parsed, query) => {
|
|
15
|
+
const limitFound = query.match(limitMatch)
|
|
16
|
+
if (limitFound) {
|
|
17
|
+
parsed.limit = limitFound ? parseInt(limitFound[1]) : undefined
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(limitFound[0], query)
|
|
19
|
+
}
|
|
20
|
+
return query
|
|
21
|
+
}
|
|
22
|
+
exports.findLimit = findLimit
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findLimit=void 0;var _removeFromQuery=require("./removeFromQuery");const limitMatch=/limit\s*(\d+)/i,findLimit=(e,i)=>{const r=i.match(limitMatch);return r?(e.limit=r?parseInt(r[1]):void 0,(0,_removeFromQuery.removeFromQuery)(r[0],i)):i};exports.findLimit=findLimit;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedMergeJoin = {
|
|
3
|
+
propertyA: string;
|
|
4
|
+
propertyB: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Extract merge-join clauses from the query.
|
|
8
|
+
* @param parsed
|
|
9
|
+
* @param query
|
|
10
|
+
*/
|
|
11
|
+
export declare const findMergeJoins: (parsed: ParsedQuery, query: string) => string;
|
|
12
|
+
//# sourceMappingURL=findMergeJoins.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findMergeJoins = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const mergeJoinMatch = /(and)?\s*merge\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+with\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig
|
|
9
|
+
/**
|
|
10
|
+
* Extract merge-join clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findMergeJoins = (parsed, query) => {
|
|
15
|
+
const mergeJoinsFound = query.matchAll(mergeJoinMatch)
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
for (const mergeJoin of mergeJoinsFound) {
|
|
18
|
+
parsed.mergeJoins.push({
|
|
19
|
+
propertyA: mergeJoin[2],
|
|
20
|
+
propertyB: mergeJoin[3]
|
|
21
|
+
})
|
|
22
|
+
query = (0, _removeFromQuery.removeFromQuery)(mergeJoin[0].trim(), query)
|
|
23
|
+
}
|
|
24
|
+
return query
|
|
25
|
+
}
|
|
26
|
+
exports.findMergeJoins = findMergeJoins
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findMergeJoins=void 0;var _removeFromQuery=require("./removeFromQuery");const mergeJoinMatch=/(and)?\s*merge\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+with\s+([a-z0-9_-]+\.[a-z0-9_-]+)/gi,findMergeJoins=(e,r)=>{const o=r.matchAll(mergeJoinMatch);for(let i of o)e.mergeJoins.push({propertyA:i[2],propertyB:i[3]}),r=(0,_removeFromQuery.removeFromQuery)(i[0].trim(),r);return r};exports.findMergeJoins=findMergeJoins;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedOffset = number;
|
|
3
|
+
/**
|
|
4
|
+
* Extract the offset clauses from the query.
|
|
5
|
+
* @param parsed
|
|
6
|
+
* @param query
|
|
7
|
+
*/
|
|
8
|
+
export declare const findOffset: (parsed: ParsedQuery, query: string) => string;
|
|
9
|
+
//# sourceMappingURL=findOffset.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findOffset = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const offsetMatch = /offset\s*(\d+)/i
|
|
9
|
+
/**
|
|
10
|
+
* Extract the offset clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findOffset = (parsed, query) => {
|
|
15
|
+
const offsetFound = query.match(offsetMatch)
|
|
16
|
+
if (offsetFound) {
|
|
17
|
+
parsed.offset = offsetFound ? parseInt(offsetFound[1]) : undefined
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(offsetFound[0], query)
|
|
19
|
+
}
|
|
20
|
+
return query
|
|
21
|
+
}
|
|
22
|
+
exports.findOffset = findOffset
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findOffset=void 0;var _removeFromQuery=require("./removeFromQuery");const offsetMatch=/offset\s*(\d+)/i,findOffset=(e,r)=>{const t=r.match(offsetMatch);return t?(e.offset=t?parseInt(t[1]):void 0,(0,_removeFromQuery.removeFromQuery)(t[0],r)):r};exports.findOffset=findOffset;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedSelect = {
|
|
3
|
+
property: string;
|
|
4
|
+
alias: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Extract select clauses from the query.
|
|
8
|
+
* @param parsed
|
|
9
|
+
* @param query
|
|
10
|
+
*/
|
|
11
|
+
export declare const findSelects: (parsed: ParsedQuery, query: string) => string;
|
|
12
|
+
//# sourceMappingURL=findSelects.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findSelects = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const selectClausesMatch = /select\s+([a-z0-9=._-]+\s*(as\s+)?([a-z0-9_-]+)?)+\s*(,\s*[a-z0-9=._-]+\s*(as\s*[a-z0-9_-]+)?)*/i
|
|
9
|
+
const selectClauseMatch = /(select)?\s*,?\s*([a-z0-9=._-]+)\s*(as\s+)?([a-z0-9_-]+)?/ig
|
|
10
|
+
/**
|
|
11
|
+
* Extract select clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
const findSelects = (parsed, query) => {
|
|
16
|
+
const selectsFound = query.match(selectClausesMatch)
|
|
17
|
+
if (selectsFound) {
|
|
18
|
+
const selectClausesFound = selectsFound[0].matchAll(selectClauseMatch)
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
for (const selectClause of selectClausesFound) {
|
|
21
|
+
parsed.selectClauses.push({
|
|
22
|
+
property: selectClause[2],
|
|
23
|
+
alias: selectClause[4]
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return (0, _removeFromQuery.removeFromQuery)(selectsFound[0], query)
|
|
27
|
+
}
|
|
28
|
+
return query
|
|
29
|
+
}
|
|
30
|
+
exports.findSelects = findSelects
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findSelects=void 0;var _removeFromQuery=require("./removeFromQuery");const selectClausesMatch=/select\s+([a-z0-9=._-]+\s*(as\s+)?([a-z0-9_-]+)?)+\s*(,\s*[a-z0-9=._-]+\s*(as\s*[a-z0-9_-]+)?)*/i,selectClauseMatch=/(select)?\s*,?\s*([a-z0-9=._-]+)\s*(as\s+)?([a-z0-9_-]+)?/gi,findSelects=(e,s)=>{const t=s.match(selectClausesMatch);if(t){const r=t[0].matchAll(selectClauseMatch);for(let s of r)e.selectClauses.push({property:s[2],alias:s[4]});return(0,_removeFromQuery.removeFromQuery)(t[0],s)}return s};exports.findSelects=findSelects;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedSortClause = {
|
|
3
|
+
property: string;
|
|
4
|
+
direction: string | 'asc' | 'desc';
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Extract sort clauses from the query.
|
|
8
|
+
* @param parsed
|
|
9
|
+
* @param query
|
|
10
|
+
*/
|
|
11
|
+
export declare const findSortClauses: (parsed: ParsedQuery, query: string) => string;
|
|
12
|
+
//# sourceMappingURL=findSortClauses.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findSortClauses = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const sortMatch = /sort\s+([a-z0-9._-]+\s*(asc|desc)?)+\s*(,\s*[a-z0-9._-]+\s*(asc|desc)?)*/i
|
|
9
|
+
const sortRuleMatch = /(sort)?\s*,?\s*([a-z0-9._-]+)\s*(asc|desc)?/ig
|
|
10
|
+
/**
|
|
11
|
+
* Extract sort clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
const findSortClauses = (parsed, query) => {
|
|
16
|
+
const sortFound = query.match(sortMatch)
|
|
17
|
+
if (sortFound) {
|
|
18
|
+
const sortRulesFound = sortFound[0].matchAll(sortRuleMatch)
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
for (const sortClause of sortRulesFound) {
|
|
21
|
+
parsed.sortClauses.push({
|
|
22
|
+
property: sortClause[2],
|
|
23
|
+
direction: sortClause[3] || 'asc'
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return (0, _removeFromQuery.removeFromQuery)(sortFound[0], query)
|
|
27
|
+
}
|
|
28
|
+
return query
|
|
29
|
+
}
|
|
30
|
+
exports.findSortClauses = findSortClauses
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findSortClauses=void 0;var _removeFromQuery=require("./removeFromQuery");const sortMatch=/sort\s+([a-z0-9._-]+\s*(asc|desc)?)+\s*(,\s*[a-z0-9._-]+\s*(asc|desc)?)*/i,sortRuleMatch=/(sort)?\s*,?\s*([a-z0-9._-]+)\s*(asc|desc)?/gi,findSortClauses=(s,e)=>{const r=e.match(sortMatch);if(r){const o=r[0].matchAll(sortRuleMatch);for(let e of o)s.sortClauses.push({property:e[2],direction:e[3]||"asc"});return(0,_removeFromQuery.removeFromQuery)(r[0],e)}return e};exports.findSortClauses=findSortClauses;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ParsedQuery } from './parseQuery';
|
|
2
|
+
export type ParsedUpdateValues = {
|
|
3
|
+
[field: string]: any;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Extract an update's "set field = value, field2 = value2" clause from the query. Uses a two-pass
|
|
7
|
+
* match, unlike the other parsers here: the set clause's own boundary is found first (so it can
|
|
8
|
+
* be removed from the query as a whole, and so the comma-separated list doesn't get confused with
|
|
9
|
+
* anything that follows, like a where clause), then each individual assignment is parsed out of
|
|
10
|
+
* that captured substring.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
export declare const findUpdateValues: (parsed: ParsedQuery, query: string) => string;
|
|
15
|
+
//# sourceMappingURL=findUpdateValues.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.findUpdateValues = void 0
|
|
7
|
+
const _removeFromQuery = require('./removeFromQuery')
|
|
8
|
+
const _parseLiteralValue = require('./parseLiteralValue')
|
|
9
|
+
const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)'
|
|
10
|
+
const setClauseMatch = new RegExp(`(set)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i')
|
|
11
|
+
const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig
|
|
12
|
+
/**
|
|
13
|
+
* Extract an update's "set field = value, field2 = value2" clause from the query. Uses a two-pass
|
|
14
|
+
* match, unlike the other parsers here: the set clause's own boundary is found first (so it can
|
|
15
|
+
* be removed from the query as a whole, and so the comma-separated list doesn't get confused with
|
|
16
|
+
* anything that follows, like a where clause), then each individual assignment is parsed out of
|
|
17
|
+
* that captured substring.
|
|
18
|
+
* @param parsed
|
|
19
|
+
* @param query
|
|
20
|
+
*/
|
|
21
|
+
const findUpdateValues = (parsed, query) => {
|
|
22
|
+
const clauseFound = query.match(setClauseMatch)
|
|
23
|
+
parsed.updateValues = {}
|
|
24
|
+
if (!clauseFound) {
|
|
25
|
+
return query
|
|
26
|
+
}
|
|
27
|
+
const assignmentsFound = clauseFound[2].matchAll(assignmentMatch)
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
for (const assignment of assignmentsFound) {
|
|
30
|
+
parsed.updateValues[assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3)
|
|
31
|
+
}
|
|
32
|
+
return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query)
|
|
33
|
+
}
|
|
34
|
+
exports.findUpdateValues = findUpdateValues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.findUpdateValues=void 0;var _removeFromQuery=require("./removeFromQuery"),_parseLiteralValue=require("./parseLiteralValue");const literal="(?:[\"'][^\"']*['\"]|[0-9]+|\\[.*?]|null|true|false)",setClauseMatch=new RegExp(`(set)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`,"i"),assignmentMatch=/([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/gi,findUpdateValues=(e,a)=>{const r=a.match(setClauseMatch);if(e.updateValues={},!r)return a;const s=r[2].matchAll(assignmentMatch);for(const a of s)e.updateValues[a[1]]=(0,_parseLiteralValue.parseLiteralValue)(a,3);return(0,_removeFromQuery.removeFromQuery)(r[0],a)};exports.findUpdateValues=findUpdateValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isEntityProperty=void 0;const isEntityProperty=t=>/^[a-z0-9_-]+\.([a-z0-9_-]+)$/i.test(t);exports.isEntityProperty=isEntityProperty;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type LiteralValue = string | number | boolean | null | any[];
|
|
2
|
+
/**
|
|
3
|
+
* Several parsers (findConditions, findInsertValues, findUpdateValues) capture a query-string
|
|
4
|
+
* literal into one of six consecutive alternation groups depending on its shape - quoted string,
|
|
5
|
+
* number, array, null, true, false - since a single regex can't otherwise tell them apart. Given
|
|
6
|
+
* the match and the index of the first of those six groups (which shifts depending on how many
|
|
7
|
+
* groups come before it in the parent regex), return the literal with its real JS type.
|
|
8
|
+
* @param match
|
|
9
|
+
* @param baseIndex
|
|
10
|
+
*/
|
|
11
|
+
export declare const parseLiteralValue: (match: RegExpMatchArray, baseIndex: number) => LiteralValue;
|
|
12
|
+
//# sourceMappingURL=parseLiteralValue.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.parseLiteralValue = void 0
|
|
7
|
+
/**
|
|
8
|
+
* Several parsers (findConditions, findInsertValues, findUpdateValues) capture a query-string
|
|
9
|
+
* literal into one of six consecutive alternation groups depending on its shape - quoted string,
|
|
10
|
+
* number, array, null, true, false - since a single regex can't otherwise tell them apart. Given
|
|
11
|
+
* the match and the index of the first of those six groups (which shifts depending on how many
|
|
12
|
+
* groups come before it in the parent regex), return the literal with its real JS type.
|
|
13
|
+
* @param match
|
|
14
|
+
* @param baseIndex
|
|
15
|
+
*/
|
|
16
|
+
const parseLiteralValue = (match, baseIndex) => {
|
|
17
|
+
if (typeof match[baseIndex] !== 'undefined') {
|
|
18
|
+
return match[baseIndex]
|
|
19
|
+
}
|
|
20
|
+
if (typeof match[baseIndex + 1] !== 'undefined') {
|
|
21
|
+
return Number(match[baseIndex + 1])
|
|
22
|
+
}
|
|
23
|
+
if (typeof match[baseIndex + 2] !== 'undefined') {
|
|
24
|
+
return JSON.parse(match[baseIndex + 2])
|
|
25
|
+
}
|
|
26
|
+
if (typeof match[baseIndex + 3] !== 'undefined') {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
if (typeof match[baseIndex + 4] !== 'undefined') {
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
exports.parseLiteralValue = parseLiteralValue
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseLiteralValue=void 0;const parseLiteralValue=(e,r)=>void 0!==e[r]?e[r]:void 0!==e[r+1]?Number(e[r+1]):void 0!==e[r+2]?JSON.parse(e[r+2]):void 0!==e[r+3]?null:void 0!==e[r+4];exports.parseLiteralValue=parseLiteralValue;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ParsedCommand, ParsedEntity } from './findCommand';
|
|
2
|
+
import { ParsedInsertRow } from './findInsertValues';
|
|
3
|
+
import { ParsedUpdateValues } from './findUpdateValues';
|
|
4
|
+
import { ParsedJoinEntity } from './findJoinEntity';
|
|
5
|
+
import { ParsedSelect } from './findSelects';
|
|
6
|
+
import { ParsedCondition } from './findConditions';
|
|
7
|
+
import { ParsedJoinClause } from './findJoinClauses';
|
|
8
|
+
import { ParsedMergeJoin } from './findMergeJoins';
|
|
9
|
+
import { ParsedSortClause } from './findSortClauses';
|
|
10
|
+
import { ParsedGroupBy } from './findGroupBy';
|
|
11
|
+
import { ParsedLimit } from './findLimit';
|
|
12
|
+
import { ParsedOffset } from './findOffset';
|
|
13
|
+
export type ParsedQuery = {
|
|
14
|
+
command: ParsedCommand | undefined;
|
|
15
|
+
entity: ParsedEntity | undefined;
|
|
16
|
+
joinEntity: ParsedJoinEntity | undefined;
|
|
17
|
+
selectClauses: ParsedSelect[];
|
|
18
|
+
insertValues: ParsedInsertRow[];
|
|
19
|
+
updateValues: ParsedUpdateValues;
|
|
20
|
+
conditions: ParsedCondition[];
|
|
21
|
+
joinClauses: ParsedJoinClause[];
|
|
22
|
+
mergeJoins: ParsedMergeJoin[];
|
|
23
|
+
sortClauses: ParsedSortClause[];
|
|
24
|
+
groupBy: ParsedGroupBy | undefined;
|
|
25
|
+
limit: ParsedLimit | undefined;
|
|
26
|
+
offset: ParsedOffset | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Break a query down into its components.
|
|
30
|
+
* @param query
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseQuery: (query: string) => ParsedQuery;
|
|
33
|
+
//# sourceMappingURL=parseQuery.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.parseQuery = void 0
|
|
7
|
+
const _siFunciona = _interopRequireDefault(require('si-funciona'))
|
|
8
|
+
const _findCommand = require('./findCommand')
|
|
9
|
+
const _findInsertValues = require('./findInsertValues')
|
|
10
|
+
const _findUpdateValues = require('./findUpdateValues')
|
|
11
|
+
const _findJoinEntity = require('./findJoinEntity')
|
|
12
|
+
const _findSelects = require('./findSelects')
|
|
13
|
+
const _findConditions = require('./findConditions')
|
|
14
|
+
const _findJoinClauses = require('./findJoinClauses')
|
|
15
|
+
const _findMergeJoins = require('./findMergeJoins')
|
|
16
|
+
const _findSortClauses = require('./findSortClauses')
|
|
17
|
+
const _findGroupBy = require('./findGroupBy')
|
|
18
|
+
const _findLimit = require('./findLimit')
|
|
19
|
+
const _findOffset = require('./findOffset')
|
|
20
|
+
function _interopRequireDefault (e) { return e && e.__esModule ? e : { default: e } }
|
|
21
|
+
/**
|
|
22
|
+
* Break a query down into its components.
|
|
23
|
+
* @param query
|
|
24
|
+
*/
|
|
25
|
+
const parseQuery = query => {
|
|
26
|
+
const parsedQuery = {
|
|
27
|
+
command: undefined,
|
|
28
|
+
entity: undefined,
|
|
29
|
+
joinEntity: undefined,
|
|
30
|
+
selectClauses: [],
|
|
31
|
+
insertValues: [],
|
|
32
|
+
updateValues: {},
|
|
33
|
+
conditions: [],
|
|
34
|
+
joinClauses: [],
|
|
35
|
+
mergeJoins: [],
|
|
36
|
+
sortClauses: [],
|
|
37
|
+
groupBy: undefined,
|
|
38
|
+
limit: undefined,
|
|
39
|
+
offset: undefined
|
|
40
|
+
}
|
|
41
|
+
const {
|
|
42
|
+
curry,
|
|
43
|
+
pipe
|
|
44
|
+
} = _siFunciona.default
|
|
45
|
+
query = pipe(curry(_findCommand.findCommand)(parsedQuery), curry(_findInsertValues.findInsertValues)(parsedQuery), curry(_findUpdateValues.findUpdateValues)(parsedQuery), curry(_findJoinEntity.findJoinEntity)(parsedQuery), curry(_findSelects.findSelects)(parsedQuery), curry(_findConditions.findConditions)(parsedQuery), curry(_findJoinClauses.findJoinClauses)(parsedQuery), curry(_findMergeJoins.findMergeJoins)(parsedQuery), curry(_findSortClauses.findSortClauses)(parsedQuery), curry(_findGroupBy.findGroupBy)(parsedQuery), curry(_findLimit.findLimit)(parsedQuery), curry(_findOffset.findOffset)(parsedQuery))(query)
|
|
46
|
+
if (query) {
|
|
47
|
+
throw new Error(`Unrecognized query value: ${query}`)
|
|
48
|
+
}
|
|
49
|
+
return parsedQuery
|
|
50
|
+
}
|
|
51
|
+
exports.parseQuery = parseQuery
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseQuery=void 0;var _siFunciona=_interopRequireDefault(require("si-funciona")),_findCommand=require("./findCommand"),_findInsertValues=require("./findInsertValues"),_findUpdateValues=require("./findUpdateValues"),_findJoinEntity=require("./findJoinEntity"),_findSelects=require("./findSelects"),_findConditions=require("./findConditions"),_findJoinClauses=require("./findJoinClauses"),_findMergeJoins=require("./findMergeJoins"),_findSortClauses=require("./findSortClauses"),_findGroupBy=require("./findGroupBy"),_findLimit=require("./findLimit"),_findOffset=require("./findOffset");function _interopRequireDefault(i){return i&&i.__esModule?i:{default:i}}const parseQuery=i=>{let e={command:void 0,entity:void 0,joinEntity:void 0,selectClauses:[],insertValues:[],updateValues:{},conditions:[],joinClauses:[],mergeJoins:[],sortClauses:[],groupBy:void 0,limit:void 0,offset:void 0};const{curry:n,pipe:r}=_siFunciona.default;if(i=r(n(_findCommand.findCommand)(e),n(_findInsertValues.findInsertValues)(e),n(_findUpdateValues.findUpdateValues)(e),n(_findJoinEntity.findJoinEntity)(e),n(_findSelects.findSelects)(e),n(_findConditions.findConditions)(e),n(_findJoinClauses.findJoinClauses)(e),n(_findMergeJoins.findMergeJoins)(e),n(_findSortClauses.findSortClauses)(e),n(_findGroupBy.findGroupBy)(e),n(_findLimit.findLimit)(e),n(_findOffset.findOffset)(e))(i))throw new Error(`Unrecognized query value: ${i}`);return e};exports.parseQuery=parseQuery;
|