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