diff --git a/functions/sql/sql-generator.js b/functions/sql/sql-generator.js index d91a7f9..572be04 100644 --- a/functions/sql/sql-generator.js +++ b/functions/sql/sql-generator.js @@ -69,13 +69,22 @@ function sqlGenerator({ tableName, genObject }) { typeof mtch.source == "object" ? mtch.source.tableName : tableName }.${ typeof mtch.source == "object" ? mtch.source.fieldName : mtch.source - }=${ - typeof mtch.target == "object" - ? mtch.target.tableName - : join.tableName - }.${ - typeof mtch.target == "object" ? mtch.target.fieldName : mtch.target - }`; + }=${(() => { + if (mtch.targetLiteral) { + sqlSearhValues.push(mtch.targetLiteral); + return "?"; + } + + return `${ + typeof mtch.target == "object" + ? mtch.target.tableName + : join.tableName + }.${ + typeof mtch.target == "object" + ? mtch.target.fieldName + : mtch.target + }`; + })()}`; } let queryString = (() => { diff --git a/package-shared/types/index.d.ts b/package-shared/types/index.d.ts index d9dd402..4c5e7a6 100644 --- a/package-shared/types/index.d.ts +++ b/package-shared/types/index.d.ts @@ -1168,6 +1168,7 @@ export type FetchDataParams = { method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE"; body?: object | string; query?: AuthFetchQuery; + tableName?: string; }; export type AuthFetchQuery = ServerQueryParam & { @@ -1196,9 +1197,11 @@ export type ServerQueryParamsJoinMatchObject< Field extends object = { [key: string]: any } > = { /** Field name from the **Root Table** */ - source: string | ServerQueryParamsJoinMatchSourceTargetObject; + source?: string | ServerQueryParamsJoinMatchSourceTargetObject; /** Field name from the **Join Table** */ - target: keyof Field | ServerQueryParamsJoinMatchSourceTargetObject; + target?: keyof Field | ServerQueryParamsJoinMatchSourceTargetObject; + /** A literal value: No source and target Needed! */ + targetLiteral?: string; }; export type ServerQueryParamsJoinMatchSourceTargetObject = {