Bugfix
This commit is contained in:
parent
12296a3e75
commit
b578843c6d
3
dist/package-shared/actions/get.d.ts
vendored
3
dist/package-shared/actions/get.d.ts
vendored
@ -11,6 +11,7 @@ type Param<T extends {
|
||||
tableName?: string;
|
||||
user_id?: string | number;
|
||||
debug?: boolean;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
export type ApiGetParams = Param;
|
||||
/**
|
||||
@ -20,5 +21,5 @@ export default function get<T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}>({ key, db, query, queryValues, tableName, user_id, debug, }: Param<T>): Promise<GetReturn>;
|
||||
}>({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }: Param<T>): Promise<GetReturn>;
|
||||
export {};
|
||||
|
3
dist/package-shared/actions/get.js
vendored
3
dist/package-shared/actions/get.js
vendored
@ -23,7 +23,7 @@ const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and
|
||||
* # Make a get request to Datasquirel API
|
||||
*/
|
||||
function get(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, user_id, debug, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }) {
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
/**
|
||||
@ -49,6 +49,7 @@ function get(_a) {
|
||||
tableName,
|
||||
dbSchema,
|
||||
debug,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
3
dist/package-shared/actions/post.d.ts
vendored
3
dist/package-shared/actions/post.d.ts
vendored
@ -6,9 +6,10 @@ type Param = {
|
||||
queryValues?: any[];
|
||||
tableName?: string;
|
||||
user_id?: boolean;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Make a post request to Datasquirel API
|
||||
*/
|
||||
export default function post({ key, query, queryValues, database, tableName, user_id, }: Param): Promise<PostReturn>;
|
||||
export default function post({ key, query, queryValues, database, tableName, user_id, forceLocal, }: Param): Promise<PostReturn>;
|
||||
export {};
|
||||
|
3
dist/package-shared/actions/post.js
vendored
3
dist/package-shared/actions/post.js
vendored
@ -22,7 +22,7 @@ const post_1 = __importDefault(require("../functions/api/query/post"));
|
||||
* # Make a post request to Datasquirel API
|
||||
*/
|
||||
function post(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, user_id, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, query, queryValues, database, tableName, user_id, forceLocal, }) {
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
/**
|
||||
@ -49,6 +49,7 @@ function post(_a) {
|
||||
dbSchema,
|
||||
queryValues,
|
||||
tableName,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ type Param<T extends {
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
debug?: boolean;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Get Function FOr API
|
||||
@ -20,5 +21,5 @@ export default function apiGet<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ query, dbFullName, queryValues, tableName, dbSchema, debug, dbContext, }: Param<T>): Promise<import("../../../types").GetReturn>;
|
||||
}>({ query, dbFullName, queryValues, tableName, dbSchema, debug, dbContext, forceLocal, }: Param<T>): Promise<import("../../../types").GetReturn>;
|
||||
export {};
|
||||
|
@ -21,7 +21,7 @@ const grab_query_and_values_1 = __importDefault(require("../../../utils/grab-que
|
||||
* # Get Function FOr API
|
||||
*/
|
||||
function apiGet(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, debug, dbContext, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, debug, dbContext, forceLocal, }) {
|
||||
const queryAndValues = (0, grab_query_and_values_1.default)({
|
||||
query,
|
||||
values: queryValues,
|
||||
@ -40,6 +40,7 @@ function apiGet(_a) {
|
||||
tableName,
|
||||
dbContext,
|
||||
debug,
|
||||
forceLocal,
|
||||
});
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("apiGet:result", result);
|
||||
|
@ -7,9 +7,10 @@ type Param = {
|
||||
tableName?: string;
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Post Function For API
|
||||
*/
|
||||
export default function apiPost({ query, dbFullName, queryValues, tableName, dbSchema, dbContext, }: Param): Promise<PostReturn>;
|
||||
export default function apiPost({ query, dbFullName, queryValues, tableName, dbSchema, dbContext, forceLocal, }: Param): Promise<PostReturn>;
|
||||
export {};
|
||||
|
@ -20,7 +20,7 @@ const runQuery_1 = __importDefault(require("../../backend/db/runQuery"));
|
||||
* # Post Function For API
|
||||
*/
|
||||
function apiPost(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, dbContext, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, dbFullName, queryValues, tableName, dbSchema, dbContext, forceLocal, }) {
|
||||
var _b;
|
||||
if (typeof query === "string" && (query === null || query === void 0 ? void 0 : query.match(/^create |^alter |^drop /i))) {
|
||||
return { success: false, msg: "Wrong Input" };
|
||||
@ -43,6 +43,7 @@ function apiPost(_a) {
|
||||
queryValuesArray: queryValues,
|
||||
tableName,
|
||||
dbContext,
|
||||
forceLocal,
|
||||
});
|
||||
results = result;
|
||||
if (error)
|
||||
|
@ -11,9 +11,10 @@ type Param = {
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
export default function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, }: Param): Promise<any>;
|
||||
export default function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, }: Param): Promise<any>;
|
||||
export {};
|
||||
|
@ -23,12 +23,14 @@ const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
function addDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, }) {
|
||||
var _b, _c;
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
const isMaster = (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
@ -6,10 +6,11 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Delete DB Entry Function
|
||||
* @description
|
||||
*/
|
||||
export default function deleteDbEntry({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, }: Param): Promise<object | null>;
|
||||
export default function deleteDbEntry({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, }: Param): Promise<object | null>;
|
||||
export {};
|
||||
|
@ -20,9 +20,11 @@ const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-han
|
||||
* @description
|
||||
*/
|
||||
function deleteDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, }) {
|
||||
try {
|
||||
const isMaster = (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
@ -8,6 +8,7 @@ type Param = {
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
type Return = {
|
||||
result: any;
|
||||
@ -16,5 +17,5 @@ type Return = {
|
||||
/**
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
export default function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, }: Param): Promise<Return>;
|
||||
export default function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, forceLocal, }: Param): Promise<Return>;
|
||||
export {};
|
||||
|
@ -26,7 +26,7 @@ exports.DbContextsArray = ["Master", "Dsql User"];
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
function runQuery(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, forceLocal, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
@ -76,6 +76,7 @@ function runQuery(_a) {
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
else {
|
||||
@ -83,6 +84,7 @@ function runQuery(_a) {
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Update DB Function
|
||||
* @description
|
||||
*/
|
||||
export default function updateDbEntry({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, }: Param): Promise<object | null>;
|
||||
export default function updateDbEntry({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }: Param): Promise<object | null>;
|
||||
export {};
|
||||
|
@ -23,14 +23,16 @@ const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-han
|
||||
* @description
|
||||
*/
|
||||
function updateDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }) {
|
||||
var _b;
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
if (!data || !Object.keys(data).length)
|
||||
return null;
|
||||
const isMaster = (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
@ -2,9 +2,10 @@ type Param = {
|
||||
queryString: string;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType | null;
|
||||
queryValuesArray?: string[];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Full Access Db Handler
|
||||
*/
|
||||
export default function fullAccessDbHandler({ queryString, tableSchema, queryValuesArray, }: Param): Promise<any>;
|
||||
export default function fullAccessDbHandler({ queryString, tableSchema, queryValuesArray, forceLocal, }: Param): Promise<any>;
|
||||
export {};
|
||||
|
@ -20,14 +20,16 @@ const serverError_1 = __importDefault(require("./serverError"));
|
||||
* # Full Access Db Handler
|
||||
*/
|
||||
function fullAccessDbHandler(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ queryString, tableSchema, queryValuesArray, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ queryString, tableSchema, queryValuesArray, forceLocal, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
const DB_CONN = global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_CONN = forceLocal
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
|
@ -2,10 +2,11 @@ type Param = {
|
||||
queryString: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Read Only Db Handler with Varaibles
|
||||
* @returns
|
||||
*/
|
||||
export default function varReadOnlyDatabaseDbHandler({ queryString, queryValuesArray, tableSchema, }: Param): Promise<any>;
|
||||
export default function varReadOnlyDatabaseDbHandler({ queryString, queryValuesArray, tableSchema, forceLocal, }: Param): Promise<any>;
|
||||
export {};
|
||||
|
@ -21,9 +21,11 @@ const conn_db_handler_1 = __importDefault(require("../../utils/db/conn-db-handle
|
||||
* @returns
|
||||
*/
|
||||
function varReadOnlyDatabaseDbHandler(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ queryString, queryValuesArray, tableSchema, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ queryString, queryValuesArray, tableSchema, forceLocal, }) {
|
||||
let results;
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_CONN = forceLocal
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
try {
|
||||
results = yield (0, conn_db_handler_1.default)(DB_CONN, queryString, queryValuesArray);
|
||||
}
|
||||
|
12
dist/package-shared/utils/data-fetching/crud.js
vendored
12
dist/package-shared/utils/data-fetching/crud.js
vendored
@ -13,9 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = dsqlCrud;
|
||||
const get_1 = __importDefault(require("../../actions/get"));
|
||||
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, targetId, query, sanitize, debug, }) {
|
||||
const finalData = sanitize ? sanitize(data) : data;
|
||||
@ -27,7 +27,12 @@ function dsqlCrud(_a) {
|
||||
tableName: table,
|
||||
genObject: query,
|
||||
});
|
||||
const GET_RES = yield (0, conn_db_handler_1.default)(global.DSQL_DB_CONN, (queryObject === null || queryObject === void 0 ? void 0 : queryObject.string) || "", (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || []);
|
||||
const GET_RES = yield (0, get_1.default)({
|
||||
query: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.string) || "",
|
||||
queryValues: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
|
||||
debug,
|
||||
forceLocal: true,
|
||||
});
|
||||
return Object.assign(Object.assign({}, GET_RES), { queryObject });
|
||||
case "insert":
|
||||
return yield (0, post_1.default)({
|
||||
@ -36,6 +41,7 @@ function dsqlCrud(_a) {
|
||||
table,
|
||||
data: finalData,
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
case "update":
|
||||
data === null || data === void 0 ? true : delete data.id;
|
||||
@ -47,6 +53,7 @@ function dsqlCrud(_a) {
|
||||
identifierValue: String(finalId),
|
||||
data: finalData,
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
case "delete":
|
||||
return yield (0, post_1.default)({
|
||||
@ -56,6 +63,7 @@ function dsqlCrud(_a) {
|
||||
identifierColumnName: "id",
|
||||
identifierValue: String(finalId),
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
default:
|
||||
return null;
|
||||
|
@ -20,6 +20,7 @@ type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
|
||||
tableName?: string;
|
||||
user_id?: string | number;
|
||||
debug?: boolean;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
export type ApiGetParams = Param;
|
||||
@ -37,6 +38,7 @@ export default async function get<
|
||||
tableName,
|
||||
user_id,
|
||||
debug,
|
||||
forceLocal,
|
||||
}: Param<T>): Promise<GetReturn> {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -70,6 +72,7 @@ export default async function get<
|
||||
tableName,
|
||||
dbSchema,
|
||||
debug,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ type Param = {
|
||||
queryValues?: any[];
|
||||
tableName?: string;
|
||||
user_id?: boolean;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -25,6 +26,7 @@ export default async function post({
|
||||
database,
|
||||
tableName,
|
||||
user_id,
|
||||
forceLocal,
|
||||
}: Param): Promise<PostReturn> {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -61,6 +63,7 @@ export default async function post({
|
||||
dbSchema,
|
||||
queryValues,
|
||||
tableName,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ type Param<T extends { [key: string]: any } = { [key: string]: any }> = {
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
debug?: boolean;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -31,6 +32,7 @@ export default async function apiGet<
|
||||
dbSchema,
|
||||
debug,
|
||||
dbContext,
|
||||
forceLocal,
|
||||
}: Param<T>): Promise<import("../../../types").GetReturn> {
|
||||
const queryAndValues = apiGetGrabQueryAndValues({
|
||||
query,
|
||||
@ -53,6 +55,7 @@ export default async function apiGet<
|
||||
tableName,
|
||||
dbContext,
|
||||
debug,
|
||||
forceLocal,
|
||||
});
|
||||
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
|
@ -10,6 +10,7 @@ type Param = {
|
||||
tableName?: string;
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
dbContext?: (typeof DbContextsArray)[number];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -22,6 +23,7 @@ export default async function apiPost({
|
||||
tableName,
|
||||
dbSchema,
|
||||
dbContext,
|
||||
forceLocal,
|
||||
}: Param): Promise<PostReturn> {
|
||||
if (typeof query === "string" && query?.match(/^create |^alter |^drop /i)) {
|
||||
return { success: false, msg: "Wrong Input" };
|
||||
@ -49,6 +51,7 @@ export default async function apiPost({
|
||||
queryValuesArray: queryValues,
|
||||
tableName,
|
||||
dbContext,
|
||||
forceLocal,
|
||||
});
|
||||
|
||||
results = result;
|
||||
|
@ -19,6 +19,7 @@ type Param = {
|
||||
update?: boolean;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -36,11 +37,14 @@ export default async function addDbEntry({
|
||||
update,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
forceLocal,
|
||||
}: Param): Promise<any> {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
|
@ -9,6 +9,7 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -21,9 +22,12 @@ export default async function deleteDbEntry({
|
||||
tableName,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
forceLocal,
|
||||
}: Param): Promise<object | null> {
|
||||
try {
|
||||
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
|
@ -18,6 +18,7 @@ type Param = {
|
||||
dbSchema?: import("../../../types").DSQL_DatabaseSchemaType;
|
||||
queryValuesArray?: (string | number)[];
|
||||
tableName?: string;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
type Return = {
|
||||
@ -37,6 +38,7 @@ export default async function runQuery({
|
||||
tableName,
|
||||
debug,
|
||||
dbContext,
|
||||
forceLocal,
|
||||
}: Param): Promise<Return> {
|
||||
/**
|
||||
* Declare variables
|
||||
@ -93,12 +95,14 @@ export default async function runQuery({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
} else {
|
||||
result = await fullAccessDbHandler({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray?.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
} else if (typeof query === "object") {
|
||||
|
@ -15,6 +15,7 @@ type Param = {
|
||||
tableSchema?: import("../../../types").DSQL_TableSchemaType;
|
||||
identifierColumnName: string;
|
||||
identifierValue: string | number;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -31,13 +32,16 @@ export default async function updateDbEntry({
|
||||
identifierValue,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
forceLocal,
|
||||
}: Param): Promise<object | null> {
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
if (!data || !Object.keys(data).length) return null;
|
||||
|
||||
const isMaster = checkIfIsMaster({ dbContext, dbFullName });
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
|
@ -6,6 +6,7 @@ type Param = {
|
||||
queryString: string;
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType | null;
|
||||
queryValuesArray?: string[];
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -15,6 +16,7 @@ export default async function fullAccessDbHandler({
|
||||
queryString,
|
||||
tableSchema,
|
||||
queryValuesArray,
|
||||
forceLocal,
|
||||
}: Param) {
|
||||
/**
|
||||
* Declare variables
|
||||
@ -23,7 +25,9 @@ export default async function fullAccessDbHandler({
|
||||
*/
|
||||
let results;
|
||||
|
||||
const DB_CONN = global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_CONN = forceLocal
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
|
@ -6,6 +6,7 @@ type Param = {
|
||||
queryString: string;
|
||||
queryValuesArray?: string[];
|
||||
tableSchema?: import("../../types").DSQL_TableSchemaType;
|
||||
forceLocal?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -16,10 +17,13 @@ export default async function varReadOnlyDatabaseDbHandler({
|
||||
queryString,
|
||||
queryValuesArray,
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
}: Param) {
|
||||
let results;
|
||||
|
||||
const DB_CONN = global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_CONN = forceLocal
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
|
||||
try {
|
||||
results = await connDbHandler(DB_CONN, queryString, queryValuesArray);
|
||||
|
@ -2,7 +2,6 @@ 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 from "../db/conn-db-handler";
|
||||
|
||||
export default async function dsqlCrud<
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
@ -31,11 +30,12 @@ export default async function dsqlCrud<
|
||||
genObject: query,
|
||||
});
|
||||
|
||||
const GET_RES = await connDbHandler(
|
||||
global.DSQL_DB_CONN,
|
||||
queryObject?.string || "",
|
||||
queryObject?.values || []
|
||||
);
|
||||
const GET_RES = await get({
|
||||
query: queryObject?.string || "",
|
||||
queryValues: queryObject?.values || [],
|
||||
debug,
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
return { ...GET_RES, queryObject };
|
||||
|
||||
@ -46,6 +46,7 @@ export default async function dsqlCrud<
|
||||
table,
|
||||
data: finalData,
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
case "update":
|
||||
@ -59,6 +60,7 @@ export default async function dsqlCrud<
|
||||
identifierValue: String(finalId),
|
||||
data: finalData,
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
case "delete":
|
||||
@ -69,6 +71,7 @@ export default async function dsqlCrud<
|
||||
identifierColumnName: "id",
|
||||
identifierValue: String(finalId),
|
||||
},
|
||||
forceLocal: true,
|
||||
});
|
||||
|
||||
default:
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "4.1.1",
|
||||
"version": "4.1.2",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user