@sap/cds-compiler
Version:
CDS (Core Data Services) compiler and backends
47 lines (43 loc) • 1.94 kB
JavaScript
;
const { isPersistedOnDatabase } = require('../model/csnUtils.js');
/**
* Check that we don't have parameterized views - as we don't know yet how to represent them on postgres
*
* @param {object} parent Object with .params
* @param {string} name Name of the params property on parent
* @param {object} params params
* @param {CSN.Path} path
*/
function checkForParams( parent, name, params, path ) {
const artifact = this.csn.definitions[path[1]];
if (artifact.kind === 'entity' && isPersistedOnDatabase(artifact) && artifact['@cds.persistence.exists'] !== true && parent.kind === 'entity') {
if (artifact.query || artifact.projection) {
if (this.options.sqlDialect === 'hana') {
for (const pname in artifact.params) {
if (pname.match(/\W/g) || pname.match(/^\d/) || pname.match(/^_/)) { // parameter name must be regular SQL identifier
this.warning(null, [ ...path, 'params', pname ], 'Expecting regular SQL-Identifier');
}
else if (this.options.sqlMapping !== 'plain' && pname.toUpperCase() !== pname) { // not plain mode: param name must be all upper
this.warning(null, [ ...path, 'params', pname ], { name: this.options.sqlMapping },
'Expecting parameter to be uppercase in naming mode $(NAME)');
}
}
}
else {
this.error('ref-unexpected-params', [ ...path, 'params' ], { value: this.options.sqlDialect },
'Parameterized views can\'t be used with sqlDialect $(VALUE)');
}
}
else {
this.error(null, path, { '#': this.options.toSql ? 'sql' : 'std' }, {
std: 'Table-like entities with parameters are not supported for conversion to SAP HANA CDS',
sql: 'Table-like entities with parameters are not supported for conversion to SQL',
});
}
}
}
module.exports = {
csnValidator: {
params: checkForParams,
},
};