Updates
This commit is contained in:
parent
9b7c98cff6
commit
cd96c11817
5
dist/package-shared/types/index.d.ts
vendored
5
dist/package-shared/types/index.d.ts
vendored
@ -1365,6 +1365,7 @@ export type DsqlCrudParam<T extends {
|
|||||||
sanitize?: (data?: T) => T;
|
sanitize?: (data?: T) => T;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
count?: boolean;
|
count?: boolean;
|
||||||
|
countOnly?: boolean;
|
||||||
};
|
};
|
||||||
export type ErrorCallback = (title: string, error: Error, data?: any) => void;
|
export type ErrorCallback = (title: string, error: Error, data?: any) => void;
|
||||||
export interface MariaDBUser {
|
export interface MariaDBUser {
|
||||||
@ -1421,6 +1422,10 @@ export type PagePropsType = {
|
|||||||
pageUrl?: string | null;
|
pageUrl?: string | null;
|
||||||
query?: any;
|
query?: any;
|
||||||
databases?: DSQL_DATASQUIREL_USER_DATABASES[] | null;
|
databases?: DSQL_DATASQUIREL_USER_DATABASES[] | null;
|
||||||
|
dbCount?: number | null;
|
||||||
|
tableCount?: number | null;
|
||||||
|
mediaCount?: number | null;
|
||||||
|
apiKeysCount?: number | null;
|
||||||
};
|
};
|
||||||
export type APIResponseObject<T extends any = any> = {
|
export type APIResponseObject<T extends any = any> = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
@ -4,7 +4,7 @@ export default function dsqlCrud<T extends {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}>({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, }: DsqlCrudParam<T>): Promise<(PostReturn & {
|
}>({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, countOnly, }: DsqlCrudParam<T>): Promise<(PostReturn & {
|
||||||
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||||
count?: number;
|
count?: number;
|
||||||
}) | null>;
|
}) | null>;
|
||||||
|
32
dist/package-shared/utils/data-fetching/crud.js
vendored
32
dist/package-shared/utils/data-fetching/crud.js
vendored
@ -17,8 +17,8 @@ const post_1 = __importDefault(require("../../actions/post"));
|
|||||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||||
function dsqlCrud(_a) {
|
function dsqlCrud(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, }) {
|
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetValue, query, sanitize, debug, targetField, targetId, count, countOnly, }) {
|
||||||
var _b, _c;
|
var _b, _c, _d, _e;
|
||||||
const finalData = sanitize ? sanitize(data) : data;
|
const finalData = sanitize ? sanitize(data) : data;
|
||||||
let queryObject;
|
let queryObject;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -28,32 +28,46 @@ function dsqlCrud(_a) {
|
|||||||
genObject: query,
|
genObject: query,
|
||||||
});
|
});
|
||||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||||
const connQueries = [
|
let connQueries = [
|
||||||
{
|
{
|
||||||
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
query: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||||
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
values: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
if (count) {
|
const countQueryObject = count || countOnly
|
||||||
const countQueryObject = (0, sql_generator_1.default)({
|
? (0, sql_generator_1.default)({
|
||||||
tableName: table,
|
tableName: table,
|
||||||
genObject: query,
|
genObject: query,
|
||||||
count: true,
|
count: true,
|
||||||
});
|
})
|
||||||
|
: undefined;
|
||||||
|
if (count && countQueryObject) {
|
||||||
connQueries.push({
|
connQueries.push({
|
||||||
query: countQueryObject.string,
|
query: countQueryObject.string,
|
||||||
values: countQueryObject.values,
|
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 res = yield (0, conn_db_handler_1.default)(DB_CONN, connQueries);
|
||||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||||
return {
|
return {
|
||||||
success: isSuccess,
|
success: isSuccess,
|
||||||
payload: isSuccess ? res[0] : null,
|
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||||
queryObject,
|
queryObject,
|
||||||
count: isSuccess && ((_c = (_b = res[1]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c["COUNT(*)"])
|
count: isSuccess
|
||||||
? res[1][0]["COUNT(*)"]
|
? ((_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,
|
: undefined,
|
||||||
};
|
};
|
||||||
case "insert":
|
case "insert":
|
||||||
|
@ -1546,6 +1546,7 @@ export type DsqlCrudParam<
|
|||||||
sanitize?: (data?: T) => T;
|
sanitize?: (data?: T) => T;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
count?: boolean;
|
count?: boolean;
|
||||||
|
countOnly?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ErrorCallback = (title: string, error: Error, data?: any) => void;
|
export type ErrorCallback = (title: string, error: Error, data?: any) => void;
|
||||||
@ -1605,6 +1606,10 @@ export type PagePropsType = {
|
|||||||
pageUrl?: string | null;
|
pageUrl?: string | null;
|
||||||
query?: any;
|
query?: any;
|
||||||
databases?: DSQL_DATASQUIREL_USER_DATABASES[] | null;
|
databases?: DSQL_DATASQUIREL_USER_DATABASES[] | null;
|
||||||
|
dbCount?: number | null;
|
||||||
|
tableCount?: number | null;
|
||||||
|
mediaCount?: number | null;
|
||||||
|
apiKeysCount?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type APIResponseObject<T extends any = any> = {
|
export type APIResponseObject<T extends any = any> = {
|
||||||
|
@ -17,6 +17,7 @@ export default async function dsqlCrud<
|
|||||||
targetField,
|
targetField,
|
||||||
targetId,
|
targetId,
|
||||||
count,
|
count,
|
||||||
|
countOnly,
|
||||||
}: DsqlCrudParam<T>): Promise<
|
}: DsqlCrudParam<T>): Promise<
|
||||||
| (PostReturn & {
|
| (PostReturn & {
|
||||||
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
|
||||||
@ -37,24 +38,34 @@ export default async function dsqlCrud<
|
|||||||
const DB_CONN =
|
const DB_CONN =
|
||||||
global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||||
|
|
||||||
const connQueries: ConnDBHandlerQueryObject[] = [
|
let connQueries: ConnDBHandlerQueryObject[] = [
|
||||||
{
|
{
|
||||||
query: queryObject?.string,
|
query: queryObject?.string,
|
||||||
values: queryObject?.values || [],
|
values: queryObject?.values || [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (count) {
|
const countQueryObject =
|
||||||
const countQueryObject = sqlGenerator({
|
count || countOnly
|
||||||
tableName: table,
|
? sqlGenerator({
|
||||||
genObject: query,
|
tableName: table,
|
||||||
count: true,
|
genObject: query,
|
||||||
});
|
count: true,
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (count && countQueryObject) {
|
||||||
connQueries.push({
|
connQueries.push({
|
||||||
query: countQueryObject.string,
|
query: countQueryObject.string,
|
||||||
values: countQueryObject.values,
|
values: countQueryObject.values,
|
||||||
});
|
});
|
||||||
|
} else if (countOnly && countQueryObject) {
|
||||||
|
connQueries = [
|
||||||
|
{
|
||||||
|
query: countQueryObject.string,
|
||||||
|
values: countQueryObject.values,
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await connDbHandler(DB_CONN, connQueries);
|
const res = await connDbHandler(DB_CONN, connQueries);
|
||||||
@ -63,13 +74,16 @@ export default async function dsqlCrud<
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: isSuccess,
|
success: isSuccess,
|
||||||
payload: isSuccess ? res[0] : null,
|
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||||
error: isSuccess ? undefined : res?.error,
|
error: isSuccess ? undefined : res?.error,
|
||||||
queryObject,
|
queryObject,
|
||||||
count:
|
count: isSuccess
|
||||||
isSuccess && res[1]?.[0]?.["COUNT(*)"]
|
? res[1]?.[0]?.["COUNT(*)"]
|
||||||
? res[1][0]["COUNT(*)"]
|
? res[1][0]["COUNT(*)"]
|
||||||
: undefined,
|
: res[0]?.[0]?.["COUNT(*)"]
|
||||||
|
? res[0][0]["COUNT(*)"]
|
||||||
|
: undefined
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
case "insert":
|
case "insert":
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "4.6.7",
|
"version": "4.6.8",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user