@sap/cds-hana
Advanced tools
Comparing version 0.9.0 to 1.5.0
@@ -9,2 +9,49 @@ # Changelog | ||
## Version 1.5.0 - 2019-02-06 | ||
### Changed | ||
- Minimum node version 8.9.0 | ||
- Improve expand performance | ||
## Version 1.4.0 - 2019-01-22 | ||
### Added | ||
- `validate_certificate` and `hostname_in_certificate` to override certificate validation in local development mode | ||
- `.execute` supports placeholders in CQN | ||
## Version 1.3.0 - 2019-01-11 | ||
### Changed | ||
- Use latest version of @sap/cds-sql | ||
## Version 1.2.0 - 2018-12-21 | ||
### Added | ||
- Set default values in case of CREATE, UPSERT and adding a child in deep documents | ||
## Version 1.1.0 - 2018-12-12 | ||
### Added | ||
- Support Deep Document CQNs | ||
## Version 1.0.3 - 2018-11-27 | ||
### Changed | ||
- Throw db error instead of wrapping it in Sql Error | ||
- Use options.credentials instead of options directly | ||
### Fixed | ||
- Post processing of Binary, Boolean and Integer64 | ||
## Version 0.10.0 - 2018-10-17 | ||
- Refactoring and changes due to updated dependencies | ||
## Version 0.9.0 - 2018-10-04 | ||
@@ -11,0 +58,0 @@ |
@@ -5,3 +5,3 @@ const _notInjected = () => { | ||
const _validateInjection = (cds) => { | ||
const _validateInjection = cds => { | ||
if (!cds || typeof cds !== 'object') { | ||
@@ -8,0 +8,0 @@ throw new Error('Injected value is not of type `cds`') |
@@ -1,5 +0,17 @@ | ||
const hdb = require('hdb') | ||
const hanaClient = require('./hanaClient') | ||
const registerReconnect = require('./registerReconnect') | ||
const CustomBuilder = require('../customBuilder/') | ||
const HdbStatement = require('../statement/HdbStatement') | ||
const cdsSql = require('@sap/cds-sql') | ||
const {BaseClient} = cdsSql | ||
const {convertToISO, convertToISONoMillis, convertErrorCodeToString, convertToString} = require('../util') | ||
const { BaseClient } = cdsSql | ||
const { | ||
convertToBoolean, | ||
convertInt64ToString, | ||
convertToISO, | ||
convertToISONoMillis, | ||
convertErrorCodeToString, | ||
convertToString | ||
} = require('../util') | ||
@@ -10,30 +22,23 @@ class Client extends BaseClient { | ||
* | ||
* @param {Object} connect | ||
* @param {string} connect.host - database host | ||
* @param {number} connect.port - database port | ||
* @param {string} connect.user - username for authentication | ||
* @param {string} connect.password - password for authentication | ||
* @param {string} [connect.schema] - default schema to be used | ||
* @param {string} [connect.ca] - database certificate as needed by hdb driver | ||
* @param {string} [connect.certificate] - database certificate as provided by instance manager | ||
* @param {Object} credentials | ||
* @param {string} credentials.host - database host | ||
* @param {number} credentials.port - database port | ||
* @param {string} credentials.user - username for authentication | ||
* @param {string} credentials.password - password for authentication | ||
* @param {string} [credentials.schema] - default schema to be used | ||
* @param {string} [credentials.ca] - database certificate as needed by hdb driver | ||
* | ||
*/ | ||
constructor (connect) { | ||
constructor (credentials) { | ||
super([ | ||
['cds.Boolean', Boolean], | ||
['cds.Integer64', String], | ||
['cds.Boolean', convertToBoolean], | ||
['cds.Integer64', convertInt64ToString], | ||
['cds.DateTime', convertToISONoMillis], | ||
['cds.Timestamp', convertToISO], | ||
// ['cds.Binary', convertToBuffer], | ||
// ['cds.LargeBinary', convertToBuffer], | ||
['cds.LargeString', convertToString] | ||
]) | ||
this._connect = connect | ||
this._credentials = credentials | ||
if (!this._connect.hasOwnProperty('ca') && this._connect.certificate) { | ||
this._connect.ca = this._connect.certificate | ||
} | ||
this._dbc = hdb.createClient(this._connect) | ||
this._dbc = hanaClient.createClient(this._credentials) | ||
this._user = 'ANONYMOUS' // Use anonymous HANA user as default | ||
@@ -44,11 +49,3 @@ // auto-commit is true by default | ||
this._dbc.on('close', () => { | ||
// try to re-connect | ||
if (this._isInUse) { | ||
this.connect() | ||
.catch(() => { | ||
this._isInUse = false | ||
}) | ||
} | ||
}) | ||
registerReconnect(this) | ||
} | ||
@@ -63,3 +60,3 @@ | ||
return new Promise((resolve, reject) => { | ||
this._dbc.connect((err) => { | ||
this._dbc.connect(err => { | ||
if (err) { | ||
@@ -69,4 +66,4 @@ return reject(convertErrorCodeToString(err)) | ||
if (this._connect.schema) { | ||
this.execute(`SET SCHEMA ${this._connect.schema}`) | ||
if (this._credentials.schema) { | ||
this.execute(`SET SCHEMA ${this._credentials.schema}`) | ||
.then(() => { | ||
@@ -76,3 +73,3 @@ this._isInUse = true | ||
}) | ||
.catch((err) => { | ||
.catch(err => { | ||
this._dbc.end() | ||
@@ -127,3 +124,3 @@ reject(convertErrorCodeToString(err)) | ||
* @param {string|object} query - SQL string or CQN object generated by the DML statements. | ||
* @param {Array} [values] - Values to be set in the SQL statement if query is provided as string. | ||
* @param {Array} [values] - Values to be set in the SQL statement if query is provided as string or as CQN object with placeholders. | ||
* @returns {Promise} Promise, that resolves with result object (array) if successful or rejects with error if not. | ||
@@ -154,11 +151,15 @@ * Result object can be undefined. | ||
const {sql, values = []} = cdsSql.builder.sqlFactory(query, { | ||
typeConversion: this._typeConversionMap, | ||
customBuilder: require('../customBuilder/'), | ||
user: this._user | ||
}, this._csn) | ||
if (cdsSql.composition.hasCompositionDelete(this._csn && this._csn.definitions, query)) { | ||
return this._processCascadeDelete(query) | ||
} | ||
const {postProcessing: {getPostProcessMapper, getPropertyMapper}} = cdsSql | ||
if (cdsSql.composition.hasDeepInsert(this._csn && this._csn.definitions, query)) { | ||
return this._processDeepInsert(query) | ||
} | ||
return this._executeSQL(sql, values, getPostProcessMapper(this._toService, this._csn, query), getPropertyMapper(this._csn, query, true)) | ||
if (cdsSql.composition.hasDeepUpdate(this._csn && this._csn.definitions, query)) { | ||
return this._processDeepUpdate(query) | ||
} | ||
return this._execute(query, values) | ||
} catch (err) { | ||
@@ -170,4 +171,31 @@ // in case an object is passed and sql builder throws an error | ||
_execute (query, inValues = []) { | ||
const query_ = this._addDefaultValues(query, false, true) | ||
const { sql, values = [] } = cdsSql.builder.sqlFactory( | ||
query_, | ||
{ | ||
typeConversion: this._typeConversionMap, | ||
customBuilder: CustomBuilder, | ||
user: this._user | ||
}, | ||
this._csn | ||
) | ||
const { postProcessing: { getPostProcessMapper, getPropertyMapper, getStructMapper } } = cdsSql | ||
const propertyMapper = getPropertyMapper(this._csn, query, true) | ||
const outValues = inValues.length > 0 ? inValues : values | ||
return this._executeSQL( | ||
sql, | ||
outValues, | ||
getPostProcessMapper(this._toService, this._csn, query), | ||
propertyMapper, | ||
getStructMapper(this._csn, query, propertyMapper) | ||
) | ||
} | ||
_processExpand (cqn) { | ||
const sqls = [] | ||
const queries = [] | ||
const expandQueries = cdsSql.expand.createJoinCQNFromExpanded(cqn, this._csn, true) | ||
@@ -178,10 +206,7 @@ | ||
const {sql, values} = cdsSql.builder.sqlFactory(cqn) | ||
sqls.push(this._executeExpand(sql, values)) | ||
const { sql, values } = cdsSql.builder.sqlFactory(cqn, undefined, this._csn) | ||
queries.push(this._executeExpand(sql, values)) | ||
} | ||
return Promise.all(sqls) | ||
.then((results) => { | ||
return cdsSql.expand.rawToExpanded(expandQueries, results) | ||
}) | ||
return cdsSql.expand.rawToExpanded(expandQueries, queries) | ||
} | ||
@@ -191,6 +216,5 @@ | ||
if (Array.isArray(values) && values.length !== 0) { | ||
return this.prepareStatement(sql) | ||
.then((statement) => { | ||
return statement.execute(values) | ||
}) | ||
return this.prepareStatement(sql).then(statement => { | ||
return statement.execute(values) | ||
}) | ||
} | ||
@@ -201,3 +225,5 @@ | ||
if (err) { | ||
return reject(new cdsSql.errors.SqlError(convertErrorCodeToString(err), sql, values)) | ||
convertErrorCodeToString(err) | ||
err.failedQuery = sql | ||
return reject(err) | ||
} | ||
@@ -210,12 +236,38 @@ | ||
_executeSQL (sql, values, postMapper, propertyMapper) { | ||
_processCascadeDelete (cqn) { | ||
return this.processNestedCQNs( | ||
cdsSql.composition.createCascadeDeleteCQNs(this._csn && this._csn.definitions, cqn), | ||
this._execute.bind(this) | ||
) | ||
} | ||
_processDeepInsert (cqn) { | ||
return this.processNestedCQNs( | ||
[cdsSql.composition.createDeepInsertCQNs(this._csn && this._csn.definitions, cqn)], | ||
this._execute.bind(this) | ||
) | ||
} | ||
_processDeepUpdate (cqn) { | ||
/* istanbul ignore next */ | ||
return cdsSql.composition | ||
.selectDeepUpdateData(this._csn && this._csn.definitions, cqn, this._execute.bind(this)) | ||
.then(selectData => { | ||
return this.processNestedCQNs( | ||
cdsSql.composition.createDeepUpdateCQNs(this._csn && this._csn.definitions, cqn, selectData), | ||
this._execute.bind(this) | ||
) | ||
}) | ||
} | ||
_executeSQL (sql, values, postMapper, propertyMapper, objStructMapper) { | ||
if (values.length !== 0) { | ||
return this.prepareStatement(sql) | ||
.then((statement) => { | ||
.then(statement => { | ||
return statement.execute(values) | ||
}) | ||
.then((result) => { | ||
return Promise.resolve(cdsSql.postProcessing.postProcess(result, postMapper, propertyMapper)) | ||
.then(result => { | ||
return Promise.resolve(cdsSql.postProcessing.postProcess(result, postMapper, propertyMapper, objStructMapper)) | ||
}) | ||
.catch((err) => { | ||
.catch(err => { | ||
return Promise.reject(err) | ||
@@ -228,6 +280,8 @@ }) | ||
if (err) { | ||
return reject(new cdsSql.errors.SqlError(convertErrorCodeToString(err), sql, values)) | ||
convertErrorCodeToString(err) | ||
err.failedQuery = sql | ||
return reject(err) | ||
} | ||
resolve(cdsSql.postProcessing.postProcess(result, postMapper, propertyMapper)) | ||
resolve(cdsSql.postProcessing.postProcess(result, postMapper, propertyMapper, objStructMapper)) | ||
}) | ||
@@ -247,5 +301,7 @@ }) | ||
if (err) { | ||
return reject(new cdsSql.errors.SqlError(convertErrorCodeToString(err), sql)) | ||
convertErrorCodeToString(err) | ||
err.failedQuery = sql | ||
return reject(err) | ||
} | ||
const HdbStatement = require('../statement/HdbStatement') | ||
resolve(new HdbStatement(statement, sql)) | ||
@@ -262,3 +318,3 @@ }) | ||
isConnected () { | ||
return this._dbc.readyState === 'connected' | ||
return this._dbc.readyState === 'connected' || (this._dbc.state && this._dbc.state() === 'connected') | ||
} | ||
@@ -275,4 +331,9 @@ | ||
this._locale = locale || 'en_US' | ||
// Works, but bad practise to access an internal scope | ||
this._dbc._connection.getClientInfo().setProperty('LOCALE', this._locale) | ||
if (this._dbc._connection) { | ||
// Works, but bad practise to access an internal scope | ||
this._dbc._connection.getClientInfo().setProperty('LOCALE', this._locale) | ||
} else { | ||
this._dbc.setClientInfo('LOCALE', this._locale) | ||
} | ||
} | ||
@@ -289,4 +350,9 @@ | ||
this._user = user || 'ANONYMOUS' // Use anonymous HANA user as fallback | ||
// Works, but bad practise to access an internal scope | ||
this._dbc._connection.getClientInfo().setProperty('XS_APPLICATIONUSER', this._user) | ||
if (this._dbc._connection) { | ||
// Works, but bad practise to access an internal scope | ||
this._dbc._connection.getClientInfo().setProperty('XS_APPLICATIONUSER', this._user) | ||
} else { | ||
this._dbc.setClientInfo('XS_APPLICATIONUSER', this._user) | ||
} | ||
} | ||
@@ -325,3 +391,3 @@ | ||
return new Promise((resolve, reject) => { | ||
this._dbc.commit((err) => { | ||
this._dbc.commit(err => { | ||
if (err) { | ||
@@ -351,3 +417,3 @@ return reject(convertErrorCodeToString(err)) | ||
return new Promise((resolve, reject) => { | ||
this._dbc.rollback((err) => { | ||
this._dbc.rollback(err => { | ||
if (err) { | ||
@@ -380,7 +446,9 @@ return reject(convertErrorCodeToString(err)) | ||
_addDropsToChain (chain, drop) { | ||
return chain.then(() => this.run(drop).catch((err) => { | ||
if (!this._ignoreError(err)) { | ||
throw err | ||
} | ||
})) | ||
return chain.then(() => | ||
this.run(drop).catch(err => { | ||
if (!this._ignoreError(err)) { | ||
throw err | ||
} | ||
}) | ||
) | ||
} | ||
@@ -390,3 +458,3 @@ | ||
// hana error code for table/view does not exist | ||
return err instanceof cdsSql.errors.SqlError && (err.rootCause.code === '259' || err.rootCause.code === '321') | ||
return err.code === '259' || err.code === '321' | ||
} | ||
@@ -393,0 +461,0 @@ } |
@@ -0,21 +1,65 @@ | ||
const _checkHanaClient = () => { | ||
try { | ||
require.resolve('@sap/hana-client') | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
const _getCertificateValidation = allowedHost => { | ||
if (allowedHost) { | ||
return host => { | ||
if (host !== allowedHost) { | ||
throw new Error( | ||
`The name on the security certificate '${allowedHost}' is invalid or does not match the name of the site '${host}'.` | ||
) | ||
} | ||
} | ||
} | ||
return () => {} | ||
} | ||
const _isHanaClient = _checkHanaClient() | ||
/** | ||
* Validates the connect and pool options and adds defaults if not given. | ||
* @param {Object} options - The db connection options. | ||
* @param {Object} options.database - The db name. | ||
* @param {Object} options.url - The db url. | ||
* @param {string} [options.host] - Address to the db | ||
* @param {string} [options.port] - Port for db | ||
* @param {string} [options.user] - Username for authentication | ||
* @param {string} [options.password] - Password for authentication | ||
* @param {Object} [pool] - The min and max pool options. | ||
* @param {number} [pool.min] - The minimum number of db connection clients. | ||
* @param {number} [pool.max] - The maximum number of db connection clients. | ||
* @param {Object} options.credentials - The credentials. | ||
* @param {Object} [options.pool] - The min and max pool options. | ||
* @param {number} [options.pool.min] - The minimum number of db connection clients. | ||
* @param {number} [options.pool.max] - The maximum number of db connection clients. | ||
*/ | ||
const options = (options) => { | ||
// TODO: Clarify what should be done with respect to .database and .url. Shall it be parsed here or will it be parsed in ql so we can ignore it here? | ||
// options.host = options.host || options.database || options.url | ||
const options = options => { | ||
options.pool.min = options.pool.min || 1 | ||
options.pool.max = options.pool.max || 100 | ||
options.pool.idleTimeoutMillisForPools = options.pool.idleTimeoutMillisForPools || 60000 | ||
options.pool.evictionRunIntervalMillis = options.pool.evictionRunIntervalMillis || 10000 | ||
if (!options.credentials) { | ||
return | ||
} | ||
if (!('ca' in options.credentials) && options.credentials.certificate) { | ||
options.credentials.ca = options.credentials.certificate | ||
} | ||
if ('encrypt' in options.credentials && !('useTLS' in options.credentials)) { | ||
options.credentials.useTLS = options.credentials.encrypt | ||
} | ||
if ('hostname_in_certificate' in options.credentials && !('sslHostNameInCertificate' in options.credentials)) { | ||
options.credentials.sslHostNameInCertificate = options.credentials.hostname_in_certificate | ||
} | ||
if ('validate_certificate' in options.credentials && !('sslValidateCertificate' in options.credentials)) { | ||
options.credentials.sslValidateCertificate = options.credentials.validate_certificate | ||
} | ||
if (!_isHanaClient && options.credentials.sslValidateCertificate === false) { | ||
options.credentials.checkServerIdentity = _getCertificateValidation(options.credentials.sslHostNameInCertificate) | ||
} | ||
} | ||
module.exports = options |
@@ -6,3 +6,3 @@ const CreateBuilder = require('@sap/cds-sql').builder.CreateBuilder | ||
const SelectBuilder = require('./CustomSelectBuilder') | ||
Object.defineProperty(this, 'SelectBuilder', {value: SelectBuilder}) | ||
Object.defineProperty(this, 'SelectBuilder', { value: SelectBuilder }) | ||
return SelectBuilder | ||
@@ -9,0 +9,0 @@ } |
@@ -6,3 +6,3 @@ const DeleteBuilder = require('@sap/cds-sql').builder.DeleteBuilder | ||
const ExpressionBuilder = require('./CustomExpressionBuilder') | ||
Object.defineProperty(this, 'ExpressionBuilder', {value: ExpressionBuilder}) | ||
Object.defineProperty(this, 'ExpressionBuilder', { value: ExpressionBuilder }) | ||
return ExpressionBuilder | ||
@@ -9,0 +9,0 @@ } |
@@ -6,3 +6,3 @@ const ExpressionBuilder = require('@sap/cds-sql').builder.ExpressionBuilder | ||
const SelectBuilder = require('./CustomSelectBuilder') | ||
Object.defineProperty(this, 'SelectBuilder', {value: SelectBuilder}) | ||
Object.defineProperty(this, 'SelectBuilder', { value: SelectBuilder }) | ||
return SelectBuilder | ||
@@ -13,3 +13,3 @@ } | ||
const ReferenceBuilder = require('./CustomReferenceBuilder') | ||
Object.defineProperty(this, 'ReferenceBuilder', {value: ReferenceBuilder}) | ||
Object.defineProperty(this, 'ReferenceBuilder', { value: ReferenceBuilder }) | ||
return ReferenceBuilder | ||
@@ -16,0 +16,0 @@ } |
@@ -6,3 +6,3 @@ const ReferenceBuilder = require('@sap/cds-sql').builder.ReferenceBuilder | ||
const SelectBuilder = require('./CustomSelectBuilder') | ||
Object.defineProperty(this, 'SelectBuilder', {value: SelectBuilder}) | ||
Object.defineProperty(this, 'SelectBuilder', { value: SelectBuilder }) | ||
return SelectBuilder | ||
@@ -14,3 +14,9 @@ } | ||
const columnsString = `(${this._columnsFromContains(this._obj.ref[1].args).join(', ')})` | ||
this._outputObj.sql.push(`${contains ? '' : 'NOT '}CONTAINS(`, `${columnsString},`, `${this._options.placeholder},`, 'FUZZY(0.9)', ')') | ||
this._outputObj.sql.push( | ||
`${contains ? '' : 'NOT '}CONTAINS(`, | ||
`${columnsString},`, | ||
`${this._options.placeholder},`, | ||
'FUZZY(0.9)', | ||
')' | ||
) | ||
@@ -27,3 +33,4 @@ const params = this._obj.ref[1].args.slice(1) | ||
searchTerm = `${searchTerm} OR ` | ||
} else { // param === 'not' | ||
} else { | ||
// param === 'not' | ||
searchTerm = `${searchTerm}-` | ||
@@ -30,0 +37,0 @@ } |
@@ -6,3 +6,3 @@ const SelectBuilder = require('@sap/cds-sql').builder.SelectBuilder | ||
const ExpressionBuilder = require('./CustomExpressionBuilder') | ||
Object.defineProperty(this, 'ExpressionBuilder', {value: ExpressionBuilder}) | ||
Object.defineProperty(this, 'ExpressionBuilder', { value: ExpressionBuilder }) | ||
return ExpressionBuilder | ||
@@ -13,7 +13,15 @@ } | ||
const ReferenceBuilder = require('./CustomReferenceBuilder') | ||
Object.defineProperty(this, 'ReferenceBuilder', {value: ReferenceBuilder}) | ||
Object.defineProperty(this, 'ReferenceBuilder', { value: ReferenceBuilder }) | ||
return ReferenceBuilder | ||
} | ||
_val (obj) { | ||
if (typeof obj.val === 'boolean') { | ||
return obj.val ? 'true' : 'false' | ||
} | ||
return obj.val | ||
} | ||
} | ||
module.exports = CustomSelectBuilder |
@@ -6,3 +6,3 @@ const UpdateBuilder = require('@sap/cds-sql').builder.UpdateBuilder | ||
const ExpressionBuilder = require('./CustomExpressionBuilder') | ||
Object.defineProperty(this, 'ExpressionBuilder', {value: ExpressionBuilder}) | ||
Object.defineProperty(this, 'ExpressionBuilder', { value: ExpressionBuilder }) | ||
return ExpressionBuilder | ||
@@ -13,3 +13,3 @@ } | ||
const ReferenceBuilder = require('./CustomReferenceBuilder') | ||
Object.defineProperty(this, 'ReferenceBuilder', {value: ReferenceBuilder}) | ||
Object.defineProperty(this, 'ReferenceBuilder', { value: ReferenceBuilder }) | ||
return ReferenceBuilder | ||
@@ -16,0 +16,0 @@ } |
const dependencies = { | ||
get CreateBuilder () { | ||
const CustomCreateBuilder = require('./CustomCreateBuilder') | ||
Object.defineProperty(dependencies, 'CreateBuilder', {value: CustomCreateBuilder}) | ||
Object.defineProperty(dependencies, 'CreateBuilder', { value: CustomCreateBuilder }) | ||
return CustomCreateBuilder | ||
@@ -9,3 +9,3 @@ }, | ||
const CustomDeleteBuilder = require('./CustomDeleteBuilder') | ||
Object.defineProperty(dependencies, 'DeleteBuilder', {value: CustomDeleteBuilder}) | ||
Object.defineProperty(dependencies, 'DeleteBuilder', { value: CustomDeleteBuilder }) | ||
return CustomDeleteBuilder | ||
@@ -15,3 +15,3 @@ }, | ||
const CustomDropBuilder = require('./CustomDropBuilder') | ||
Object.defineProperty(dependencies, 'DropBuilder', {value: CustomDropBuilder}) | ||
Object.defineProperty(dependencies, 'DropBuilder', { value: CustomDropBuilder }) | ||
return CustomDropBuilder | ||
@@ -21,3 +21,3 @@ }, | ||
const CustomSelectBuilder = require('./CustomSelectBuilder') | ||
Object.defineProperty(dependencies, 'SelectBuilder', {value: CustomSelectBuilder}) | ||
Object.defineProperty(dependencies, 'SelectBuilder', { value: CustomSelectBuilder }) | ||
return CustomSelectBuilder | ||
@@ -27,3 +27,3 @@ }, | ||
const CustomUpdateBuilder = require('./CustomUpdateBuilder') | ||
Object.defineProperty(dependencies, 'UpdateBuilder', {value: CustomUpdateBuilder}) | ||
Object.defineProperty(dependencies, 'UpdateBuilder', { value: CustomUpdateBuilder }) | ||
return CustomUpdateBuilder | ||
@@ -30,0 +30,0 @@ } |
const dependencies = { | ||
get Client () { | ||
const Client = require('./client/Client') | ||
Object.defineProperty(dependencies, 'Client', {value: Client}) | ||
Object.defineProperty(dependencies, 'Client', { value: Client }) | ||
return Client | ||
@@ -9,3 +9,3 @@ }, | ||
const options = require('./client/options') | ||
Object.defineProperty(dependencies, 'options', {value: options}) | ||
Object.defineProperty(dependencies, 'options', { value: options }) | ||
return options | ||
@@ -12,0 +12,0 @@ }, |
@@ -0,1 +1,3 @@ | ||
const { convertErrorCodeToString } = require('../util') | ||
class HdbStatement { | ||
@@ -37,6 +39,6 @@ /** | ||
if (err) { | ||
const {errors: {SqlError}} = require('@sap/cds-sql') | ||
const {convertErrorCodeToString} = require('../util') | ||
convertErrorCodeToString(err) | ||
err.failedQuery = this._sql | ||
return reject(new SqlError(convertErrorCodeToString(err), this._sql, values)) | ||
return reject(err) | ||
} | ||
@@ -43,0 +45,0 @@ |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
const convertErrorCodeToString = (err) => { | ||
const convertErrorCodeToString = err => { | ||
if (typeof err.code === 'number') { | ||
@@ -16,9 +16,29 @@ err.code = err.code.toString() | ||
const convertToISO = (element) => { | ||
return new Date(element).toISOString() | ||
const convertToBoolean = boolean => { | ||
if (boolean === null) { | ||
return null | ||
} | ||
return Boolean(boolean) | ||
} | ||
const convertToISONoMillis = (element) => { | ||
const convertInt64ToString = int64 => { | ||
if (int64 === null) { | ||
return null | ||
} | ||
return String(int64) | ||
} | ||
const convertToISO = element => { | ||
if (element) { | ||
const dateTime = new Date(element).toISOString() | ||
return new Date(element + 'Z').toISOString() | ||
} | ||
return null | ||
} | ||
const convertToISONoMillis = element => { | ||
if (element) { | ||
const dateTime = new Date(element + 'Z').toISOString() | ||
return dateTime.slice(0, 19) + dateTime.slice(23) | ||
@@ -30,8 +50,13 @@ } | ||
// const convertToBuffer = (element) => { return Buffer.from(element) } | ||
const convertToString = (element) => { | ||
return Buffer.from(element, 'base64').toString() | ||
const convertToString = element => { | ||
if (element) { | ||
return element instanceof Buffer ? Buffer.from(element, 'base64').toString() : element | ||
} | ||
return null | ||
} | ||
module.exports = { | ||
convertToBoolean, | ||
convertInt64ToString, | ||
convertToISO, | ||
@@ -38,0 +63,0 @@ convertToISONoMillis, |
{ | ||
"name": "@sap/cds-hana", | ||
"version": "0.9.0", | ||
"version": "1.5.0", | ||
"lockfileVersion": 1, | ||
"requires": true, | ||
"dependencies": { | ||
"@sap/cds-sql": { | ||
"version": "0.11.0" | ||
"version": "1.5.0" | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-sql":"0.11.0"},"deprecated":false,"description":"Driver package for access to hana database, including setting up the client, configuring all the necessary options to initiate the connection and handling database specifics so that they can be processed on our end.","devDependencies":{"@sap/cds":"git://github.wdf.sap.corp/cdx/cds","hdb":"^0.16.0","jest":"^23.4.0","jest-junit":"^5.1.0","jsdoc-to-markdown":"^4.0.0","standard":"^11.0.0","standard-reporter":"^1.0.0"},"engines":{"node":">= 6.11.0"},"jest":{"testEnvironment":"node"},"jest-junit":{"suiteName":"jest tests","output":"reports/sonar/test-reporter.xml","classNameTemplate":"{classname}-{title}","titleTemplate":"{classname}-{title}","ancestorSeparator":" › ","usePathForSuiteName":"true"},"main":"lib/index.js","name":"@sap/cds-hana","scripts":{"build":"npm run test && npm run jsdoc2md","clean":"rm -rf reports && rm -f npm-debug.log","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","test":"npm run clean && npm run lint && npm run test-unit","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":"0.9.0","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-sql":"1.5.0"},"deprecated":false,"description":"Driver package for access to hana database, including setting up the client, configuring all the necessary options to initiate the connection and handling database specifics so that they can be processed on our end.","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-hana","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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
53058
0
23
768
1
2
+ Added@sap/cds-sql@1.5.0(transitive)
- Removed@sap/cds-sql@0.11.0(transitive)
Updated@sap/cds-sql@1.5.0