This commit is contained in:
Benjamin Toby 2025-05-21 09:34:49 +01:00
parent 4adb5af430
commit 0fc2c7fb3e
8 changed files with 36 additions and 11 deletions

View File

@ -21,5 +21,5 @@ export default function get<T extends {
[k: string]: any;
} = {
[k: string]: any;
}>({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }: Param<T>): Promise<GetReturn>;
}, R extends any = any>({ key, db, query, queryValues, tableName, user_id, debug, forceLocal, }: Param<T>): Promise<GetReturn<R>>;
export {};

View File

@ -30,6 +30,12 @@ function sqlGenerator({ tableName, genObject, dbFullName }) {
if (queryObj.equality == "LIKE") {
str = `LOWER(${finalFieldName}) LIKE LOWER('%${valueParsed}%')`;
}
else if (queryObj.equality == "REGEXP") {
str = `${finalFieldName} REGEXP '${valueParsed}'`;
}
else if (queryObj.equality == "FULLTEXT") {
str = `MATCH(${finalFieldName}) AGAINST('${valueParsed}' IN BOOLEAN MODE)`;
}
else if (queryObj.equality == "NOT EQUAL") {
str = `${finalFieldName} != ?`;
sqlSearhValues.push(valueParsed);

View File

@ -277,9 +277,9 @@ export interface UpdateUserFunctionReturn {
success: boolean;
payload?: Object[] | string;
}
export interface GetReturn {
export interface GetReturn<R extends any = any> {
success: boolean;
payload?: any;
payload?: R;
msg?: string;
error?: string;
schema?: DSQL_TableSchemaType;
@ -942,7 +942,7 @@ export type FetchApiReturn = {
[key: string]: any;
};
export declare const ServerQueryOperators: readonly ["AND", "OR"];
export declare const ServerQueryEqualities: readonly ["EQUAL", "LIKE", "NOT EQUAL"];
export declare const ServerQueryEqualities: readonly ["EQUAL", "LIKE", "NOT EQUAL", "REGEXP", "FULLTEXT"];
export type ServerQueryParam<T extends {
[k: string]: any;
} = {
@ -1120,6 +1120,7 @@ export type HandleSocialDbFunctionParams = {
additionalFields?: string[];
debug?: boolean;
loginOnly?: boolean;
social_id?: string | number;
};
export type HandleSocialDbFunctionReturn = {
success: boolean;

View File

@ -12,6 +12,12 @@ exports.TextFieldTypesArray = [
{ title: "Shell", value: "shell" },
];
exports.ServerQueryOperators = ["AND", "OR"];
exports.ServerQueryEqualities = ["EQUAL", "LIKE", "NOT EQUAL"];
exports.ServerQueryEqualities = [
"EQUAL",
"LIKE",
"NOT EQUAL",
"REGEXP",
"FULLTEXT",
];
exports.DataCrudRequestMethods = ["GET", "POST", "PUT", "DELETE"];
exports.DsqlCrudActions = ["insert", "update", "delete", "get"];

View File

@ -30,7 +30,8 @@ export type ApiGetParams = Param;
* # Make a get request to Datasquirel API
*/
export default async function get<
T extends { [k: string]: any } = { [k: string]: any }
T extends { [k: string]: any } = { [k: string]: any },
R extends any = any
>({
key,
db,
@ -40,7 +41,7 @@ export default async function get<
user_id,
debug,
forceLocal,
}: Param<T>): Promise<GetReturn> {
}: Param<T>): Promise<GetReturn<R>> {
const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames;

View File

@ -62,6 +62,10 @@ export default function sqlGenerator<
if (queryObj.equality == "LIKE") {
str = `LOWER(${finalFieldName}) LIKE LOWER('%${valueParsed}%')`;
} else if (queryObj.equality == "REGEXP") {
str = `${finalFieldName} REGEXP '${valueParsed}'`;
} else if (queryObj.equality == "FULLTEXT") {
str = `MATCH(${finalFieldName}) AGAINST('${valueParsed}' IN BOOLEAN MODE)`;
} else if (queryObj.equality == "NOT EQUAL") {
str = `${finalFieldName} != ?`;
sqlSearhValues.push(valueParsed);

View File

@ -291,9 +291,9 @@ export interface UpdateUserFunctionReturn {
payload?: Object[] | string;
}
export interface GetReturn {
export interface GetReturn<R extends any = any> {
success: boolean;
payload?: any;
payload?: R;
msg?: string;
error?: string;
schema?: DSQL_TableSchemaType;
@ -1092,7 +1092,13 @@ export type FetchApiReturn = {
};
export const ServerQueryOperators = ["AND", "OR"] as const;
export const ServerQueryEqualities = ["EQUAL", "LIKE", "NOT EQUAL"] as const;
export const ServerQueryEqualities = [
"EQUAL",
"LIKE",
"NOT EQUAL",
"REGEXP",
"FULLTEXT",
] as const;
export type ServerQueryParam<
T extends { [k: string]: any } = { [k: string]: any }
@ -1295,6 +1301,7 @@ export type HandleSocialDbFunctionParams = {
additionalFields?: string[];
debug?: boolean;
loginOnly?: boolean;
social_id?: string | number;
};
export type HandleSocialDbFunctionReturn = {

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "4.6.1",
"version": "4.6.2",
"description": "Cloud-based SQL data management tool",
"main": "dist/index.js",
"bin": {