Getting casting working again, have to pass down prefix for checking against fields.
This commit is contained in:
parent
b0e6d3e72c
commit
3394e974d3
|
@ -184,7 +184,11 @@ class InternalBuilder {
|
||||||
query: Knex.QueryBuilder,
|
query: Knex.QueryBuilder,
|
||||||
filters: SearchFilters | undefined,
|
filters: SearchFilters | undefined,
|
||||||
table: Table,
|
table: Table,
|
||||||
opts: { aliases?: Record<string, string>; relationship?: boolean }
|
opts: {
|
||||||
|
aliases?: Record<string, string>
|
||||||
|
relationship?: boolean
|
||||||
|
columnPrefix?: string
|
||||||
|
}
|
||||||
): Knex.QueryBuilder {
|
): Knex.QueryBuilder {
|
||||||
if (!filters) {
|
if (!filters) {
|
||||||
return query
|
return query
|
||||||
|
@ -192,7 +196,10 @@ class InternalBuilder {
|
||||||
filters = parseFilters(filters)
|
filters = parseFilters(filters)
|
||||||
// if all or specified in filters, then everything is an or
|
// if all or specified in filters, then everything is an or
|
||||||
const allOr = filters.allOr
|
const allOr = filters.allOr
|
||||||
const sqlStatements = new SqlStatements(this.client, table, { allOr })
|
const sqlStatements = new SqlStatements(this.client, table, {
|
||||||
|
allOr,
|
||||||
|
columnPrefix: opts.columnPrefix,
|
||||||
|
})
|
||||||
const tableName =
|
const tableName =
|
||||||
this.client === SqlClient.SQL_LITE ? table._id! : table.name
|
this.client === SqlClient.SQL_LITE ? table._id! : table.name
|
||||||
|
|
||||||
|
@ -663,6 +670,7 @@ class InternalBuilder {
|
||||||
}
|
}
|
||||||
// add filters to the query (where)
|
// add filters to the query (where)
|
||||||
query = this.addFilters(query, filters, json.meta.table, {
|
query = this.addFilters(query, filters, json.meta.table, {
|
||||||
|
columnPrefix: json.meta.columnPrefix,
|
||||||
aliases: tableAliases,
|
aliases: tableAliases,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -698,6 +706,7 @@ class InternalBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addFilters(query, filters, json.meta.table, {
|
return this.addFilters(query, filters, json.meta.table, {
|
||||||
|
columnPrefix: json.meta.columnPrefix,
|
||||||
relationship: true,
|
relationship: true,
|
||||||
aliases: tableAliases,
|
aliases: tableAliases,
|
||||||
})
|
})
|
||||||
|
@ -708,6 +717,7 @@ class InternalBuilder {
|
||||||
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
||||||
const parsedBody = parseBody(body)
|
const parsedBody = parseBody(body)
|
||||||
query = this.addFilters(query, filters, json.meta.table, {
|
query = this.addFilters(query, filters, json.meta.table, {
|
||||||
|
columnPrefix: json.meta.columnPrefix,
|
||||||
aliases: tableAliases,
|
aliases: tableAliases,
|
||||||
})
|
})
|
||||||
// mysql can't use returning
|
// mysql can't use returning
|
||||||
|
@ -722,6 +732,7 @@ class InternalBuilder {
|
||||||
const { endpoint, filters, tableAliases } = json
|
const { endpoint, filters, tableAliases } = json
|
||||||
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
||||||
query = this.addFilters(query, filters, json.meta.table, {
|
query = this.addFilters(query, filters, json.meta.table, {
|
||||||
|
columnPrefix: json.meta.columnPrefix,
|
||||||
aliases: tableAliases,
|
aliases: tableAliases,
|
||||||
})
|
})
|
||||||
// mysql can't use returning
|
// mysql can't use returning
|
||||||
|
|
|
@ -5,19 +5,27 @@ export class SqlStatements {
|
||||||
client: string
|
client: string
|
||||||
table: Table
|
table: Table
|
||||||
allOr: boolean | undefined
|
allOr: boolean | undefined
|
||||||
|
columnPrefix: string | undefined
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
client: string,
|
client: string,
|
||||||
table: Table,
|
table: Table,
|
||||||
{ allOr }: { allOr?: boolean } = {}
|
{ allOr, columnPrefix }: { allOr?: boolean; columnPrefix?: string } = {}
|
||||||
) {
|
) {
|
||||||
this.client = client
|
this.client = client
|
||||||
this.table = table
|
this.table = table
|
||||||
this.allOr = allOr
|
this.allOr = allOr
|
||||||
|
this.columnPrefix = columnPrefix
|
||||||
}
|
}
|
||||||
|
|
||||||
getField(key: string): FieldSchema | undefined {
|
getField(key: string): FieldSchema | undefined {
|
||||||
const fieldName = key.split(".")[1]
|
const fieldName = key.split(".")[1]
|
||||||
return this.table.schema[fieldName]
|
let found = this.table.schema[fieldName]
|
||||||
|
if (!found && this.columnPrefix) {
|
||||||
|
const prefixRemovedFieldName = fieldName.replace(this.columnPrefix, "")
|
||||||
|
found = this.table.schema[prefixRemovedFieldName]
|
||||||
|
}
|
||||||
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
between(
|
between(
|
||||||
|
|
|
@ -235,6 +235,7 @@ export async function search(
|
||||||
meta: {
|
meta: {
|
||||||
table,
|
table,
|
||||||
tables: allTablesMap,
|
tables: allTablesMap,
|
||||||
|
columnPrefix: USER_COLUMN_PREFIX,
|
||||||
},
|
},
|
||||||
resource: {
|
resource: {
|
||||||
fields: buildInternalFieldList(table, allTables),
|
fields: buildInternalFieldList(table, allTables),
|
||||||
|
|
|
@ -122,6 +122,8 @@ export interface QueryJson {
|
||||||
table: Table
|
table: Table
|
||||||
tables?: Record<string, Table>
|
tables?: Record<string, Table>
|
||||||
renamed?: RenameColumn
|
renamed?: RenameColumn
|
||||||
|
// can specify something that columns could be prefixed with
|
||||||
|
columnPrefix?: string
|
||||||
}
|
}
|
||||||
extra?: {
|
extra?: {
|
||||||
idFilter?: SearchFilters
|
idFilter?: SearchFilters
|
||||||
|
|
Loading…
Reference in New Issue