|
|
|
@ -206,14 +206,14 @@ class BaseModelSqlv2 {
|
|
|
|
|
const { where, fields, ...rest } = this._getListArgs(args as any); |
|
|
|
|
|
|
|
|
|
const innerQb = this.dbDriver(this.tnPath); |
|
|
|
|
innerQb.select('*') |
|
|
|
|
innerQb.select('*'); |
|
|
|
|
|
|
|
|
|
const wrapperQb = this.dbDriver.from(innerQb.as(INNER_QUERY_ALIAS)) |
|
|
|
|
const wrapperQb = this.dbDriver.from(innerQb.as(INNER_QUERY_ALIAS)); |
|
|
|
|
await this.selectObject({ |
|
|
|
|
qb: wrapperQb, |
|
|
|
|
fieldsSet: args.fieldsSet, |
|
|
|
|
viewId: this.viewId, |
|
|
|
|
alias: INNER_QUERY_ALIAS |
|
|
|
|
alias: INNER_QUERY_ALIAS, |
|
|
|
|
}); |
|
|
|
|
if (+rest?.shuffle) { |
|
|
|
|
await this.shuffle({ qb: innerQb }); |
|
|
|
@ -288,10 +288,6 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
const data = await this.execAndParse(wrapperQb); |
|
|
|
|
|
|
|
|
|
// todo: remove
|
|
|
|
|
console.log(wrapperQb.toQuery()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return data?.map((d) => { |
|
|
|
|
d.__proto__ = proto; |
|
|
|
|
return d; |
|
|
|
@ -413,7 +409,10 @@ class BaseModelSqlv2 {
|
|
|
|
|
return await qb; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async multipleHmList({ colId, ids }, args: { limit?; offset?; fieldsSet?:Set<string> } = {}) { |
|
|
|
|
async multipleHmList( |
|
|
|
|
{ colId, ids }, |
|
|
|
|
args: { limit?; offset?; fieldsSet?: Set<string> } = {} |
|
|
|
|
) { |
|
|
|
|
try { |
|
|
|
|
const { where, sort, ...rest } = this._getListArgs(args as any); |
|
|
|
|
// todo: get only required fields
|
|
|
|
@ -441,7 +440,11 @@ class BaseModelSqlv2 {
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(childTn); |
|
|
|
|
await childModel.selectObject({ qb, extractPkAndPv: true, fieldsSet: args.fieldsSet }); |
|
|
|
|
await childModel.selectObject({ |
|
|
|
|
qb, |
|
|
|
|
extractPkAndPv: true, |
|
|
|
|
fieldsSet: args.fieldsSet, |
|
|
|
|
}); |
|
|
|
|
await this.applySortAndFilter({ table: childTable, where, qb, sort }); |
|
|
|
|
|
|
|
|
|
const childQb = this.dbDriver.queryBuilder().from( |
|
|
|
@ -1254,7 +1257,10 @@ class BaseModelSqlv2 {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async getSelectQueryBuilderForFormula(column: Column<any>, tableAlias?:string ) { |
|
|
|
|
private async getSelectQueryBuilderForFormula( |
|
|
|
|
column: Column<any>, |
|
|
|
|
tableAlias?: string |
|
|
|
|
) { |
|
|
|
|
const formula = await column.getColOptions<FormulaColumn>(); |
|
|
|
|
if (formula.error) throw new Error(`Formula error: ${formula.error}`); |
|
|
|
|
const qb = await formulaQueryBuilderv2( |
|
|
|
@ -1408,7 +1414,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
{ |
|
|
|
|
// limit: ids.length,
|
|
|
|
|
where: `(${pCol.column_name},in,${ids.join(',')})`, |
|
|
|
|
fieldsSet: (readLoader as any).args?.fieldsSet |
|
|
|
|
fieldsSet: (readLoader as any).args?.fieldsSet, |
|
|
|
|
}, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
@ -1482,7 +1488,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
extractPkAndPv, |
|
|
|
|
viewId, |
|
|
|
|
fieldsSet, |
|
|
|
|
alias |
|
|
|
|
alias, |
|
|
|
|
}: { |
|
|
|
|
fieldsSet?: Set<string>; |
|
|
|
|
qb: Knex.QueryBuilder; |
|
|
|
@ -1510,14 +1516,15 @@ class BaseModelSqlv2 {
|
|
|
|
|
// hide if column marked as hidden in view
|
|
|
|
|
// of if column is system field and system field is hidden
|
|
|
|
|
if ( |
|
|
|
|
fieldsSet ? !fieldsSet.has(column.title) : ( |
|
|
|
|
!extractPkAndPv && |
|
|
|
|
fieldsSet |
|
|
|
|
? !fieldsSet.has(column.title) |
|
|
|
|
: !extractPkAndPv && |
|
|
|
|
!(viewOrTableColumn instanceof Column) && |
|
|
|
|
(!(viewOrTableColumn as GridViewColumn)?.show || |
|
|
|
|
(!view?.show_system_fields && |
|
|
|
|
column.uidt !== UITypes.ForeignKey && |
|
|
|
|
!column.pk && |
|
|
|
|
isSystemColumn(column))) ) |
|
|
|
|
isSystemColumn(column))) |
|
|
|
|
) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
@ -1575,7 +1582,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
case UITypes.Formula: |
|
|
|
|
try { |
|
|
|
|
const selectQb = await this.getSelectQueryBuilderForFormula( |
|
|
|
|
barcodeValueColumn, |
|
|
|
|
barcodeValueColumn |
|
|
|
|
); |
|
|
|
|
qb.select({ |
|
|
|
|
[column.column_name]: selectQb.builder, |
|
|
|
@ -1608,7 +1615,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
]) |
|
|
|
|
); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
console.log(e); |
|
|
|
|
// return dummy select
|
|
|
|
|
qb.select( |
|
|
|
|
this.dbDriver.raw(`'ERR' as ??`, [sanitize(column.title)]) |
|
|
|
|