Comparing version 47.0.1 to 47.0.2
import assert from 'assert'; | ||
import { defaultPropDescriptor } from './config.js'; | ||
import { genColumnMaping, patchWhereColumnAlias, splitScopedColumn } from './smart-join.helper.js'; | ||
import { SmartKey } from './types.js'; | ||
@@ -12,23 +13,7 @@ export function processJoinTableColumnAlias(builder) { | ||
} | ||
const aliasMap = new Map(); | ||
// @ts-ignore | ||
// const queryContext = builder._queryContext as QueryContext | undefined | ||
// const caseConvert = queryContext?.postProcessResponseCaseConvert ?? CaseType.snake | ||
const tablesJoin = new Set([...builder._tablesJoin]); | ||
tablesJoin.forEach((tableName) => { | ||
// @ts-ignore | ||
const scopedCols = dbDict.scoped[tableName]; | ||
if (typeof scopedCols === 'object') { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
Object.entries(scopedCols).forEach(([colName, col]) => { | ||
if (typeof col !== 'string') { | ||
return; | ||
} | ||
if (aliasMap.has(colName)) { | ||
const colName2 = col.replace(/\./ug, '_'); | ||
aliasMap.set(colName2, col); | ||
} | ||
else { | ||
aliasMap.set(colName, col); | ||
} | ||
}); | ||
} | ||
}); | ||
const aliasMap = genColumnMaping(dbDict, tablesJoin); | ||
const aliasObject = {}; | ||
@@ -45,27 +30,2 @@ aliasMap.forEach((col, alias) => { | ||
} | ||
function patchWhereColumnAlias(builder, aliasMap = new Map()) { | ||
if (!aliasMap.size) { | ||
return builder; | ||
} | ||
// @ts-ignore | ||
const statements = builder._statements; | ||
if (Array.isArray(statements) && statements.length) { | ||
statements.forEach((statement) => { | ||
if (statement.grouping !== 'where') { | ||
return; | ||
} | ||
// if (statement.asColumn) { return } | ||
const { column } = statement; | ||
if (!column || typeof column !== 'string') { | ||
return; | ||
} | ||
const scoped = aliasMap.get(column); | ||
if (!scoped || column === scoped) { | ||
return; | ||
} | ||
statement.column = scoped; | ||
}); | ||
} | ||
return builder; | ||
} | ||
export function extRefTableFnPropertySmartJoin(refTable) { | ||
@@ -109,10 +69,2 @@ Object.values(SmartKey).forEach((joinType) => { | ||
} | ||
function splitScopedColumn(input) { | ||
const arr = input.split('.'); | ||
const tableName = arr.slice(0, -1).join('.'); | ||
const col = arr.at(-1); | ||
assert(tableName); | ||
assert(col); | ||
return [tableName, col]; | ||
} | ||
//# sourceMappingURL=smart-join.js.map |
{ | ||
"name": "kmore", | ||
"author": "waiting", | ||
"version": "47.0.1", | ||
"version": "47.0.2", | ||
"description": "A SQL query builder based on knex with powerful TypeScript type support", | ||
@@ -81,3 +81,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "e74baf85711fdee61a03350505c43925ce62a1b8" | ||
"gitHead": "e7e96f5c0e7a783e234f61b3836482edb08c92d4" | ||
} |
import assert from 'assert' | ||
import { defaultPropDescriptor } from './config.js' | ||
import { genColumnMaping, patchWhereColumnAlias, splitScopedColumn } from './smart-join.helper.js' | ||
import { KmoreQueryBuilder, SmartKey } from './types.js' | ||
@@ -20,25 +21,8 @@ | ||
const aliasMap = new Map<string, string>() | ||
// @ts-ignore | ||
// const queryContext = builder._queryContext as QueryContext | undefined | ||
// const caseConvert = queryContext?.postProcessResponseCaseConvert ?? CaseType.snake | ||
const tablesJoin = new Set([...builder._tablesJoin]) | ||
const aliasMap = genColumnMaping(dbDict, tablesJoin) | ||
tablesJoin.forEach((tableName) => { | ||
// @ts-ignore | ||
const scopedCols = dbDict.scoped[tableName] | ||
if (typeof scopedCols === 'object') { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
Object.entries(scopedCols).forEach(([colName, col]) => { | ||
if (typeof col !== 'string') { return } | ||
if (aliasMap.has(colName)) { | ||
const colName2 = col.replace(/\./ug, '_') | ||
aliasMap.set(colName2, col) | ||
} | ||
else { | ||
aliasMap.set(colName, col) | ||
} | ||
}) | ||
} | ||
}) | ||
const aliasObject: Record<string, string> = {} | ||
@@ -57,32 +41,3 @@ aliasMap.forEach((col, alias) => { | ||
function patchWhereColumnAlias( | ||
builder: KmoreQueryBuilder, | ||
aliasMap: Map<string, string> = new Map(), | ||
): KmoreQueryBuilder { | ||
if (! aliasMap.size) { | ||
return builder | ||
} | ||
// @ts-ignore | ||
const statements = builder._statements | ||
if (Array.isArray(statements) && statements.length) { | ||
statements.forEach((statement) => { | ||
if (statement.grouping !== 'where') { return } | ||
// if (statement.asColumn) { return } | ||
const { column } = statement | ||
if (! column || typeof column !== 'string') { return } | ||
const scoped = aliasMap.get(column) | ||
if (! scoped || column === scoped) { return } | ||
statement.column = scoped | ||
}) | ||
} | ||
return builder | ||
} | ||
export function extRefTableFnPropertySmartJoin( | ||
@@ -148,14 +103,1 @@ refTable: KmoreQueryBuilder, | ||
function splitScopedColumn(input: string): [string, string] { | ||
const arr = input.split('.') | ||
const tableName = arr.slice(0, -1).join('.') | ||
const col = arr.at(-1) | ||
assert(tableName) | ||
assert(col) | ||
return [tableName, col] | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
253626
82
4295