mp-js-api 0.0.10 → 0.0.11
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/dist/tables/participants.d.ts +8 -8
- package/dist/tables/participants.d.ts.map +1 -1
- package/dist/utils/json-sql.d.ts +2 -0
- package/dist/utils/json-sql.d.ts.map +1 -0
- package/dist/utils/json-sql.js +111 -0
- package/package.json +1 -1
- package/src/tables/participants.ts +8 -8
- package/src/utils/json-sql.ts +132 -0
|
@@ -38,18 +38,18 @@ export interface Participant {
|
|
|
38
38
|
participantStartDate: string;
|
|
39
39
|
participantEndDate: null | string;
|
|
40
40
|
notes: string;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
_firstAttendanceEver: null | string;
|
|
42
|
+
_secondAttendanceEver: null | string;
|
|
43
|
+
_thirdAttendanceEver: null | string;
|
|
44
|
+
_lastAttendanceEver: null | string;
|
|
45
45
|
subStatusName: null | string;
|
|
46
46
|
statusDate: null | string;
|
|
47
47
|
formerDenomination: null | string;
|
|
48
48
|
formerChurch: null | string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
_backgroundCheckInformation: null | string;
|
|
50
|
+
_backgroundCheckType: null | string;
|
|
51
|
+
_backgroundCheckStatus: null | string;
|
|
52
|
+
_backgroundCheckDate: null | string;
|
|
53
53
|
sacramentInformation: null | string;
|
|
54
54
|
churchOfRecord: null | string;
|
|
55
55
|
baptismParishName: null | string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"participants.d.ts","sourceRoot":"","sources":["../../src/tables/participants.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,IAAI,GAAG,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE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IACpC,uBAAuB,EAAE,IAAI,GAAG,MAAM,CAAC;IACvC,oBAAoB,EAAE,IAAI,GAAG,MAAM,CAAC;IACpC,qBAAqB,EAAE,IAAI,GAAG,MAAM,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-sql.d.ts","sourceRoot":"","sources":["../../src/utils/json-sql.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function jsonToSqlFilter(json) {
|
|
4
|
+
const conditions = [];
|
|
5
|
+
// Loop through each key-value pair in the JSON object
|
|
6
|
+
for (const [key, value] of Object.entries(json)) {
|
|
7
|
+
let condition = '';
|
|
8
|
+
// If the value is a string, wrap it in quotes
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
condition = `${key} = '${value}'`;
|
|
11
|
+
}
|
|
12
|
+
// If the value is a number or boolean, no quotes are needed
|
|
13
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
14
|
+
condition = `${key} = ${value}`;
|
|
15
|
+
}
|
|
16
|
+
// If the value is an array, assume it represents an IN condition
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
const valueList = value.map(val => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
19
|
+
condition = `${key} IN (${valueList})`;
|
|
20
|
+
}
|
|
21
|
+
// If the value is an object, we can assume it's a nested condition (e.g., for complex queries)
|
|
22
|
+
else if (typeof value === 'object') {
|
|
23
|
+
const subConditions = Object.entries(value).map(([subKey, subValue]) => {
|
|
24
|
+
if (typeof subValue === 'string') {
|
|
25
|
+
return `${subKey} = '${subValue}'`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return `${subKey} = ${subValue}`;
|
|
29
|
+
}
|
|
30
|
+
}).join(' AND ');
|
|
31
|
+
condition = `${key} (${subConditions})`;
|
|
32
|
+
}
|
|
33
|
+
conditions.push(condition);
|
|
34
|
+
}
|
|
35
|
+
// Join the conditions with 'AND'
|
|
36
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
37
|
+
}
|
|
38
|
+
// Example Usage
|
|
39
|
+
const json1 = {
|
|
40
|
+
name: "John",
|
|
41
|
+
age: 30,
|
|
42
|
+
active: true,
|
|
43
|
+
hobbies: ["reading", "gaming"],
|
|
44
|
+
address: {
|
|
45
|
+
city: "New York",
|
|
46
|
+
zip: "10001"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const query1 = jsonToSqlFilter(json1);
|
|
50
|
+
console.log(query1);
|
|
51
|
+
function jsonToSqlQuery(json) {
|
|
52
|
+
const conditions = [];
|
|
53
|
+
// Loop through each key-value pair in the JSON object
|
|
54
|
+
for (const [key, value] of Object.entries(json)) {
|
|
55
|
+
let condition = '';
|
|
56
|
+
// If the value is an object (operator condition)
|
|
57
|
+
if (typeof value === 'object' && value !== null) {
|
|
58
|
+
const operatorConditions = [];
|
|
59
|
+
let [operator, operatorValue] = [null, null];
|
|
60
|
+
for ([operator, operatorValue] of Object.entries(value)) {
|
|
61
|
+
switch (operator) {
|
|
62
|
+
case "$eq":
|
|
63
|
+
operatorConditions.push(`${key} = '${operatorValue}'`);
|
|
64
|
+
break;
|
|
65
|
+
case "$gt":
|
|
66
|
+
operatorConditions.push(`${key} > ${operatorValue}`);
|
|
67
|
+
break;
|
|
68
|
+
case "$lt":
|
|
69
|
+
operatorConditions.push(`${key} < ${operatorValue}`);
|
|
70
|
+
break;
|
|
71
|
+
case "$gte":
|
|
72
|
+
operatorConditions.push(`${key} >= ${operatorValue}`);
|
|
73
|
+
break;
|
|
74
|
+
case "$lte":
|
|
75
|
+
operatorConditions.push(`${key} <= ${operatorValue}`);
|
|
76
|
+
break;
|
|
77
|
+
case "$ne":
|
|
78
|
+
operatorConditions.push(`${key} != '${operatorValue}'`);
|
|
79
|
+
break;
|
|
80
|
+
case "$in":
|
|
81
|
+
const inValues = operatorValue.map((val) => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
82
|
+
operatorConditions.push(`${key} IN (${inValues})`);
|
|
83
|
+
break;
|
|
84
|
+
case "$like":
|
|
85
|
+
operatorConditions.push(`${key} LIKE '%${operatorValue}%'`);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unsupported operator: ${operator}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Join all conditions for a field with AND
|
|
92
|
+
condition = operatorConditions.join(' AND ');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// For simple equality condition
|
|
96
|
+
condition = `${key} = '${value}'`;
|
|
97
|
+
}
|
|
98
|
+
conditions.push(condition);
|
|
99
|
+
}
|
|
100
|
+
// Join the conditions with AND
|
|
101
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
102
|
+
}
|
|
103
|
+
// Example Usage
|
|
104
|
+
const json = {
|
|
105
|
+
"age": { "$gt": 30 },
|
|
106
|
+
"name": { "$eq": "John" },
|
|
107
|
+
"status": { "$in": ["active", "pending"] },
|
|
108
|
+
"address.city": { "$eq": "New York" }
|
|
109
|
+
};
|
|
110
|
+
const query = jsonToSqlQuery(json);
|
|
111
|
+
console.log(query);
|
package/package.json
CHANGED
|
@@ -39,18 +39,18 @@ export interface Participant {
|
|
|
39
39
|
participantStartDate: string;
|
|
40
40
|
participantEndDate: null | string;
|
|
41
41
|
notes: string;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
_firstAttendanceEver: null | string;
|
|
43
|
+
_secondAttendanceEver: null | string;
|
|
44
|
+
_thirdAttendanceEver: null | string;
|
|
45
|
+
_lastAttendanceEver: null | string;
|
|
46
46
|
subStatusName: null | string;
|
|
47
47
|
statusDate: null | string;
|
|
48
48
|
formerDenomination: null | string;
|
|
49
49
|
formerChurch: null | string;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
_backgroundCheckInformation: null | string;
|
|
51
|
+
_backgroundCheckType: null | string;
|
|
52
|
+
_backgroundCheckStatus: null | string;
|
|
53
|
+
_backgroundCheckDate: null | string;
|
|
54
54
|
sacramentInformation: null | string;
|
|
55
55
|
churchOfRecord: null | string;
|
|
56
56
|
baptismParishName: null | string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
function jsonToSqlFilter(json: Record<string, any>): string {
|
|
2
|
+
const conditions: string[] = [];
|
|
3
|
+
|
|
4
|
+
// Loop through each key-value pair in the JSON object
|
|
5
|
+
for (const [key, value] of Object.entries(json)) {
|
|
6
|
+
let condition = '';
|
|
7
|
+
|
|
8
|
+
// If the value is a string, wrap it in quotes
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
condition = `${key} = '${value}'`;
|
|
11
|
+
}
|
|
12
|
+
// If the value is a number or boolean, no quotes are needed
|
|
13
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
14
|
+
condition = `${key} = ${value}`;
|
|
15
|
+
}
|
|
16
|
+
// If the value is an array, assume it represents an IN condition
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
const valueList = value.map(val =>
|
|
19
|
+
typeof val === 'string' ? `'${val}'` : val
|
|
20
|
+
).join(', ');
|
|
21
|
+
condition = `${key} IN (${valueList})`;
|
|
22
|
+
}
|
|
23
|
+
// If the value is an object, we can assume it's a nested condition (e.g., for complex queries)
|
|
24
|
+
else if (typeof value === 'object') {
|
|
25
|
+
const subConditions = Object.entries(value).map(([subKey, subValue]) => {
|
|
26
|
+
if (typeof subValue === 'string') {
|
|
27
|
+
return `${subKey} = '${subValue}'`;
|
|
28
|
+
} else {
|
|
29
|
+
return `${subKey} = ${subValue}`;
|
|
30
|
+
}
|
|
31
|
+
}).join(' AND ');
|
|
32
|
+
condition = `${key} (${subConditions})`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
conditions.push(condition);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Join the conditions with 'AND'
|
|
39
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Example Usage
|
|
43
|
+
const json1 = {
|
|
44
|
+
name: "John",
|
|
45
|
+
age: 30,
|
|
46
|
+
active: true,
|
|
47
|
+
hobbies: ["reading", "gaming"],
|
|
48
|
+
address: {
|
|
49
|
+
city: "New York",
|
|
50
|
+
zip: "10001"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const query1 = jsonToSqlFilter(json1);
|
|
55
|
+
console.log(query1);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
type QueryCondition = {
|
|
64
|
+
[key: string]: any; // key is field, value is condition or value
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function jsonToSqlQuery(json: QueryCondition): string {
|
|
68
|
+
const conditions: string[] = [];
|
|
69
|
+
|
|
70
|
+
// Loop through each key-value pair in the JSON object
|
|
71
|
+
for (const [key, value] of Object.entries(json)) {
|
|
72
|
+
let condition = '';
|
|
73
|
+
|
|
74
|
+
// If the value is an object (operator condition)
|
|
75
|
+
if (typeof value === 'object' && value !== null) {
|
|
76
|
+
const operatorConditions: string[] = [];
|
|
77
|
+
let [operator, operatorValue]: any[] = [null, null];
|
|
78
|
+
for ([operator, operatorValue] of Object.entries(value)) {
|
|
79
|
+
switch (operator) {
|
|
80
|
+
case "$eq":
|
|
81
|
+
operatorConditions.push(`${key} = '${operatorValue}'`);
|
|
82
|
+
break;
|
|
83
|
+
case "$gt":
|
|
84
|
+
operatorConditions.push(`${key} > ${operatorValue}`);
|
|
85
|
+
break;
|
|
86
|
+
case "$lt":
|
|
87
|
+
operatorConditions.push(`${key} < ${operatorValue}`);
|
|
88
|
+
break;
|
|
89
|
+
case "$gte":
|
|
90
|
+
operatorConditions.push(`${key} >= ${operatorValue}`);
|
|
91
|
+
break;
|
|
92
|
+
case "$lte":
|
|
93
|
+
operatorConditions.push(`${key} <= ${operatorValue}`);
|
|
94
|
+
break;
|
|
95
|
+
case "$ne":
|
|
96
|
+
operatorConditions.push(`${key} != '${operatorValue}'`);
|
|
97
|
+
break;
|
|
98
|
+
case "$in":
|
|
99
|
+
const inValues = operatorValue.map((val: any) => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
100
|
+
operatorConditions.push(`${key} IN (${inValues})`);
|
|
101
|
+
break;
|
|
102
|
+
case "$like":
|
|
103
|
+
operatorConditions.push(`${key} LIKE '%${operatorValue}%'`);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
throw new Error(`Unsupported operator: ${operator}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Join all conditions for a field with AND
|
|
110
|
+
condition = operatorConditions.join(' AND ');
|
|
111
|
+
} else {
|
|
112
|
+
// For simple equality condition
|
|
113
|
+
condition = `${key} = '${value}'`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
conditions.push(condition);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Join the conditions with AND
|
|
120
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Example Usage
|
|
124
|
+
const json = {
|
|
125
|
+
"age": { "$gt": 30 },
|
|
126
|
+
"name": { "$eq": "John" },
|
|
127
|
+
"status": { "$in": ["active", "pending"] },
|
|
128
|
+
"address.city": { "$eq": "New York" }
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const query = jsonToSqlQuery(json);
|
|
132
|
+
console.log(query);
|