@sap/cds-ql
Advanced tools
Comparing version 1.0.0 to 1.5.0
@@ -9,2 +9,33 @@ # Changelog | ||
## Version 1.5.0 - 2019-02-06 | ||
### Changed | ||
- Minimum node version 8.9.0 | ||
## Version 1.4.0 - 2019-01-22 | ||
### Changed | ||
- Use latest version of @sap/cds-sql | ||
## Version 1.3.0 - 2019-01-11 | ||
### Changed | ||
- Use latest version of uuid and @sap/cds-sql | ||
## Version 1.2.0 - 2018-12-21 | ||
### Added | ||
- Allow Arrays in `UPDATE.set()` | ||
## Version 1.1.0 - 2018-12-12 | ||
### Added | ||
- Support for `full join` in SELECT | ||
- Support for inline | ||
## Version 1.0.0 - 2018-11-27 | ||
@@ -11,0 +42,0 @@ |
@@ -88,3 +88,3 @@ const Pool = require('./Pool') | ||
if (model) { | ||
return cds.load(...(Array.isArray(model) ? model : [model])).then(csn => { | ||
return cds.load(model).then(csn => { | ||
this.model = cds.linked(cds.unfold.for.odata(csn)) | ||
@@ -292,3 +292,5 @@ }) | ||
// require only when needed | ||
require('@sap/instance-manager').create(this.options.credentials || this.options, (err, instanceManager) => { | ||
let options = this.options.credentials || this.options | ||
options = Object.assign(options, { cache_max_items: 1, cache_item_expire_seconds: 1 }) | ||
require('@sap/instance-manager').create(options, (err, instanceManager) => { | ||
if (err) { | ||
@@ -295,0 +297,0 @@ reject(err) |
@@ -45,3 +45,5 @@ const { addToQueue } = require('./queue') | ||
if (value) { | ||
const entity = value.source || value.name || value | ||
// OLD CSN -> value.source | ||
const entity = | ||
(value.query && value.query.target && value.query.target.name) || value.source || value.name || value | ||
@@ -48,0 +50,0 @@ if (typeof entity === 'string') { |
@@ -139,2 +139,11 @@ const BaseStatement = require('./BaseStatement') | ||
as (selectCqn) { | ||
if (!selectCqn || !selectCqn.SELECT) { | ||
throw new IllegalFunctionArgumentError('as') | ||
} | ||
this.INSERT.as = selectCqn | ||
return this | ||
} | ||
_invalidArgs (argName, args) { | ||
@@ -141,0 +150,0 @@ if (!Array.isArray(args) || args.length === 0) { |
@@ -88,2 +88,5 @@ const cds = require('../cds') | ||
this.SELECT.columns = [] | ||
if (columns.includes('.{')) { | ||
columns = `{${columns.replace(/{/g, '').replace(/}/g, '')}}` | ||
} | ||
const res = cds.parse.cql(`SELECT from ${entity} ${columns.replace(/'/g, '')}`) | ||
@@ -214,2 +217,13 @@ this._parseArray(res.SELECT.columns, entity) | ||
/** | ||
* Add full join. | ||
* | ||
* @param tableName - Table name to be used for join. | ||
* @returns {Select} this object instance for chaining. | ||
* @throws UnexpectedFunctionCallError - If where or having was already called. | ||
*/ | ||
fullJoin (tableName, as) { | ||
return this._join(tableName, as, 'full') | ||
} | ||
/** | ||
* .on can only be used after .join has been called. | ||
@@ -411,2 +425,11 @@ * @param {string|Object} arg1 Can be object if argument is passed as an object or can be a string when an identifier is directly passed. | ||
} | ||
if (cqn.join) { | ||
return cqn.args | ||
.map(arg => { | ||
return this._getEntityNameFromCQN(arg) | ||
}) | ||
.filter(name => { | ||
return !name.endsWith('_drafts') | ||
})[0] | ||
} | ||
} | ||
@@ -536,6 +559,7 @@ | ||
_addColumnToOrderBy (column, order = 'asc') { | ||
const res = column.includes('.') ? this._parseElementWithDot(column, this.SELECT.from.ref[0]) : { ref: [column] } | ||
if (this.SELECT.hasOwnProperty('orderBy')) { | ||
this.SELECT.orderBy.push({ ref: [column] }) | ||
this.SELECT.orderBy.push(res) | ||
} else { | ||
this.SELECT.orderBy = [{ ref: [column] }] | ||
this.SELECT.orderBy = [res] | ||
} | ||
@@ -553,6 +577,11 @@ | ||
_addColumnToGroupBy (column) { | ||
const res = | ||
typeof column === 'string' && column.includes('.') | ||
? this._parseElementWithDot(column, this.SELECT.from.ref[0]) | ||
: { ref: [column] } | ||
if (this.SELECT.hasOwnProperty('groupBy')) { | ||
this.SELECT.groupBy.push({ ref: [column] }) | ||
this.SELECT.groupBy.push(res) | ||
} else { | ||
this.SELECT.groupBy = [{ ref: [column] }] | ||
this.SELECT.groupBy = [res] | ||
} | ||
@@ -571,3 +600,3 @@ } | ||
} else if (typeof columns[i] === 'string' && columns[i].includes('.')) { | ||
this._parseElementWithDot(columns[i], entityName) | ||
this.SELECT.columns.push(this._parseElementWithDot(columns[i], entityName)) | ||
} else { | ||
@@ -634,4 +663,4 @@ this.SELECT.columns.push(this._parseElement(columns[i])) | ||
if ((key.startsWith('expand(') || key.startsWith('inline(')) && Array.isArray(object[key])) { | ||
return this._parseExpandInline(key, object[key]) | ||
if (key.startsWith('expand(') && Array.isArray(object[key])) { | ||
return this._parseExpand(key, object[key]) | ||
} | ||
@@ -652,18 +681,9 @@ | ||
_parseExpandInline (expr, elements) { | ||
let ref, type | ||
if (expr.startsWith('expand(')) { | ||
type = 'expand' | ||
ref = { | ||
ref: [expr.replace(/(^expand\(|\)$)/g, '')] | ||
} | ||
} else { | ||
type = 'inline' | ||
ref = { | ||
ref: [expr.replace(/(^inline\(|\)$)/g, '')] | ||
} | ||
_parseExpand (expr, elements) { | ||
const ref = { | ||
ref: [expr.replace(/(^expand\(|\)$)/g, '')] | ||
} | ||
ref[type] = [] | ||
ref['expand'] = [] | ||
for (const element of elements) { | ||
ref[type].push(this._parseElement(element)) | ||
ref['expand'].push(this._parseElement(element)) | ||
} | ||
@@ -675,13 +695,10 @@ return ref | ||
if (column.includes('.{')) { | ||
// <-- inline, no isAssociation check | ||
this.SELECT.columns.push(this._buildInline(this._matchInline(column))) | ||
} else { | ||
// inline or column name with dot | ||
const parts = column.split(/\./) | ||
if (this._isAssociation(entityName, parts[0])) { | ||
this.SELECT.columns.push(this._parseElement({ [`inline(${parts[0]})`]: [parts[1]] })) | ||
} else { | ||
this.SELECT.columns.push(this._parseStringElement(column)) | ||
} | ||
return { ref: this._matchInline(column) } | ||
} | ||
const parts = column.split(/\./) | ||
if (this[MODEL] && this._isAssociation(entityName, parts[0])) { | ||
return { ref: parts } | ||
} | ||
return this._parseStringElement(column) | ||
} | ||
@@ -688,0 +705,0 @@ |
@@ -71,3 +71,5 @@ const Where = require('./Where') | ||
valueObject[key] === undefined || | ||
(valueObject[key] instanceof Object && Object.keys(valueObject[key]).length === 0) | ||
(valueObject[key] instanceof Object && | ||
!Array.isArray(valueObject[key]) && | ||
Object.keys(valueObject[key]).length === 0) | ||
) { | ||
@@ -74,0 +76,0 @@ return true |
@@ -500,6 +500,6 @@ const BaseStatement = require('./BaseStatement') | ||
_matchInline (name) { | ||
let matches = name.split(/\.\{/) | ||
const lastIndex = matches.length - 1 | ||
matches[lastIndex] = matches[lastIndex].match(/(\w+)\}+/)[1] | ||
return matches | ||
return name | ||
.replace(/{/g, '') | ||
.replace(/}/g, '') | ||
.split(/\./) | ||
} | ||
@@ -511,32 +511,29 @@ | ||
_buildWithTableName (element) { | ||
const tableNames = this._getTableNames() | ||
const matched = this._matchTableColumn(element) | ||
if (matched && tableNames.indexOf(matched[0]) !== -1) { | ||
return { ref: [matched[0], matched[1]] } | ||
_parseInlineAssociation (element, tableNames) { | ||
if (element.includes('.{')) { | ||
return { ref: this._matchInline(element) } | ||
} | ||
if (matched && this[MODEL]) { | ||
const parts = element.split(/\./) | ||
if (parts && this[MODEL]) { | ||
for (const table of tableNames) { | ||
if (this._isAssociation(table, matched[0])) { | ||
// <-- inline or column name with dot | ||
return this._buildInline(matched) | ||
// inline or column name with dot | ||
if (this._isAssociation(table, parts[0])) { | ||
return { ref: parts } | ||
} | ||
} | ||
} | ||
} | ||
if (element.includes('.{')) { | ||
// <-- inline, no isAssociation check | ||
return this._buildInline(this._matchInline(element)) | ||
_buildWithTableName (element) { | ||
const tableNames = this._getTableNames() | ||
const matched = this._matchTableColumn(element) | ||
if (matched && tableNames.indexOf(matched[0]) !== -1) { | ||
return { ref: [matched[0], matched[1]] } | ||
} | ||
} | ||
_buildInline (array) { | ||
let ref = { ref: [array[0]] } | ||
if (array.length > 1) { | ||
array.splice(0, 1) | ||
ref['inline'] = [this._buildInline(array)] | ||
if (element.includes('.')) { | ||
return this._parseInlineAssociation(element, tableNames) | ||
} | ||
return ref | ||
} | ||
@@ -695,3 +692,4 @@ | ||
_isAssociation (entityName, associationName) { | ||
const entity = this[MODEL].definitions[entityName] | ||
const name = typeof entityName === 'object' ? entityName.name : entityName | ||
const entity = this[MODEL].definitions[name] | ||
if (entity) { | ||
@@ -698,0 +696,0 @@ return entity.elements[associationName] && entity.elements[associationName].type === 'cds.Association' |
{ | ||
"name": "@sap/cds-ql", | ||
"version": "1.0.0", | ||
"version": "1.5.0", | ||
"lockfileVersion": 1, | ||
"requires": true, | ||
"dependencies": { | ||
"@sap/cds-hana": { | ||
"version": "1.0.3" | ||
"version": "1.5.0", | ||
"requires": { | ||
"@sap/cds-sql": "1.5.0" | ||
} | ||
}, | ||
"@sap/cds-sql": { | ||
"version": "1.0.3" | ||
"version": "1.5.0" | ||
}, | ||
"@sap/cds-sqlite": { | ||
"version": "1.0.3" | ||
"version": "1.5.0", | ||
"requires": { | ||
"@sap/cds-sql": "1.5.0" | ||
} | ||
}, | ||
@@ -18,5 +26,5 @@ "generic-pool": { | ||
"uuid": { | ||
"version": "3.2.1" | ||
"version": "3.3.2" | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-hana":"1.0.3","@sap/cds-sql":"1.0.3","@sap/cds-sqlite":"1.0.3","generic-pool":"3.4.2","uuid":"3.2.1"},"deprecated":false,"description":"This package deals with creating a pool of connection clients, connecting to a driver (read: db) and using these connection clients from the pool to insert, delete, select and update values or rows from a specific table. Performing these insert, delete, select and update operations also includes executing embedded queries and plain statements.","devDependencies":{"@sap/instance-manager":"^1.3.4","@sap/xsenv":"^1.2.9","husky":"^1.2.0","jest":"^23.6.0","jest-junit":"^5.2.0","jsdoc-to-markdown":"^4.0.1","lint-staged":"^8.1.0","prettier-standard":"^8.0.1","sqlite3":"4.0.4","standard":"^12.0.1","standard-reporter":"^1.0.5"},"engines":{"node":">= 8.0.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"jest":{"testEnvironment":"node"},"jest-junit":{"suiteName":"jest tests","output":"reports/sonar/test-reporter.xml","classNameTemplate":"{classname}-{title}","titleTemplate":"{classname}-{title}","ancestorSeparator":" › ","usePathForSuiteName":"true"},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-ql","scripts":{"build":"npm run test && npm run jsdoc2md","clean":"rm -rf reports && rm -f npm-debug.log && rm -rf node_modules/@sap/*/node_modules/@sap/cds-*","jsdoc2md":"jsdoc2md --param-list-format list lib/**/*.js > docs/api.md","lint":"([ -d reports ] || mkdir reports) && standard --env jest && standard | standard-reporter --checkstyle > reports/eslint.jslint.xml","prepareRelease":"node node_modules/filter-node-package package.json","snapshots":"[ -e .pipeline/snapshots.sh ] && sh .pipeline/snapshots.sh","test":"node -v && npm run clean && npm run lint && npm run test-unit && npm run test-integration","test-integration":"jest --config=jest-integration.json && [ -e reports/sonar/test-reporter.xml ] && mv reports/sonar/test-reporter.xml reports/sonar/test-integration.xml","test-unit":"jest --config=jest-unit.json && [ -e reports/sonar/test-reporter.xml ] && mv reports/sonar/test-reporter.xml reports/sonar/test-unit.xml"},"standard":{"env":["jest"],"globals":["jest"]},"version":"1.0.0","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-hana":"1.5.0","@sap/cds-sql":"1.5.0","@sap/cds-sqlite":"1.5.0","generic-pool":"3.4.2","uuid":"3.3.2"},"deprecated":false,"description":"This package deals with creating a pool of connection clients, connecting to a driver (read: db) and using these connection clients from the pool to insert, delete, select and update values or rows from a specific table. Performing these insert, delete, select and update operations also includes executing embedded queries and plain statements.","engines":{"node":">= 8.9.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-ql","version":"1.5.0","license":"SEE LICENSE IN developer-license-3.1.txt"} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141143
0
3118
+ Added@sap/cds-hana@1.5.0(transitive)
+ Added@sap/cds-sql@1.5.0(transitive)
+ Added@sap/cds-sqlite@1.5.0(transitive)
+ Addeduuid@3.3.2(transitive)
- Removed@sap/cds-hana@1.0.3(transitive)
- Removed@sap/cds-sql@1.0.3(transitive)
- Removed@sap/cds-sqlite@1.0.3(transitive)
- Removeduuid@3.2.1(transitive)
Updated@sap/cds-hana@1.5.0
Updated@sap/cds-sql@1.5.0
Updated@sap/cds-sqlite@1.5.0
Updateduuid@3.3.2