Updates
This commit is contained in:
parent
cd96c11817
commit
8639c9f34d
@ -4,8 +4,5 @@ type Param = {
|
||||
userId: string | number;
|
||||
dummy?: boolean;
|
||||
};
|
||||
export default function addQueue({ queue, userId, dummy }: Param): Promise<(import("../../../types").PostReturn & {
|
||||
queryObject?: ReturnType<Awaited<typeof import("../../dsql/sql/sql-generator").default>>;
|
||||
count?: number;
|
||||
}) | null | undefined>;
|
||||
export default function addQueue({ queue, userId, dummy }: Param): Promise<import("../../../utils/data-fetching/crud").DsqlCrudReturn | undefined>;
|
||||
export {};
|
||||
|
0
dist/package-shared/utils/data-fetching/crud-batch-get.d.ts
vendored
Normal file
0
dist/package-shared/utils/data-fetching/crud-batch-get.d.ts
vendored
Normal file
36
dist/package-shared/utils/data-fetching/crud-batch-get.js
vendored
Normal file
36
dist/package-shared/utils/data-fetching/crud-batch-get.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
// import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
// import { DsqlCrudParam } from "../../types";
|
||||
// import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||
// import { DsqlCrudReturn } from "./crud";
|
||||
// export default async function dsqlCrudBatchGet({
|
||||
// batchQuery,
|
||||
// }: DsqlCrudParam<any>): Promise<DsqlCrudReturn> {
|
||||
// try {
|
||||
// const queryObjects = batchQuery?.map((q) =>
|
||||
// sqlGenerator({
|
||||
// tableName: q.tableName,
|
||||
// genObject: q,
|
||||
// })
|
||||
// );
|
||||
// const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
// let connQueries: ConnDBHandlerQueryObject[] | undefined =
|
||||
// queryObjects?.map((q) => ({
|
||||
// query: q.string,
|
||||
// values: q.values,
|
||||
// }));
|
||||
// if (!connQueries) return null;
|
||||
// const res = (await connDbHandler(DB_CONN, connQueries)) as any[][];
|
||||
// const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
// if (!isSuccess) return null;
|
||||
// return {
|
||||
// success: isSuccess,
|
||||
// batchPayload: isSuccess ? res : null,
|
||||
// };
|
||||
// } catch (error: any) {
|
||||
// return {
|
||||
// success: false,
|
||||
// error: error.message,
|
||||
// };
|
||||
// }
|
||||
// }
|
3
dist/package-shared/utils/data-fetching/crud-get.d.ts
vendored
Normal file
3
dist/package-shared/utils/data-fetching/crud-get.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { DsqlCrudParam } from "../../types";
|
||||
import { DsqlCrudReturn } from "./crud";
|
||||
export default function dsqlCrudGet({ table, query, count, countOnly, }: DsqlCrudParam<any>): Promise<DsqlCrudReturn>;
|
70
dist/package-shared/utils/data-fetching/crud-get.js
vendored
Normal file
70
dist/package-shared/utils/data-fetching/crud-get.js
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = dsqlCrudGet;
|
||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
function dsqlCrudGet(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, }) {
|
||||
var _b, _c, _d, _e;
|
||||
let queryObject;
|
||||
queryObject = (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
});
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let connQueries = [
|
||||
{
|
||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||
},
|
||||
];
|
||||
const countQueryObject = count || countOnly
|
||||
? (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
})
|
||||
: undefined;
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
}
|
||||
else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
},
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
queryObject,
|
||||
count: isSuccess
|
||||
? ((_c = (_b = res[1]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c["COUNT(*)"])
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: ((_e = (_d = res[0]) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e["COUNT(*)"])
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
});
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
import { DsqlCrudParam, PostReturn } from "../../types";
|
||||
export type DsqlCrudReturn = (PostReturn & {
|
||||
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||
count?: number;
|
||||
batchPayload?: any[][] | null;
|
||||
}) | null;
|
||||
export default function dsqlCrud<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, countOnly, }: DsqlCrudParam<T>): Promise<(PostReturn & {
|
||||
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||
count?: number;
|
||||
}) | null>;
|
||||
}>(params: DsqlCrudParam<T>): Promise<DsqlCrudReturn>;
|
||||
|
61
dist/package-shared/utils/data-fetching/crud.js
vendored
61
dist/package-shared/utils/data-fetching/crud.js
vendored
@ -14,62 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = dsqlCrud;
|
||||
const post_1 = __importDefault(require("../../actions/post"));
|
||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
function dsqlCrud(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, countOnly, }) {
|
||||
var _b, _c, _d, _e;
|
||||
// import dsqlCrudBatchGet from "./crud-batch-get";
|
||||
const crud_get_1 = __importDefault(require("./crud-get"));
|
||||
function dsqlCrud(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, } = params;
|
||||
const finalData = sanitize ? sanitize(data) : data;
|
||||
let queryObject;
|
||||
switch (action) {
|
||||
case "get":
|
||||
queryObject = (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
});
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let connQueries = [
|
||||
{
|
||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||
},
|
||||
];
|
||||
const countQueryObject = count || countOnly
|
||||
? (0, sql_generator_1.default)({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
})
|
||||
: undefined;
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
}
|
||||
else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
},
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
queryObject,
|
||||
count: isSuccess
|
||||
? ((_c = (_b = res[1]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c["COUNT(*)"])
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: ((_e = (_d = res[0]) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e["COUNT(*)"])
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
return yield (0, crud_get_1.default)(params);
|
||||
// case "batch-get":
|
||||
// return await dsqlCrudBatchGet(params);
|
||||
case "insert":
|
||||
return yield (0, post_1.default)({
|
||||
query: {
|
||||
|
43
package-shared/utils/data-fetching/crud-batch-get.ts
Normal file
43
package-shared/utils/data-fetching/crud-batch-get.ts
Normal file
@ -0,0 +1,43 @@
|
||||
// import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
// import { DsqlCrudParam } from "../../types";
|
||||
// import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||
// import { DsqlCrudReturn } from "./crud";
|
||||
|
||||
// export default async function dsqlCrudBatchGet({
|
||||
// batchQuery,
|
||||
// }: DsqlCrudParam<any>): Promise<DsqlCrudReturn> {
|
||||
// try {
|
||||
// const queryObjects = batchQuery?.map((q) =>
|
||||
// sqlGenerator({
|
||||
// tableName: q.tableName,
|
||||
// genObject: q,
|
||||
// })
|
||||
// );
|
||||
|
||||
// const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
// let connQueries: ConnDBHandlerQueryObject[] | undefined =
|
||||
// queryObjects?.map((q) => ({
|
||||
// query: q.string,
|
||||
// values: q.values,
|
||||
// }));
|
||||
|
||||
// if (!connQueries) return null;
|
||||
|
||||
// const res = (await connDbHandler(DB_CONN, connQueries)) as any[][];
|
||||
|
||||
// const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
|
||||
// if (!isSuccess) return null;
|
||||
|
||||
// return {
|
||||
// success: isSuccess,
|
||||
// batchPayload: isSuccess ? res : null,
|
||||
// };
|
||||
// } catch (error: any) {
|
||||
// return {
|
||||
// success: false,
|
||||
// error: error.message,
|
||||
// };
|
||||
// }
|
||||
// }
|
68
package-shared/utils/data-fetching/crud-get.ts
Normal file
68
package-shared/utils/data-fetching/crud-get.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
import { DsqlCrudParam } from "../../types";
|
||||
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||
import { DsqlCrudReturn } from "./crud";
|
||||
|
||||
export default async function dsqlCrudGet({
|
||||
table,
|
||||
query,
|
||||
count,
|
||||
countOnly,
|
||||
}: DsqlCrudParam<any>): Promise<DsqlCrudReturn> {
|
||||
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
|
||||
|
||||
queryObject = sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
});
|
||||
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
let connQueries: ConnDBHandlerQueryObject[] = [
|
||||
{
|
||||
query: queryObject?.string,
|
||||
values: queryObject?.values || [],
|
||||
},
|
||||
];
|
||||
|
||||
const countQueryObject =
|
||||
count || countOnly
|
||||
? sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
} else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const res = await connDbHandler(DB_CONN, connQueries);
|
||||
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
error: isSuccess ? undefined : res?.error,
|
||||
queryObject,
|
||||
count: isSuccess
|
||||
? res[1]?.[0]?.["COUNT(*)"]
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: res[0]?.[0]?.["COUNT(*)"]
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
}
|
@ -1,90 +1,37 @@
|
||||
import get from "../../actions/get";
|
||||
import post from "../../actions/post";
|
||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
import { DsqlCrudParam, PostReturn } from "../../types";
|
||||
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||
// import dsqlCrudBatchGet from "./crud-batch-get";
|
||||
import dsqlCrudGet from "./crud-get";
|
||||
|
||||
export default async function dsqlCrud<
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
>({
|
||||
action,
|
||||
data,
|
||||
table,
|
||||
targetValue,
|
||||
query,
|
||||
sanitize,
|
||||
debug,
|
||||
targetField,
|
||||
targetId,
|
||||
count,
|
||||
countOnly,
|
||||
}: DsqlCrudParam<T>): Promise<
|
||||
export type DsqlCrudReturn =
|
||||
| (PostReturn & {
|
||||
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||
count?: number;
|
||||
batchPayload?: any[][] | null;
|
||||
})
|
||||
| null
|
||||
> {
|
||||
| null;
|
||||
|
||||
export default async function dsqlCrud<
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
>(params: DsqlCrudParam<T>): Promise<DsqlCrudReturn> {
|
||||
const {
|
||||
action,
|
||||
data,
|
||||
table,
|
||||
targetValue,
|
||||
sanitize,
|
||||
targetField,
|
||||
targetId,
|
||||
} = params;
|
||||
const finalData = sanitize ? sanitize(data) : data;
|
||||
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
|
||||
|
||||
switch (action) {
|
||||
case "get":
|
||||
queryObject = sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
});
|
||||
return await dsqlCrudGet(params);
|
||||
|
||||
const DB_CONN =
|
||||
global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
let connQueries: ConnDBHandlerQueryObject[] = [
|
||||
{
|
||||
query: queryObject?.string,
|
||||
values: queryObject?.values || [],
|
||||
},
|
||||
];
|
||||
|
||||
const countQueryObject =
|
||||
count || countOnly
|
||||
? sqlGenerator({
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
count: true,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (count && countQueryObject) {
|
||||
connQueries.push({
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
});
|
||||
} else if (countOnly && countQueryObject) {
|
||||
connQueries = [
|
||||
{
|
||||
query: countQueryObject.string,
|
||||
values: countQueryObject.values,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const res = await connDbHandler(DB_CONN, connQueries);
|
||||
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
error: isSuccess ? undefined : res?.error,
|
||||
queryObject,
|
||||
count: isSuccess
|
||||
? res[1]?.[0]?.["COUNT(*)"]
|
||||
? res[1][0]["COUNT(*)"]
|
||||
: res[0]?.[0]?.["COUNT(*)"]
|
||||
? res[0][0]["COUNT(*)"]
|
||||
: undefined
|
||||
: undefined,
|
||||
};
|
||||
// case "batch-get":
|
||||
// return await dsqlCrudBatchGet(params);
|
||||
|
||||
case "insert":
|
||||
return await post({
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "4.6.8",
|
||||
"version": "4.6.9",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user