@sap/cds-sqlite
Advanced tools
Comparing version 1.11.1 to 1.17.1
@@ -9,2 +9,49 @@ # Changelog | ||
## Version 1.17.1 - 2019-09-18 | ||
### Changed | ||
- Updated version of @sap/cds-sql to 1.17.1 | ||
## Version 1.17.0 - 2019-09-09 | ||
### Added | ||
- Streaming into sqlite | ||
## Version 1.16.0 - 2019-08-21 | ||
### Changed | ||
- Signature of the Client's constructor | ||
## Version 1.15.0 - 2019-07-23 | ||
### Added | ||
- Support multi tenancy for file based database | ||
### Fixed | ||
- Streaming supports `null` values | ||
## Version 1.14.0 - 2019-07-09 | ||
### Added | ||
- Named binding parameters | ||
- Support files as db in tenant manager | ||
## Version 1.13.0 - 2019-06-24 | ||
### Changed | ||
- Updated version of @sap/cds-sql to 1.13.0 | ||
## Version 1.12.0 - 2019-05-24 | ||
### Changed | ||
- Updated version of @sap/cds-sql to 1.12.0 | ||
## Version 1.11.1 - 2019-05-16 | ||
@@ -11,0 +58,0 @@ |
@@ -7,3 +7,2 @@ const { Database } = require('sqlite3') | ||
BaseClient, | ||
errors: { IllegalFunctionArgumentError, InconsistentClientError }, | ||
builder: { sqlFactory }, | ||
@@ -36,6 +35,7 @@ expand: { createJoinCQNFromExpanded, hasExpand, rawToExpanded }, | ||
* | ||
* @param {Object} credentials - Connection details. | ||
* @param {string} credentials.database - Filename to the database or :memory; for in memory | ||
* @param {Object} options - Connection details. | ||
* @param {Object} options.credentials - Connection details. | ||
* @param {string} options.credentials.database - Filename to the database or :memory; for in memory | ||
*/ | ||
constructor (credentials) { | ||
constructor ({ credentials }) { | ||
super([ | ||
@@ -65,3 +65,3 @@ ['cds.Boolean', convertToBoolean], | ||
if (!this._credentials) { | ||
return reject(new IllegalFunctionArgumentError('options.credentials')) | ||
return reject(new Error('Cannot connect to database. No connection credentials provided.')) | ||
} | ||
@@ -132,7 +132,7 @@ | ||
if (this._toBeDestroyed) { | ||
return reject(new InconsistentClientError()) | ||
return reject(new Error('Client is in an inconsistent state')) | ||
} | ||
if (!Array.isArray(values)) { | ||
return reject(new IllegalFunctionArgumentError('values')) | ||
if (!Array.isArray(values) && (typeof query !== 'string' || typeof values !== 'object')) { | ||
return reject(new Error(`Cannot execute SQL statement. Invalid values provided: ${JSON.stringify(values)}`)) | ||
} | ||
@@ -184,3 +184,3 @@ | ||
if (!query.SELECT && (typeof query !== 'string' || !query.trim().startsWith('SELECT'))) { | ||
throw new IllegalFunctionArgumentError('query') | ||
throw new Error(`Cannot stream from HANA. Invalid query provided: ${JSON.stringify(query)}`) | ||
} | ||
@@ -194,10 +194,11 @@ | ||
const stream_ = new Readable() | ||
const val = Object.values(resultSet[0])[0] | ||
let val = Object.values(resultSet[0])[0] | ||
if (val === null) { | ||
return null | ||
} | ||
if (typeof val === 'number') { | ||
return | ||
val = val.toString() | ||
} | ||
const stream_ = new Readable() | ||
stream_.push(val) | ||
@@ -230,8 +231,10 @@ stream_.push(null) | ||
return this._executeSQL( | ||
sql, | ||
outValues, | ||
cqn.SELECT && cqn.SELECT.one, | ||
getPostProcessMapper(this._toService, this._csn, cqn) | ||
) | ||
return this._streamValues(cqn, outValues).then(() => { | ||
return this._executeSQL( | ||
sql, | ||
outValues, | ||
cqn.SELECT && cqn.SELECT.one, | ||
getPostProcessMapper(this._toService, this._csn, cqn) | ||
) | ||
}) | ||
} | ||
@@ -249,2 +252,7 @@ | ||
_executeSQL (sql, values, isOne, postMapper) { | ||
// support named binding parameters | ||
if (values && typeof values === 'object' && !Array.isArray(values)) { | ||
values = this._getValuesProxy(values) | ||
} | ||
if (this._isStatementType('select', sql)) { | ||
@@ -262,2 +270,22 @@ return this._executeSelect(sql, values, isOne, postMapper) | ||
_getValuesProxy (values) { | ||
return new Proxy(values, { | ||
getOwnPropertyDescriptor: (obj, prop) => { | ||
if (prop.length > 1 && prop.startsWith(':')) { | ||
return Object.getOwnPropertyDescriptor(obj, prop.slice(1)) | ||
} | ||
return Object.getOwnPropertyDescriptor(obj, prop) | ||
}, | ||
get: (obj, prop) => { | ||
if (prop.length > 1 && prop.startsWith(':')) { | ||
return obj[prop.slice(1)] | ||
} | ||
return obj[prop] | ||
}, | ||
ownKeys: target => { | ||
return Reflect.ownKeys(target).map(key => `:${key}`) | ||
} | ||
}) | ||
} | ||
_isStatementType (type, sql) { | ||
@@ -277,2 +305,4 @@ // Regex is faster than toLower + trim + startsWith | ||
if (result) Object.setPrototypeOf(result, Array.prototype) | ||
resolve(this._returnFirstResultIfOne(isOne, postProcess(result, postMapper))) | ||
@@ -371,2 +401,28 @@ }) | ||
_stream2Buffer (stream) { | ||
return new Promise(resolve => { | ||
const buffer = [] | ||
stream.on('data', chunk => { | ||
buffer.push(chunk) | ||
}) | ||
stream.on('end', () => { | ||
resolve(Buffer.concat(buffer)) | ||
}) | ||
stream.on('error', () => { | ||
stream.removeAllListeners('error') | ||
stream.push(null) | ||
}) | ||
}) | ||
} | ||
async _streamValues (cqn, values) { | ||
if (cqn.UPDATE || cqn.INSERT) { | ||
for (let i = 0; i < values.length; i++) { | ||
if (values[i] && typeof values[i].pipe === 'function') { | ||
values[i] = await this._stream2Buffer(values[i]) | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
@@ -373,0 +429,0 @@ * Prepare SQL statement. |
@@ -1,6 +0,8 @@ | ||
const { errors: { IllegalFunctionArgumentError } } = require('@sap/cds-sql') | ||
const _validateFails = option => { | ||
throw new Error(`Invalid database option: ${option}`) | ||
} | ||
const _validateDatabase = database => { | ||
if (!database) { | ||
throw new IllegalFunctionArgumentError('options.credentials.database') | ||
_validateFails('no "options.credentials.database" provided') | ||
} | ||
@@ -11,3 +13,3 @@ } | ||
if (options.pool.min > options.pool.max) { | ||
throw new IllegalFunctionArgumentError('options.pool.min') | ||
_validateFails('"options.pool.min" is bigger than "options.pool.max"') | ||
} | ||
@@ -17,11 +19,11 @@ | ||
if (options.pool.max !== 1) { | ||
throw new IllegalFunctionArgumentError('options.pool.max') | ||
_validateFails('"options.pool.max" in :memory: should equal 1') | ||
} | ||
if (options.pool.evictionRunIntervalMillis !== 0) { | ||
throw new IllegalFunctionArgumentError('options.pool.evictionRunIntervalMillis') | ||
_validateFails('"options.pool.evictionRunIntervalMillis" in :memory: should equal 0') | ||
} | ||
if (options.pool.idleTimeoutMillisForPools !== 0) { | ||
throw new IllegalFunctionArgumentError('options.pool.idleTimeoutMillisForPools') | ||
_validateFails('"options.pool.idleTimeoutMillisForPools" in :memory: should equal 0') | ||
} | ||
@@ -41,7 +43,7 @@ } | ||
* @param {number} [options.pool.idleTimeoutMillisForPools] - The time interval in ms until an idle pool is evicted. | ||
* @throws {IllegalFunctionArgumentError} | ||
* @throws Error if one of the options is invalid or missing | ||
*/ | ||
const options = options => { | ||
options.credentials = options.credentials || {} | ||
options.credentials.database = options.credentials.database || options.database || options.host || options.url | ||
options.credentials.database = options.credentials.database || options.database || options.host || options.url || options.credentials.url | ||
@@ -48,0 +50,0 @@ options.pool.min = options.pool.min || 1 |
@@ -22,2 +22,7 @@ const dependencies = { | ||
}, | ||
get TenantManager () { | ||
const TenantManager = require('./client/TenantManager') | ||
Object.defineProperty(dependencies, 'TenantManager', { value: TenantManager }) | ||
return TenantManager | ||
}, | ||
inject: (...args) => { | ||
@@ -24,0 +29,0 @@ return require('./cds').inject(...args) |
const { | ||
errors: { IllegalFunctionArgumentError }, | ||
thenable: { all, reject } | ||
@@ -42,3 +41,3 @@ } = require('@sap/cds-sql') | ||
return reject(new IllegalFunctionArgumentError('values')) | ||
return reject(new Error(`Cannot execute SQL statement. Invalid values provided: ${JSON.stringify(values)}`)) | ||
} | ||
@@ -45,0 +44,0 @@ |
{ | ||
"name": "@sap/cds-sqlite", | ||
"version": "1.11.1", | ||
"version": "1.17.1", | ||
"lockfileVersion": 1, | ||
@@ -8,5 +8,11 @@ "requires": true, | ||
"@sap/cds-sql": { | ||
"version": "1.11.1" | ||
"version": "1.17.1", | ||
"requires": { | ||
"uuid": "3.3.2" | ||
} | ||
}, | ||
"uuid": { | ||
"version": "3.3.2" | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-sql":"1.11.1"},"deprecated":false,"description":"Driver package for access to sqlite 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-sqlite","version":"1.11.1","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bundleDependencies":false,"dependencies":{"@sap/cds-sql":"1.17.1"},"deprecated":false,"description":"Driver package for access to sqlite 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-sqlite","version":"1.17.1","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
64091
21
998
+ Added@sap/cds-sql@1.17.1(transitive)
+ Addeduuid@3.3.2(transitive)
- Removed@sap/cds-sql@1.11.1(transitive)
Updated@sap/cds-sql@1.17.1