diff --git a/README.md b/README.md index f2b3f9825..bbb19ca3c 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ var rxSession = driver.rxSession({ }) ``` -### Executing Statements +### Executing Queries #### Consuming Records with Streaming API diff --git a/examples/node.js b/examples/node.js index a9611f8c2..685e423fd 100644 --- a/examples/node.js +++ b/examples/node.js @@ -19,7 +19,7 @@ var neo4j = require('neo4j') -var statement = [ +var query = [ 'MERGE (alice:Person {name:{name_a},age:{age_a}})', 'MERGE (bob:Person {name:{name_b},age:{age_b}})', 'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)', @@ -36,7 +36,7 @@ var params = { var driver = neo4j.driver('bolt://localhost') var streamSession = driver.session() -var streamResult = streamSession.run(statement.join(' '), params) +var streamResult = streamSession.run(query.join(' '), params) streamResult.subscribe({ onNext: function (record) { // On receipt of RECORD @@ -58,7 +58,7 @@ streamResult.subscribe({ }) var promiseSession = driver.session() -var promiseResult = promiseSession.run(statement.join(' '), params) +var promiseResult = promiseSession.run(query.join(' '), params) promiseResult .then(function (records) { records.forEach(function (record) { diff --git a/src/driver.js b/src/driver.js index 065a9e450..d53172506 100644 --- a/src/driver.js +++ b/src/driver.js @@ -58,7 +58,7 @@ let idGenerator = 0 /** * A driver maintains one or more {@link Session}s with a remote - * Neo4j instance. Through the {@link Session}s you can send statements + * Neo4j instance. Through the {@link Session}s you can send queries * and retrieve results from the database. * * Drivers are reasonably expensive to create - you should strive to keep one diff --git a/src/internal/bolt-protocol-v1.js b/src/internal/bolt-protocol-v1.js index 14228e4ed..2f6c60ae2 100644 --- a/src/internal/bolt-protocol-v1.js +++ b/src/internal/bolt-protocol-v1.js @@ -217,9 +217,9 @@ export default class BoltProtocol { } /** - * Send a Cypher statement through the underlying connection. - * @param {string} statement the cypher statement. - * @param {Object} parameters the statement parameters. + * Send a Cypher query through the underlying connection. + * @param {string} query the cypher query. + * @param {Object} parameters the query parameters. * @param {Object} param * @param {Bookmark} param.bookmark the bookmark. * @param {TxConfig} param.txConfig the transaction configuration. @@ -235,7 +235,7 @@ export default class BoltProtocol { * @returns {StreamObserver} the stream observer that monitors the corresponding server response. */ run ( - statement, + query, parameters, { bookmark, @@ -267,7 +267,7 @@ export default class BoltProtocol { assertDatabaseIsEmpty(database, this._connection, observer) this._connection.write( - RequestMessage.run(statement, parameters), + RequestMessage.run(query, parameters), observer, false ) diff --git a/src/internal/bolt-protocol-v3.js b/src/internal/bolt-protocol-v3.js index 34581dd62..4184ed7a8 100644 --- a/src/internal/bolt-protocol-v3.js +++ b/src/internal/bolt-protocol-v3.js @@ -141,7 +141,7 @@ export default class BoltProtocol extends BoltProtocolV2 { } run ( - statement, + query, parameters, { bookmark, @@ -171,7 +171,7 @@ export default class BoltProtocol extends BoltProtocolV2 { assertDatabaseIsEmpty(database, this._connection, observer) this._connection.write( - RequestMessage.runWithMetadata(statement, parameters, { + RequestMessage.runWithMetadata(query, parameters, { bookmark, txConfig, mode diff --git a/src/internal/bolt-protocol-v4.js b/src/internal/bolt-protocol-v4.js index 046e24173..ecdd6e93b 100644 --- a/src/internal/bolt-protocol-v4.js +++ b/src/internal/bolt-protocol-v4.js @@ -55,7 +55,7 @@ export default class BoltProtocol extends BoltProtocolV3 { } run ( - statement, + query, parameters, { bookmark, @@ -89,7 +89,7 @@ export default class BoltProtocol extends BoltProtocolV3 { const flushRun = reactive this._connection.write( - RequestMessage.runWithMetadata(statement, parameters, { + RequestMessage.runWithMetadata(query, parameters, { bookmark, txConfig, database, diff --git a/src/internal/request-message.js b/src/internal/request-message.js index e5463cc6b..5a87f7a49 100644 --- a/src/internal/request-message.js +++ b/src/internal/request-message.js @@ -26,7 +26,7 @@ import { assertString } from './util' const INIT = 0x01 // 0000 0001 // INIT const ACK_FAILURE = 0x0e // 0000 1110 // ACK_FAILURE - unused const RESET = 0x0f // 0000 1111 // RESET -const RUN = 0x10 // 0001 0000 // RUN +const RUN = 0x10 // 0001 0000 // RUN const DISCARD_ALL = 0x2f // 0010 1111 // DISCARD_ALL - unused const PULL_ALL = 0x3f // 0011 1111 // PULL_ALL @@ -68,15 +68,15 @@ export default class RequestMessage { /** * Create a new RUN message. - * @param {string} statement the cypher statement. - * @param {Object} parameters the statement parameters. + * @param {string} query the cypher query. + * @param {Object} parameters the query parameters. * @return {RequestMessage} new RUN message. */ - static run (statement, parameters) { + static run (query, parameters) { return new RequestMessage( RUN, - [statement, parameters], - () => `RUN ${statement} ${JSON.stringify(parameters)}` + [query, parameters], + () => `RUN ${query} ${JSON.stringify(parameters)}` ) } @@ -146,8 +146,8 @@ export default class RequestMessage { /** * Create a new RUN message with additional metadata. - * @param {string} statement the cypher statement. - * @param {Object} parameters the statement parameters. + * @param {string} query the cypher query. + * @param {Object} parameters the query parameters. * @param {Bookmark} bookmark the bookmark. * @param {TxConfig} txConfig the configuration. * @param {string} database the database name. @@ -155,18 +155,16 @@ export default class RequestMessage { * @return {RequestMessage} new RUN message with additional metadata. */ static runWithMetadata ( - statement, + query, parameters, { bookmark, txConfig, database, mode } = {} ) { const metadata = buildTxMetadata(bookmark, txConfig, database, mode) return new RequestMessage( RUN, - [statement, parameters, metadata], + [query, parameters, metadata], () => - `RUN ${statement} ${JSON.stringify(parameters)} ${JSON.stringify( - metadata - )}` + `RUN ${query} ${JSON.stringify(parameters)} ${JSON.stringify(metadata)}` ) } @@ -239,7 +237,7 @@ function buildTxMetadata (bookmark, txConfig, database, mode) { /** * Create an object that represents streaming metadata. - * @param {Integer|number} stmtId The statement id to stream its results. + * @param {Integer|number} stmtId The query id to stream its results. * @param {Integer|number} n The number of records to stream. * @returns {Object} a metadata object. */ diff --git a/src/internal/stream-observers.js b/src/internal/stream-observers.js index 5107edcae..a3eceb807 100644 --- a/src/internal/stream-observers.js +++ b/src/internal/stream-observers.js @@ -92,7 +92,7 @@ class ResultStreamObserver extends StreamObserver { this._beforeComplete = beforeComplete this._afterComplete = afterComplete - this._statementId = null + this._queryId = null this._moreFunction = moreFunction this._discardFunction = discardFunction this._discard = false @@ -140,7 +140,7 @@ class ResultStreamObserver extends StreamObserver { // Extract server generated query id for use in requestMore and discard // functions if (meta.qid) { - this._statementId = meta.qid + this._queryId = meta.qid // remove qid from metadata object delete meta.qid @@ -236,11 +236,11 @@ class ResultStreamObserver extends StreamObserver { this._streaming = true if (this._discard) { - this._discardFunction(this._connection, this._statementId, this) + this._discardFunction(this._connection, this._queryId, this) } else { this._moreFunction( this._connection, - this._statementId, + this._queryId, this._fetchSize, this ) @@ -261,7 +261,7 @@ class ResultStreamObserver extends StreamObserver { /** * Stream observer defaults to handling responses for two messages: RUN + PULL_ALL or RUN + DISCARD_ALL. - * Response for RUN initializes statement keys. Response for PULL_ALL / DISCARD_ALL exposes the result stream. + * Response for RUN initializes query keys. Response for PULL_ALL / DISCARD_ALL exposes the result stream. * * However, some operations can be represented as a single message which receives full metadata in a single response. * For example, operations to begin, commit and rollback an explicit transaction use two messages in Bolt V1 but a single message in Bolt V3. diff --git a/src/internal/util.js b/src/internal/util.js index a55cb7d2a..0c924d858 100644 --- a/src/internal/util.js +++ b/src/internal/util.js @@ -31,7 +31,7 @@ function isEmptyObjectOrNull (obj) { return false } - for (let prop in obj) { + for (const prop in obj) { if (obj.hasOwnProperty(prop)) { return false } @@ -45,25 +45,25 @@ function isObject (obj) { } /** - * Check and normalize given statement and parameters. - * @param {string|{text: string, parameters: object}} statement the statement to check. + * Check and normalize given query and parameters. + * @param {string|{text: string, parameters: object}} query the query to check. * @param {Object} parameters * @return {{query: string, params: object}} the normalized query with parameters. * @throws TypeError when either given query or parameters are invalid. */ -function validateStatementAndParameters (statement, parameters) { - let query = statement +function validateQueryAndParameters (query, parameters) { + let validatedQuery = query let params = parameters || {} - if (typeof statement === 'object' && statement.text) { - query = statement.text - params = statement.parameters || {} + if (typeof query === 'object' && query.text) { + validatedQuery = query.text + params = query.parameters || {} } - assertCypherStatement(query) + assertCypherQuery(validatedQuery) assertQueryParameters(params) - return { query, params } + return { validatedQuery, params } } function assertObject (obj, objName) { @@ -122,12 +122,10 @@ function assertValidDate (obj, objName) { return obj } -function assertCypherStatement (obj) { - assertString(obj, 'Cypher statement') +function assertCypherQuery (obj) { + assertString(obj, 'Cypher query') if (obj.trim().length === 0) { - throw new TypeError( - 'Cypher statement is expected to be a non-empty string.' - ) + throw new TypeError('Cypher query is expected to be a non-empty string.') } } @@ -154,7 +152,7 @@ export { assertNumber, assertNumberOrInteger, assertValidDate, - validateStatementAndParameters, + validateQueryAndParameters, ENCRYPTION_ON, ENCRYPTION_OFF } diff --git a/src/record.js b/src/record.js index 88e03b6a3..c8857ba49 100644 --- a/src/record.js +++ b/src/record.js @@ -29,13 +29,13 @@ function generateFieldLookup (keys) { /** * Records make up the contents of the {@link Result}, and is how you access - * the output of a statement. A simple statement might yield a result stream + * the output of a query. A simple query might yield a result stream * with a single record, for instance: * * MATCH (u:User) RETURN u.name, u.age * * This returns a stream of records with two fields, named `u.name` and `u.age`, - * each record represents one user found by the statement above. You can access + * each record represents one user found by the query above. You can access * the values of each field either by name: * * record.get("u.name") @@ -147,7 +147,7 @@ class Record { "This record has no field with index '" + index + "'. Remember that indexes start at `0`, " + - 'and make sure your statement returns records in the shape you meant it to.' + 'and make sure your query returns records in the shape you meant it to.' ) } diff --git a/src/result-rx.js b/src/result-rx.js index df5989b85..79571c1b0 100644 --- a/src/result-rx.js +++ b/src/result-rx.js @@ -56,9 +56,9 @@ export default class RxResult { /** * Returns an observable that exposes a single item containing field names - * returned by the executing statement. + * returned by the executing query. * - * Errors raised by actual statement execution can surface on the returned + * Errors raised by actual query execution can surface on the returned * observable stream. * * @public @@ -69,7 +69,7 @@ export default class RxResult { } /** - * Returns an observable that exposes each record returned by the executing statement. + * Returns an observable that exposes each record returned by the executing query. * * Errors raised during the streaming phase can surface on the returned observable stream. * @@ -89,7 +89,7 @@ export default class RxResult { /** * Returns an observable that exposes a single item of {@link ResultSummary} that is generated by - * the server after the streaming of the executing statement is completed. + * the server after the streaming of the executing query is completed. * * *Subscribing to this stream before subscribing to records() stream causes the results to be discarded on the server.* * diff --git a/src/result-summary.js b/src/result-summary.js index 9573db53f..05d0d5d46 100644 --- a/src/result-summary.js +++ b/src/result-summary.js @@ -26,39 +26,39 @@ import { isInt } from './integer' class ResultSummary { /** * @constructor - * @param {string} statement - The statement this summary is for - * @param {Object} parameters - Parameters for the statement - * @param {Object} metadata - Statement metadata + * @param {string} query - The query this summary is for + * @param {Object} parameters - Parameters for the query + * @param {Object} metadata - Query metadata */ - constructor (statement, parameters, metadata) { + constructor (query, parameters, metadata) { /** - * The statement and parameters this summary is for. + * The query and parameters this summary is for. * @type {{text: string, parameters: Object}} * @public */ - this.statement = { text: statement, parameters } + this.query = { text: query, parameters } /** - * The type of statement executed. Can be "r" for read-only statement, "rw" for read-write statement, - * "w" for write-only statement and "s" for schema-write statement. - * String constants are available in {@link statementType} object. + * The type of query executed. Can be "r" for read-only query, "rw" for read-write query, + * "w" for write-only query and "s" for schema-write query. + * String constants are available in {@link queryType} object. * @type {string} * @public */ - this.statementType = metadata.type + this.queryType = metadata.type /** - * Counters for operations the statement triggered. - * @type {StatementStatistics} + * Counters for operations the query triggered. + * @type {QueryStatistics} * @public */ - this.counters = new StatementStatistics(metadata.stats || {}) + this.counters = new QueryStatistics(metadata.stats || {}) // for backwards compatibility, remove in future version this.updateStatistics = this.counters /** - * This describes how the database will execute the statement. - * Statement plan for the executed statement if available, otherwise undefined. + * This describes how the database will execute the query. + * Query plan for the executed query if available, otherwise undefined. * Will only be populated for queries that start with "EXPLAIN". * @type {Plan} */ @@ -68,8 +68,8 @@ class ResultSummary { : false /** - * This describes how the database did execute your statement. This will contain detailed information about what - * each step of the plan did. Profiled statement plan for the executed statement if available, otherwise undefined. + * This describes how the database did execute your query. This will contain detailed information about what + * each step of the plan did. Profiled query plan for the executed query if available, otherwise undefined. * Will only be populated for queries that start with "PROFILE". * @type {ProfiledPlan} * @public @@ -77,9 +77,9 @@ class ResultSummary { this.profile = metadata.profile ? new ProfiledPlan(metadata.profile) : false /** - * An array of notifications that might arise when executing the statement. Notifications can be warnings about - * problematic statements or other valuable information that can be presented in a client. Unlike failures - * or errors, notifications do not affect the execution of a statement. + * An array of notifications that might arise when executing the query. Notifications can be warnings about + * problematic queries or other valuable information that can be presented in a client. Unlike failures + * or errors, notifications do not affect the execution of a query. * @type {Array} * @public */ @@ -198,7 +198,7 @@ class ProfiledPlan { * Get statistical information for a {@link Result}. * @access public */ -class StatementStatistics { +class QueryStatistics { /** * Structurize the statistics * @constructor @@ -245,7 +245,7 @@ class StatementStatistics { } /** - * Returns the statement statistics updates in a dictionary. + * Returns the query statistics updates in a dictionary. * @returns {*} */ updates () { @@ -329,13 +329,13 @@ function valueOrDefault (key, values, defaultValue = 0) { } } -const statementType = { +const queryType = { READ_ONLY: 'r', READ_WRITE: 'rw', WRITE_ONLY: 'w', SCHEMA_WRITE: 's' } -export { statementType } +export { queryType } export default ResultSummary diff --git a/src/result.js b/src/result.js index 6777f04cc..be9abb19a 100644 --- a/src/result.js +++ b/src/result.js @@ -28,7 +28,7 @@ const DEFAULT_ON_COMPLETED = summary => {} const DEFAULT_METADATA_SUPPLIER = metadata => {} /** - * A stream of {@link Record} representing the result of a statement. + * A stream of {@link Record} representing the result of a query. * Can be consumed eagerly as {@link Promise} resolved with array of records and {@link ResultSummary} * summary, or rejected with error that contains {@link string} code and {@link string} message. * Alternatively can be consumed lazily using {@link Result#subscribe} function. @@ -40,15 +40,15 @@ class Result { * @constructor * @access private * @param {Promise} streamObserverPromise - * @param {mixed} statement - Cypher statement to execute - * @param {Object} parameters - Map with parameters to use in statement + * @param {mixed} query - Cypher query to execute + * @param {Object} parameters - Map with parameters to use in query * @param {ConnectionHolder} connectionHolder - to be notified when result is either fully consumed or error happened. */ - constructor (streamObserverPromise, statement, parameters, connectionHolder) { + constructor (streamObserverPromise, query, parameters, connectionHolder) { this._stack = captureStacktrace() this._streamObserverPromise = streamObserverPromise this._p = null - this._statement = statement + this._query = query this._parameters = parameters || {} this._connectionHolder = connectionHolder || EMPTY_CONNECTION_HOLDER } @@ -167,7 +167,7 @@ class Result { this._connectionHolder.releaseConnection().then(() => { onCompletedOriginal.call( observer, - new ResultSummary(this._statement, this._parameters, metadata) + new ResultSummary(this._query, this._parameters, metadata) ) }) } diff --git a/src/session-rx.js b/src/session-rx.js index b1279ad19..e2a8dbc4c 100644 --- a/src/session-rx.js +++ b/src/session-rx.js @@ -42,22 +42,20 @@ export default class RxSession { } /** - * Creates a reactive result that will execute the statement with the provided parameters and the provided + * Creates a reactive result that will execute the query with the provided parameters and the provided * transaction configuration that applies to the underlying auto-commit transaction. * * @public - * @param {string} statement - Statement to be executed. - * @param {Object} parameters - Parameter values to use in statement execution. + * @param {string} query - Query to be executed. + * @param {Object} parameters - Parameter values to use in query execution. * @param {TransactionConfig} transactionConfig - Configuration for the new auto-commit transaction. * @returns {RxResult} - A reactive result */ - run (statement, parameters, transactionConfig) { + run (query, parameters, transactionConfig) { return new RxResult( new Observable(observer => { try { - observer.next( - this._session.run(statement, parameters, transactionConfig) - ) + observer.next(this._session.run(query, parameters, transactionConfig)) observer.complete() } catch (err) { observer.error(err) @@ -121,7 +119,7 @@ export default class RxSession { } /** - * Returns the bookmark received following the last successfully completed statement, which is executed + * Returns the bookmark received following the last successfully completed query, which is executed * either in an {@link RxTransaction} obtained from this session instance or directly through one of * the {@link RxSession#run} method of this session instance. * diff --git a/src/session.js b/src/session.js index 22ec8ef51..e4f0f4043 100644 --- a/src/session.js +++ b/src/session.js @@ -23,7 +23,7 @@ import { import Result from './result' import Transaction from './transaction' import { newError } from './error' -import { validateStatementAndParameters } from './internal/util' +import { validateQueryAndParameters } from './internal/util' import ConnectionHolder from './internal/connection-holder' import Driver from './driver' import { ACCESS_MODE_READ, ACCESS_MODE_WRITE } from './internal/constants' @@ -33,7 +33,7 @@ import TxConfig from './internal/tx-config' /** * A Session instance is used for handling the connection and - * sending statements through the connection. + * sending queries through the connection. * In a single session, multiple queries will be executed serially. * In order to execute parallel queries, multiple sessions are required. * @access public @@ -84,27 +84,27 @@ class Session { } /** - * Run Cypher statement - * Could be called with a statement object i.e.: `{text: "MATCH ...", prameters: {param: 1}}` - * or with the statement and parameters as separate arguments. + * Run Cypher query + * Could be called with a query object i.e.: `{text: "MATCH ...", prameters: {param: 1}}` + * or with the query and parameters as separate arguments. * * @public - * @param {mixed} statement - Cypher statement to execute - * @param {Object} parameters - Map with parameters to use in statement + * @param {mixed} query - Cypher query to execute + * @param {Object} parameters - Map with parameters to use in query * @param {TransactionConfig} [transactionConfig] - configuration for the new auto-commit transaction. * @return {Result} - New Result */ - run (statement, parameters, transactionConfig) { - const { query, params } = validateStatementAndParameters( - statement, + run (query, parameters, transactionConfig) { + const { validatedQuery, params } = validateQueryAndParameters( + query, parameters ) const autoCommitTxConfig = transactionConfig ? new TxConfig(transactionConfig) : TxConfig.empty() - return this._run(query, params, connection => - connection.protocol().run(query, params, { + return this._run(validatedQuery, params, connection => + connection.protocol().run(validatedQuery, params, { bookmark: this._lastBookmark, txConfig: autoCommitTxConfig, mode: this._mode, @@ -116,14 +116,14 @@ class Session { ) } - _run (statement, parameters, customRunner) { + _run (query, parameters, customRunner) { const connectionHolder = this._connectionHolderWithMode(this._mode) let observerPromise if (!this._open) { observerPromise = Promise.resolve( new FailedObserver({ - error: newError('Cannot run statement in a closed session.') + error: newError('Cannot run query in a closed session.') }) ) } else if (!this._hasTx && connectionHolder.initializeConnection()) { @@ -135,21 +135,21 @@ class Session { observerPromise = Promise.resolve( new FailedObserver({ error: newError( - 'Statements cannot be run directly on a ' + + 'Queries cannot be run directly on a ' + 'session with an open transaction; either run from within the ' + 'transaction or use a different session.' ) }) ) } - return new Result(observerPromise, statement, parameters, connectionHolder) + return new Result(observerPromise, query, parameters, connectionHolder) } /** * Begin a new transaction in this session. A session can have at most one transaction running at a time, if you * want to run multiple concurrent transactions, you should use multiple concurrent sessions. * - * While a transaction is open the session cannot be used to run statements outside the transaction. + * While a transaction is open the session cannot be used to run queries outside the transaction. * * @param {TransactionConfig} [transactionConfig] - configuration for the new auto-commit transaction. * @returns {Transaction} - New Transaction diff --git a/src/transaction-rx.js b/src/transaction-rx.js index 4d636de3a..7143724b3 100644 --- a/src/transaction-rx.js +++ b/src/transaction-rx.js @@ -34,19 +34,19 @@ export default class RxTransaction { } /** - * Creates a reactive result that will execute the statement in this transaction, with the provided parameters. + * Creates a reactive result that will execute the query in this transaction, with the provided parameters. * * @public - * @param {string} statement - Statement to be executed. - * @param {Object} parameters - Parameter values to use in statement execution. + * @param {string} query - Query to be executed. + * @param {Object} parameters - Parameter values to use in query execution. * @returns {RxResult} - A reactive result */ - run (statement, parameters) { + run (query, parameters) { return new RxResult( new Observable(observer => { try { - observer.next(this._txc.run(statement, parameters)) + observer.next(this._txc.run(query, parameters)) observer.complete() } catch (err) { observer.error(err) @@ -75,7 +75,7 @@ export default class RxTransaction { } /** - * Rollbacks the transaction. + * Rolls back the transaction. * * @public * @returns {Observable} - An empty observable diff --git a/src/transaction.js b/src/transaction.js index 9c785f921..996691e35 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -17,7 +17,7 @@ * limitations under the License. */ import Result from './result' -import { validateStatementAndParameters } from './internal/util' +import { validateQueryAndParameters } from './internal/util' import ConnectionHolder, { EMPTY_CONNECTION_HOLDER } from './internal/connection-holder' @@ -74,20 +74,20 @@ class Transaction { } /** - * Run Cypher statement - * Could be called with a statement object i.e.: `{text: "MATCH ...", parameters: {param: 1}}` - * or with the statement and parameters as separate arguments. - * @param {mixed} statement - Cypher statement to execute - * @param {Object} parameters - Map with parameters to use in statement + * Run Cypher query + * Could be called with a query object i.e.: `{text: "MATCH ...", parameters: {param: 1}}` + * or with the query and parameters as separate arguments. + * @param {mixed} query - Cypher query to execute + * @param {Object} parameters - Map with parameters to use in query * @return {Result} New Result */ - run (statement, parameters) { - const { query, params } = validateStatementAndParameters( - statement, + run (query, parameters) { + const { validatedQuery, params } = validateQueryAndParameters( + query, parameters ) - var result = this._state.run(query, params, { + var result = this._state.run(validatedQuery, params, { connectionHolder: this._connectionHolder, onError: this._onError, onComplete: this._onComplete, @@ -201,7 +201,7 @@ const _states = { } }, run: ( - statement, + query, parameters, { connectionHolder, onError, onComplete, reactive, fetchSize } ) => { @@ -210,7 +210,7 @@ const _states = { const observerPromise = connectionHolder .getConnection() .then(conn => - conn.protocol().run(statement, parameters, { + conn.protocol().run(query, parameters, { bookmark: Bookmark.empty(), txConfig: TxConfig.empty(), beforeError: onError, @@ -221,7 +221,7 @@ const _states = { ) .catch(error => new FailedObserver({ error, onError })) - return newCompletedResult(observerPromise, statement, parameters) + return newCompletedResult(observerPromise, query, parameters) } }, @@ -250,18 +250,18 @@ const _states = { } }, run: ( - statement, + query, parameters, { connectionHolder, onError, onComplete, reactive } ) => { return newCompletedResult( new FailedObserver({ error: newError( - 'Cannot run statement in this transaction, because it has been rolled back either because of an error or explicit termination.' + 'Cannot run query in this transaction, because it has been rolled back either because of an error or explicit termination.' ), onError }), - statement, + query, parameters ) } @@ -300,18 +300,18 @@ const _states = { } }, run: ( - statement, + query, parameters, { connectionHolder, onError, onComplete, reactive } ) => { return newCompletedResult( new FailedObserver({ error: newError( - 'Cannot run statement in this transaction, because it has already been committed.' + 'Cannot run query in this transaction, because it has already been committed.' ), onError }), - statement, + query, parameters ) } @@ -349,18 +349,18 @@ const _states = { } }, run: ( - statement, + query, parameters, { connectionHolder, onError, onComplete, reactive } ) => { return newCompletedResult( new FailedObserver({ error: newError( - 'Cannot run statement in this transaction, because it has already been rolled back.' + 'Cannot run query in this transaction, because it has already been rolled back.' ), onError }), - statement, + query, parameters ) } @@ -417,15 +417,15 @@ function finishTransaction ( * For cases when result represents an intermediate or failed action, does not require any metadata and does not * need to influence real connection holder to release connections. * @param {ResultStreamObserver} observer - an observer for the created result. - * @param {string} statement - the cypher statement that produced the result. - * @param {Object} parameters - the parameters for cypher statement that produced the result. + * @param {string} query - the cypher query that produced the result. + * @param {Object} parameters - the parameters for cypher query that produced the result. * @return {Result} new result. * @private */ -function newCompletedResult (observerPromise, statement, parameters) { +function newCompletedResult (observerPromise, query, parameters) { return new Result( Promise.resolve(observerPromise), - statement, + query, parameters, EMPTY_CONNECTION_HOLDER ) diff --git a/test/examples.test.js b/test/examples.test.js index 623e4b384..67982fb75 100644 --- a/test/examples.test.js +++ b/test/examples.test.js @@ -270,7 +270,7 @@ describe('#integration examples', () => { try { await session.run('CREATE (i:Item)') } catch (error) { - console.log(`unable to execute statement. ${error}`) + console.log(`unable to execute query. ${error}`) } finally { await session.close() } diff --git a/test/internal/bolt-protocol-v1.test.js b/test/internal/bolt-protocol-v1.test.js index c71216cd9..d35414172 100644 --- a/test/internal/bolt-protocol-v1.test.js +++ b/test/internal/bolt-protocol-v1.test.js @@ -82,13 +82,13 @@ describe('#unit BoltProtocolV1', () => { expect(recorder.flushes).toEqual([true]) }) - it('should run a statement', () => { + it('should run a query', () => { const recorder = new utils.MessageRecordingConnection() const protocol = new BoltProtocolV1(recorder, null, false) - const statement = 'RETURN $x, $y' + const query = 'RETURN $x, $y' const parameters = { x: 'x', y: 'y' } - const observer = protocol.run(statement, parameters, { + const observer = protocol.run(query, parameters, { bookmark: Bookmark.empty(), txConfig: TxConfig.empty(), mode: WRITE @@ -97,7 +97,7 @@ describe('#unit BoltProtocolV1', () => { recorder.verifyMessageCount(2) expect(recorder.messages[0]).toBeMessage( - RequestMessage.run(statement, parameters) + RequestMessage.run(query, parameters) ) expect(recorder.messages[1]).toBeMessage(RequestMessage.pullAll()) expect(recorder.observers).toEqual([observer, observer]) @@ -209,7 +209,7 @@ describe('#unit BoltProtocolV1', () => { describe('run', () => { function verifyRun (txConfig) { verifyError((protocol, _observer) => - protocol.run('statement', {}, { txConfig }) + protocol.run('query', {}, { txConfig }) ) } @@ -253,7 +253,7 @@ describe('#unit BoltProtocolV1', () => { describe('run', () => { function verifyRun (database) { - verifyError(protocol => protocol.run('statement', {}, { database })) + verifyError(protocol => protocol.run('query', {}, { database })) } it('should throw error when database is set', () => { diff --git a/test/internal/bolt-protocol-v3.test.js b/test/internal/bolt-protocol-v3.test.js index 4cd2cb648..55d85582b 100644 --- a/test/internal/bolt-protocol-v3.test.js +++ b/test/internal/bolt-protocol-v3.test.js @@ -60,7 +60,7 @@ describe('#unit BoltProtocolV3', () => { expect(recorder.flushes).toEqual([true]) }) - it('should run a statement', () => { + it('should run a query', () => { const bookmark = new Bookmark([ 'neo4j:bookmark:v1:tx1', 'neo4j:bookmark:v1:tx2' @@ -72,10 +72,10 @@ describe('#unit BoltProtocolV3', () => { const recorder = new utils.MessageRecordingConnection() const protocol = new BoltProtocolV3(recorder, null, false) - const statement = 'RETURN $x, $y' + const query = 'RETURN $x, $y' const parameters = { x: 'x', y: 'y' } - const observer = protocol.run(statement, parameters, { + const observer = protocol.run(query, parameters, { bookmark, txConfig, mode: WRITE @@ -84,7 +84,7 @@ describe('#unit BoltProtocolV3', () => { recorder.verifyMessageCount(2) expect(recorder.messages[0]).toBeMessage( - RequestMessage.runWithMetadata(statement, parameters, { + RequestMessage.runWithMetadata(query, parameters, { bookmark, txConfig, mode: WRITE @@ -177,7 +177,7 @@ describe('#unit BoltProtocolV3', () => { describe('run', () => { function verifyRun (database) { - verifyError(protocol => protocol.run('statement', {}, { database })) + verifyError(protocol => protocol.run('query', {}, { database })) } it('should throw error when database is set', () => { diff --git a/test/internal/bolt-protocol-v4.test.js b/test/internal/bolt-protocol-v4.test.js index 4a2714968..a38d6c871 100644 --- a/test/internal/bolt-protocol-v4.test.js +++ b/test/internal/bolt-protocol-v4.test.js @@ -29,7 +29,7 @@ describe('#unit BoltProtocolV4', () => { jasmine.addMatchers(utils.matchers) }) - it('should run a statement', () => { + it('should run a query', () => { const database = 'testdb' const bookmark = new Bookmark([ 'neo4j:bookmark:v1:tx1', @@ -42,10 +42,10 @@ describe('#unit BoltProtocolV4', () => { const recorder = new utils.MessageRecordingConnection() const protocol = new BoltProtocolV4(recorder, null, false) - const statement = 'RETURN $x, $y' + const query = 'RETURN $x, $y' const parameters = { x: 'x', y: 'y' } - const observer = protocol.run(statement, parameters, { + const observer = protocol.run(query, parameters, { bookmark, txConfig, database, @@ -55,7 +55,7 @@ describe('#unit BoltProtocolV4', () => { recorder.verifyMessageCount(2) expect(recorder.messages[0]).toBeMessage( - RequestMessage.runWithMetadata(statement, parameters, { + RequestMessage.runWithMetadata(query, parameters, { bookmark, txConfig, database, diff --git a/test/internal/fake-connection.js b/test/internal/fake-connection.js index a16d99baa..37a0dc978 100644 --- a/test/internal/fake-connection.js +++ b/test/internal/fake-connection.js @@ -38,7 +38,7 @@ export default class FakeConnection extends Connection { this.resetInvoked = 0 this.releaseInvoked = 0 - this.seenStatements = [] + this.seenQueries = [] this.seenParameters = [] this.seenProtocolOptions = [] this._server = {} @@ -69,10 +69,10 @@ export default class FakeConnection extends Connection { } protocol () { - // return fake protocol object that simply records seen statements and parameters + // return fake protocol object that simply records seen queries and parameters return { - run: (statement, parameters, protocolOptions) => { - this.seenStatements.push(statement) + run: (query, parameters, protocolOptions) => { + this.seenQueries.push(query) this.seenParameters.push(parameters) this.seenProtocolOptions.push(protocolOptions) } diff --git a/test/internal/logger.test.js b/test/internal/logger.test.js index 474b43c98..9c68a1f44 100644 --- a/test/internal/logger.test.js +++ b/test/internal/logger.test.js @@ -96,11 +96,11 @@ describe('#integration Logger', () => { expect(seenLevels).toContain('info') expect(seenLevels).toContain('debug') - // the executed statement should've been logged - const statementLogged = seenMessages.find( + // the executed query should've been logged + const queryLogged = seenMessages.find( message => message.indexOf('RETURN 42') !== -1 ) - expect(statementLogged).toBeTruthy() + expect(queryLogged).toBeTruthy() await session.close() await driver.close() @@ -121,12 +121,12 @@ describe('#integration Logger', () => { expect(logged.length).toBeGreaterThan(0) - // the executed statement should've been logged - const statementLogged = logged.find( + // the executed query should've been logged + const queryLogged = logged.find( log => log.indexOf('DEBUG') !== -1 && log.indexOf('RETURN 123456789') !== -1 ) - expect(statementLogged).toBeTruthy() + expect(queryLogged).toBeTruthy() // driver creation should've been logged because it is on info level const driverCreationLogged = logged.find( @@ -153,11 +153,11 @@ describe('#integration Logger', () => { await session.run('RETURN 123456789') expect(logged.length).toBeGreaterThan(0) - // the executed statement should not be logged because it is in debug level - const statementLogged = logged.find( + // the executed query should not be logged because it is in debug level + const queryLogged = logged.find( log => log.indexOf('RETURN 123456789') !== -1 ) - expect(statementLogged).toBeFalsy() + expect(queryLogged).toBeFalsy() // driver creation should've been logged because it is on info level const driverCreationLogged = logged.find( diff --git a/test/internal/node/routing.driver.boltkit.test.js b/test/internal/node/routing.driver.boltkit.test.js index 45a49a94b..5277aebc8 100644 --- a/test/internal/node/routing.driver.boltkit.test.js +++ b/test/internal/node/routing.driver.boltkit.test.js @@ -1948,7 +1948,7 @@ describe('#stub-routing routing driver with stub server', () => { { disableLosslessIntegers: true } )) - it('should send read access mode on statement metadata', async () => { + it('should send read access mode on query metadata', async () => { if (!boltStub.supported) { return } @@ -1978,7 +1978,7 @@ describe('#stub-routing routing driver with stub server', () => { await readServer.exit() }) - it('should send read access mode on statement metadata with read transaction', async () => { + it('should send read access mode on query metadata with read transaction', async () => { if (!boltStub.supported) { return } @@ -2010,7 +2010,7 @@ describe('#stub-routing routing driver with stub server', () => { await readServer.exit() }) - it('should not send write access mode on statement metadata', async () => { + it('should not send write access mode on query metadata', async () => { if (!boltStub.supported) { return } @@ -2035,7 +2035,7 @@ describe('#stub-routing routing driver with stub server', () => { await writeServer.exit() }) - it('should not send write access mode on statement metadata with write transaction', async () => { + it('should not send write access mode on query metadata with write transaction', async () => { if (!boltStub.supported) { return } diff --git a/test/internal/request-message.test.js b/test/internal/request-message.test.js index 47b565249..5fd40b24f 100644 --- a/test/internal/request-message.test.js +++ b/test/internal/request-message.test.js @@ -36,15 +36,15 @@ describe('#unit RequestMessage', () => { }) it('should create RUN message', () => { - const statement = 'RETURN $x' + const query = 'RETURN $x' const parameters = { x: 42 } - const message = RequestMessage.run(statement, parameters) + const message = RequestMessage.run(query, parameters) expect(message.signature).toEqual(0x10) - expect(message.fields).toEqual([statement, parameters]) + expect(message.fields).toEqual([query, parameters]) expect(message.toString()).toEqual( - `RUN ${statement} ${JSON.stringify(parameters)}` + `RUN ${query} ${JSON.stringify(parameters)}` ) }) @@ -124,7 +124,7 @@ describe('#unit RequestMessage', () => { it('should create RUN with metadata message', () => { ;[READ, WRITE].forEach(mode => { - const statement = 'RETURN $x' + const query = 'RETURN $x' const parameters = { x: 42 } const bookmark = new Bookmark([ 'neo4j:bookmark:v1:tx1', @@ -136,7 +136,7 @@ describe('#unit RequestMessage', () => { metadata: { a: 'a', b: 'b' } }) - const message = RequestMessage.runWithMetadata(statement, parameters, { + const message = RequestMessage.runWithMetadata(query, parameters, { bookmark, txConfig, mode @@ -152,9 +152,9 @@ describe('#unit RequestMessage', () => { } expect(message.signature).toEqual(0x10) - expect(message.fields).toEqual([statement, parameters, expectedMetadata]) + expect(message.fields).toEqual([query, parameters, expectedMetadata]) expect(message.toString()).toEqual( - `RUN ${statement} ${JSON.stringify(parameters)} ${JSON.stringify( + `RUN ${query} ${JSON.stringify(parameters)} ${JSON.stringify( expectedMetadata )}` ) diff --git a/test/internal/routing-util.test.js b/test/internal/routing-util.test.js index 94d5ef2aa..f8a3fe09f 100644 --- a/test/internal/routing-util.test.js +++ b/test/internal/routing-util.test.js @@ -101,7 +101,7 @@ describe('#unit RoutingUtil', () => { const session = FakeSession.withFakeConnection(connection) callRoutingProcedure(session, '', {}).then(() => { - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.cluster.routing.getRoutingTable($context)' ]) expect(connection.seenParameters).toEqual([{ context: {} }]) @@ -115,7 +115,7 @@ describe('#unit RoutingUtil', () => { callRoutingProcedure(session, '', { key1: 'value1', key2: 'value2' }).then( () => { - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.cluster.routing.getRoutingTable($context)' ]) expect(connection.seenParameters).toEqual([ @@ -131,7 +131,7 @@ describe('#unit RoutingUtil', () => { const session = FakeSession.withFakeConnection(connection) callRoutingProcedure(session, '', {}).then(() => { - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.cluster.routing.getRoutingTable($context)' ]) expect(connection.seenParameters).toEqual([{ context: {} }]) @@ -144,7 +144,7 @@ describe('#unit RoutingUtil', () => { const session = FakeSession.withFakeConnection(connection) callRoutingProcedure(session, '', { key1: 'foo', key2: 'bar' }).then(() => { - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.cluster.routing.getRoutingTable($context)' ]) expect(connection.seenParameters).toEqual([ @@ -181,7 +181,7 @@ describe('#unit RoutingUtil', () => { await callRoutingProcedure(session, '', {}) - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.routing.getRoutingTable($context, $database)' ]) expect(connection.seenParameters).toEqual([ @@ -208,7 +208,7 @@ describe('#unit RoutingUtil', () => { await callRoutingProcedure(session, '', {}) - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.routing.getRoutingTable($context, $database)' ]) expect(connection.seenParameters).toEqual([ @@ -234,7 +234,7 @@ describe('#unit RoutingUtil', () => { await callRoutingProcedure(session, '', {}) - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.routing.getRoutingTable($context, $database)' ]) expect(connection.seenParameters).toEqual([ @@ -407,7 +407,7 @@ describe('#unit RoutingUtil', () => { const session = FakeSession.withFakeConnection(connection) callRoutingProcedure(session, database, context).then(() => { - expect(connection.seenStatements).toEqual([ + expect(connection.seenQueries).toEqual([ 'CALL dbms.routing.getRoutingTable($context, $database)' ]) expect(connection.seenParameters).toEqual([ @@ -523,11 +523,11 @@ describe('#unit RoutingUtil', () => { return new FakeSession(null, connection) } - _run (ignoreStatement, ignoreParameters, statementRunner) { + _run (ignoreQuery, ignoreParameters, queryRunner) { if (this._runResponse) { return this._runResponse } - statementRunner(this._fakeConnection) + queryRunner(this._fakeConnection) return Promise.resolve() } diff --git a/test/internal/stream-observer.test.js b/test/internal/stream-observer.test.js index ee69bcfdc..6f8a97304 100644 --- a/test/internal/stream-observer.test.js +++ b/test/internal/stream-observer.test.js @@ -80,7 +80,7 @@ describe('#unit ResultStreamObserver', () => { it('passes received error the subscriber', () => { const streamObserver = newStreamObserver() - const error = new Error('Invalid Cypher statement') + const error = new Error('Invalid Cypher query') let receivedError = null const observer = newObserver(NO_OP, error => { @@ -95,7 +95,7 @@ describe('#unit ResultStreamObserver', () => { it('passes existing error to a new subscriber', () => { const streamObserver = newStreamObserver() - const error = new Error('Invalid Cypher statement') + const error = new Error('Invalid Cypher query') streamObserver.onError(error) diff --git a/test/internal/util.test.js b/test/internal/util.test.js index 5a2e6e140..60ea4a0b9 100644 --- a/test/internal/util.test.js +++ b/test/internal/util.test.js @@ -55,23 +55,23 @@ describe('#unit Utils', () => { verifyInvalidString(console.log) }) - it('should check cypher statements (non-empty strings)', () => { + it('should check cypher queries (non-empty strings)', () => { verifyValidString(new String('foo')) verifyValidString(String('foo')) verifyValidString('foo') - verifyInvalidCypherStatement('') - verifyInvalidCypherStatement('\n') - verifyInvalidCypherStatement('\t') - verifyInvalidCypherStatement('\r') - verifyInvalidCypherStatement(' ') - verifyInvalidCypherStatement(' \n\r') - verifyInvalidCypherStatement({}) - verifyInvalidCypherStatement({ foo: 1 }) - verifyInvalidCypherStatement([]) - verifyInvalidCypherStatement(['1']) - verifyInvalidCypherStatement([1, '2']) - verifyInvalidCypherStatement(console.log) + verifyInvalidCypherQuery('') + verifyInvalidCypherQuery('\n') + verifyInvalidCypherQuery('\t') + verifyInvalidCypherQuery('\r') + verifyInvalidCypherQuery(' ') + verifyInvalidCypherQuery(' \n\r') + verifyInvalidCypherQuery({}) + verifyInvalidCypherQuery({ foo: 1 }) + verifyInvalidCypherQuery([]) + verifyInvalidCypherQuery(['1']) + verifyInvalidCypherQuery([1, '2']) + verifyInvalidCypherQuery(console.log) }) it('should check valid query parameters', () => { @@ -198,22 +198,20 @@ describe('#unit Utils', () => { ) } - function verifyInvalidCypherStatement (str) { - expect(() => util.validateStatementAndParameters(str, {})).toThrowError( + function verifyInvalidCypherQuery (str) { + expect(() => util.validateQueryAndParameters(str, {})).toThrowError( TypeError ) } function verifyValidQueryParameters (obj) { - expect(() => - util.validateStatementAndParameters('RETURN 1', obj) - ).not.toThrow() + expect(() => util.validateQueryAndParameters('RETURN 1', obj)).not.toThrow() } function verifyInvalidQueryParameters (obj) { - expect(() => - util.validateStatementAndParameters('RETURN 1', obj) - ).toThrowError(TypeError) + expect(() => util.validateQueryAndParameters('RETURN 1', obj)).toThrowError( + TypeError + ) } function verifyValidDate (obj) { diff --git a/test/nested-statements.test.js b/test/nested-statements.test.js index efa0d93dc..f5b742d7d 100644 --- a/test/nested-statements.test.js +++ b/test/nested-statements.test.js @@ -18,7 +18,7 @@ */ import neo4j from '../src' -import { statementType } from '../src/result-summary' +import { queryType } from '../src/result-summary' import Session from '../src/session' import { READ } from '../src/driver' import SingleConnectionProvider from '../src/internal/connection-provider-single' @@ -116,7 +116,7 @@ describe('#integration session', () => { ).toBeRejectedWith( jasmine.objectContaining({ message: - 'Statements cannot be run directly on a session with an open transaction; ' + + 'Queries cannot be run directly on a session with an open transaction; ' + 'either run from within the transaction or use a different session.' }) ) diff --git a/test/record.test.js b/test/record.test.js index 8fdb4083e..4c4c2f7b0 100644 --- a/test/record.test.js +++ b/test/record.test.js @@ -88,7 +88,7 @@ describe('#unit Record', () => { }).toThrow( new Neo4jError( "This record has no field with index '1'. Remember that indexes start at `0`, " + - 'and make sure your statement returns records in the shape you meant it to.' + 'and make sure your query returns records in the shape you meant it to.' ) ) }) diff --git a/test/rx/navigation.test.js b/test/rx/navigation.test.js index a3503971d..eebfc26fc 100644 --- a/test/rx/navigation.test.js +++ b/test/rx/navigation.test.js @@ -82,14 +82,14 @@ describe('#integration-rx navigation', () => { it('should return records only once', () => shouldReturnRecordsOnlyOnce(serverVersion, session)) - it('should return empty keys for statement without return', () => - shouldReturnEmptyKeysForStatementWithNoReturn(serverVersion, session)) + it('should return empty keys for query without return', () => + shouldReturnEmptyKeysForQueryWithNoReturn(serverVersion, session)) - it('should return no records for statement without return', () => - shouldReturnNoRecordsForStatementWithNoReturn(serverVersion, session)) + it('should return no records for query without return', () => + shouldReturnNoRecordsForQueryWithNoReturn(serverVersion, session)) - it('should return summary for statement without return', () => - shouldReturnSummaryForStatementWithNoReturn(serverVersion, session)) + it('should return summary for query without return', () => + shouldReturnSummaryForQueryWithNoReturn(serverVersion, session)) it('should fail on keys when run fails', () => shouldFailOnKeysWhenRunFails(serverVersion, session)) @@ -187,14 +187,14 @@ describe('#integration-rx navigation', () => { it('should return records only once', () => shouldReturnRecordsOnlyOnce(serverVersion, txc)) - it('should return empty keys for statement without return', () => - shouldReturnEmptyKeysForStatementWithNoReturn(serverVersion, txc)) + it('should return empty keys for query without return', () => + shouldReturnEmptyKeysForQueryWithNoReturn(serverVersion, txc)) - it('should return no records for statement without return', () => - shouldReturnNoRecordsForStatementWithNoReturn(serverVersion, txc)) + it('should return no records for query without return', () => + shouldReturnNoRecordsForQueryWithNoReturn(serverVersion, txc)) - it('should return summary for statement without return', () => - shouldReturnSummaryForStatementWithNoReturn(serverVersion, txc)) + it('should return summary for query without return', () => + shouldReturnSummaryForQueryWithNoReturn(serverVersion, txc)) it('should fail on keys when run fails', () => shouldFailOnKeysWhenRunFails(serverVersion, txc)) @@ -435,10 +435,7 @@ describe('#integration-rx navigation', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnEmptyKeysForStatementWithNoReturn ( - version, - runnable - ) { + async function shouldReturnEmptyKeysForQueryWithNoReturn (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } @@ -461,10 +458,7 @@ describe('#integration-rx navigation', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnNoRecordsForStatementWithNoReturn ( - version, - runnable - ) { + async function shouldReturnNoRecordsForQueryWithNoReturn (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } @@ -478,10 +472,7 @@ describe('#integration-rx navigation', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnSummaryForStatementWithNoReturn ( - version, - runnable - ) { + async function shouldReturnSummaryForQueryWithNoReturn (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } @@ -631,7 +622,7 @@ describe('#integration-rx navigation', () => { await collectAndAssertEmpty(closeFunc()) const expectedError = jasmine.objectContaining({ - message: jasmine.stringMatching(/Cannot run statement/) + message: jasmine.stringMatching(/Cannot run query/) }) await collectAndAssertError(result.keys(), expectedError) await collectAndAssertError(result.records(), expectedError) @@ -671,17 +662,17 @@ describe('#integration-rx navigation', () => { ]) } - async function collectAndAssertSummary (result, expectedStatementType = 'r') { + async function collectAndAssertSummary (result, expectedQueryType = 'r') { const summary = await result .consume() .pipe( - map(s => s.statementType), + map(s => s.queryType), materialize(), toArray() ) .toPromise() expect(summary).toEqual([ - Notification.createNext(expectedStatementType), + Notification.createNext(expectedQueryType), Notification.createComplete() ]) } diff --git a/test/rx/nested-statements.test.js b/test/rx/nested-statements.test.js index 2830885c9..b96f6e358 100644 --- a/test/rx/nested-statements.test.js +++ b/test/rx/nested-statements.test.js @@ -119,7 +119,7 @@ describe('#integration-rx transaction', () => { expect(result).toEqual([ Notification.createError( jasmine.stringMatching( - /Statements cannot be run directly on a session with an open transaction/ + /Queries cannot be run directly on a session with an open transaction/ ) ) ]) diff --git a/test/rx/session.test.js b/test/rx/session.test.js index be57ac5eb..dd82c07e7 100644 --- a/test/rx/session.test.js +++ b/test/rx/session.test.js @@ -49,7 +49,7 @@ describe('#integration rx-session', () => { await driver.close() }) - it('should be able to run a simple statement', async () => { + it('should be able to run a simple query', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -111,7 +111,7 @@ describe('#integration rx-session', () => { } const txcWork = new ConfigurableTransactionWork({ - statement: 'CREATE (:WithoutRetry) RETURN 5' + query: 'CREATE (:WithoutRetry) RETURN 5' }) const result = await session @@ -136,7 +136,7 @@ describe('#integration rx-session', () => { } const txcWork = new ConfigurableTransactionWork({ - statement: 'CREATE (:WithReactiveFailure) RETURN 7', + query: 'CREATE (:WithReactiveFailure) RETURN 7', reactiveFailures: [ newError('service unavailable', SERVICE_UNAVAILABLE), newError('session expired', SESSION_EXPIRED), @@ -166,7 +166,7 @@ describe('#integration rx-session', () => { } const txcWork = new ConfigurableTransactionWork({ - statement: 'CREATE (:WithSyncFailure) RETURN 9', + query: 'CREATE (:WithSyncFailure) RETURN 9', syncFailures: [ newError('service unavailable', SERVICE_UNAVAILABLE), newError('session expired', SESSION_EXPIRED), @@ -196,7 +196,7 @@ describe('#integration rx-session', () => { } const txcWork = new ConfigurableTransactionWork({ - statement: 'UNWIND [10, 5, 0] AS x CREATE (:Hi) RETURN 10/x' + query: 'UNWIND [10, 5, 0] AS x CREATE (:Hi) RETURN 10/x' }) const result = await session @@ -222,7 +222,7 @@ describe('#integration rx-session', () => { } const txcWork = new ConfigurableTransactionWork({ - statement: 'CREATE (:Person) RETURN 1', + query: 'CREATE (:Person) RETURN 1', syncFailures: [ newError( 'a transient error', @@ -261,8 +261,8 @@ describe('#integration rx-session', () => { .toPromise() } class ConfigurableTransactionWork { - constructor ({ statement, syncFailures = [], reactiveFailures = [] } = {}) { - this._statement = statement + constructor ({ query, syncFailures = [], reactiveFailures = [] } = {}) { + this._query = query this._syncFailures = syncFailures this._syncFailuresIndex = 0 this._reactiveFailures = reactiveFailures @@ -286,7 +286,7 @@ describe('#integration rx-session', () => { } return txc - .run(this._statement) + .run(this._query) .records() .pipe(map(r => r.get(0).toInt())) } diff --git a/test/rx/summary.test.js b/test/rx/summary.test.js index 4a2f91b85..02133a222 100644 --- a/test/rx/summary.test.js +++ b/test/rx/summary.test.js @@ -48,14 +48,14 @@ describe('#integration-rx summary', () => { it('should return non-null summary', () => shouldReturnNonNullSummary(serverVersion, session)) - it('should return summary with statement text', () => - shouldReturnSummaryWithStatementText(serverVersion, session)) + it('should return summary with query text', () => + shouldReturnSummaryWithQueryText(serverVersion, session)) - it('should return summary with statement text and parameters', () => - shouldReturnSummaryWithStatementTextAndParams(serverVersion, session)) + it('should return summary with query text and parameters', () => + shouldReturnSummaryWithQueryTextAndParams(serverVersion, session)) - it('should return summary with statement type', () => - shouldReturnSummaryWithCorrectStatementType(serverVersion, session)) + it('should return summary with query type', () => + shouldReturnSummaryWithCorrectQueryType(serverVersion, session)) it('should return summary with correct counters for create', () => shouldReturnSummaryWithUpdateStatisticsForCreate(serverVersion, session)) @@ -147,14 +147,14 @@ describe('#integration-rx summary', () => { it('should return non-null summary', () => shouldReturnNonNullSummary(serverVersion, txc)) - it('should return summary with statement text', () => - shouldReturnSummaryWithStatementText(serverVersion, txc)) + it('should return summary with query text', () => + shouldReturnSummaryWithQueryText(serverVersion, txc)) - it('should return summary with statement text and parameters', () => - shouldReturnSummaryWithStatementTextAndParams(serverVersion, txc)) + it('should return summary with query text and parameters', () => + shouldReturnSummaryWithQueryTextAndParams(serverVersion, txc)) - it('should return summary with statement type', () => - shouldReturnSummaryWithCorrectStatementType(serverVersion, txc)) + it('should return summary with query type', () => + shouldReturnSummaryWithCorrectQueryType(serverVersion, txc)) it('should return summary with correct counters for create', () => shouldReturnSummaryWithUpdateStatisticsForCreate(serverVersion, txc)) @@ -259,12 +259,12 @@ describe('#integration-rx summary', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnSummaryWithStatementText (version, runnable) { + async function shouldReturnSummaryWithQueryText (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } - await verifyStatementTextAndParameters( + await verifyQueryTextAndParameters( runnable, 'UNWIND RANGE(1, 10) AS n RETURN n' ) @@ -274,15 +274,12 @@ describe('#integration-rx summary', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnSummaryWithStatementTextAndParams ( - version, - runnable - ) { + async function shouldReturnSummaryWithQueryTextAndParams (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } - await verifyStatementTextAndParameters( + await verifyQueryTextAndParameters( runnable, 'UNWIND RANGE(1, $x) AS n RETURN n', { x: 100 } @@ -293,17 +290,14 @@ describe('#integration-rx summary', () => { * @param {ServerVersion} version * @param {RxSession|RxTransaction} runnable */ - async function shouldReturnSummaryWithCorrectStatementType ( - version, - runnable - ) { + async function shouldReturnSummaryWithCorrectQueryType (version, runnable) { if (version.compareTo(VERSION_4_0_0) < 0) { return } - await verifyStatementType(runnable, 'CREATE (n)', 'w') - await verifyStatementType(runnable, 'MATCH (n) RETURN n LIMIT 1', 'r') - await verifyStatementType(runnable, 'CREATE (n) RETURN n', 'rw') + await verifyQueryType(runnable, 'CREATE (n)', 'w') + await verifyQueryType(runnable, 'MATCH (n) RETURN n LIMIT 1', 'r') + await verifyQueryType(runnable, 'CREATE (n) RETURN n', 'rw') } /** @@ -646,7 +640,9 @@ describe('#integration-rx summary', () => { 'The provided label is not in the database.' ) expect(summary.notifications[0].description).toBe( - "One of the labels in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing label name is: ThisLabelDoesNotExist)" + "One of the labels in your query is not available in the database, make sure you didn't misspell it or that" + + ' the label is available when you run this statement in your application (the missing label name is:' + + ' ThisLabelDoesNotExist)' ) expect(summary.notifications[0].severity).toBe('WARNING') } @@ -654,53 +650,49 @@ describe('#integration-rx summary', () => { /** * * @param {RxSession|RxTransaction} runnable - * @param {string} statement + * @param {string} query * @param {*} parameters */ - async function verifyStatementTextAndParameters ( + async function verifyQueryTextAndParameters ( runnable, - statement, + query, parameters = null ) { const summary = await runnable - .run(statement, parameters) + .run(query, parameters) .consume() .toPromise() expect(summary).toBeDefined() - expect(summary.statement).toBeDefined() - expect(summary.statement.text).toBe(statement) - expect(summary.statement.parameters).toEqual(parameters || {}) + expect(summary.query).toBeDefined() + expect(summary.query.text).toBe(query) + expect(summary.query.parameters).toEqual(parameters || {}) } /** * * @param {RxSession|RxTransaction} runnable - * @param {string} statement - * @param {string} expectedStatementType + * @param {string} query + * @param {string} expectedQueryType */ - async function verifyStatementType ( - runnable, - statement, - expectedStatementType - ) { + async function verifyQueryType (runnable, query, expectedQueryType) { const summary = await runnable - .run(statement) + .run(query) .consume() .toPromise() expect(summary).toBeDefined() - expect(summary.statementType).toBe(expectedStatementType) + expect(summary.queryType).toBe(expectedQueryType) } /** * * @param {RxSession|RxTransaction} runnable - * @param {string} statement + * @param {string} query * @param {*} parameters * @param {*} stats */ - async function verifyUpdates (runnable, statement, parameters, stats) { + async function verifyUpdates (runnable, query, parameters, stats) { const summary = await runnable - .run(statement, parameters) + .run(query, parameters) .consume() .toPromise() expect(summary).toBeDefined() @@ -712,19 +704,19 @@ describe('#integration-rx summary', () => { /** * * @param {RxSession|RxTransaction} runnable - * @param {string} statement + * @param {string} query * @param {*} parameters * @param {number} systemUpdates * @returns {Promise} */ async function verifySystemUpdates ( runnable, - statement, + query, parameters, systemUpdates ) { const summary = await runnable - .run(statement, parameters) + .run(query, parameters) .consume() .toPromise() expect(summary).toBeDefined() diff --git a/test/rx/transaction.test.js b/test/rx/transaction.test.js index 83e093e7e..caf2b92d6 100644 --- a/test/rx/transaction.test.js +++ b/test/rx/transaction.test.js @@ -88,7 +88,7 @@ describe('#integration-rx transaction', () => { expect(result).toEqual([Notification.createComplete()]) }) - it('should run statement and commit', async () => { + it('should run query and commit', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -117,7 +117,7 @@ describe('#integration-rx transaction', () => { expect(await countNodes(42)).toBe(1) }) - it('should run statement and rollback', async () => { + it('should run query and rollback', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -146,38 +146,38 @@ describe('#integration-rx transaction', () => { expect(await countNodes(42)).toBe(0) }) - it('should run multiple statements and commit', async () => { - await verifyCanRunMultipleStatements(true) + it('should run multiple queries and commit', async () => { + await verifyCanRunMultipleQueries(true) }) - it('should run multiple statements and rollback', async () => { - await verifyCanRunMultipleStatements(false) + it('should run multiple queries and rollback', async () => { + await verifyCanRunMultipleQueries(false) }) - it('should run multiple statements without waiting and commit', async () => { - await verifyCanRunMultipleStatementsWithoutWaiting(true) + it('should run multiple queries without waiting and commit', async () => { + await verifyCanRunMultipleQueriesWithoutWaiting(true) }) - it('should run multiple statements without waiting and rollback', async () => { - await verifyCanRunMultipleStatementsWithoutWaiting(false) + it('should run multiple queries without waiting and rollback', async () => { + await verifyCanRunMultipleQueriesWithoutWaiting(false) }) - it('should run multiple statements without streaming and commit', async () => { - await verifyCanRunMultipleStatementsWithoutStreaming(true) + it('should run multiple queries without streaming and commit', async () => { + await verifyCanRunMultipleQueriesWithoutStreaming(true) }) - it('should run multiple statements without streaming and rollback', async () => { - await verifyCanRunMultipleStatementsWithoutStreaming(false) + it('should run multiple queries without streaming and rollback', async () => { + await verifyCanRunMultipleQueriesWithoutStreaming(false) }) - it('should fail to commit after a failed statement', async () => { + it('should fail to commit after a failed query', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } const txc = await session.beginTransaction().toPromise() - await verifyFailsWithWrongStatement(txc) + await verifyFailsWithWrongQuery(txc) const result = await txc .commit() @@ -197,14 +197,14 @@ describe('#integration-rx transaction', () => { ]) }) - it('should succeed to rollback after a failed statement', async () => { + it('should succeed to rollback after a failed query', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } const txc = await session.beginTransaction().toPromise() - await verifyFailsWithWrongStatement(txc) + await verifyFailsWithWrongQuery(txc) const result = await txc .rollback() @@ -216,7 +216,7 @@ describe('#integration-rx transaction', () => { expect(result).toEqual([Notification.createComplete()]) }) - it('should fail to commit after successful and failed statement', async () => { + it('should fail to commit after successful and failed query', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -225,7 +225,7 @@ describe('#integration-rx transaction', () => { await verifyCanCreateNode(txc, 5) await verifyCanReturnOne(txc) - await verifyFailsWithWrongStatement(txc) + await verifyFailsWithWrongQuery(txc) const result = await txc .commit() @@ -245,7 +245,7 @@ describe('#integration-rx transaction', () => { ]) }) - it('should succeed to rollback after successful and failed statement', async () => { + it('should succeed to rollback after successful and failed query', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -254,7 +254,7 @@ describe('#integration-rx transaction', () => { await verifyCanCreateNode(txc, 5) await verifyCanReturnOne(txc) - await verifyFailsWithWrongStatement(txc) + await verifyFailsWithWrongQuery(txc) const result = await txc .rollback() @@ -266,14 +266,14 @@ describe('#integration-rx transaction', () => { expect(result).toEqual([Notification.createComplete()]) }) - it('should fail to run another statement after a failed one', async () => { + it('should fail to run another query after a failed one', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } const txc = await session.beginTransaction().toPromise() - await verifyFailsWithWrongStatement(txc) + await verifyFailsWithWrongQuery(txc) const result = await txc .run('CREATE ()') @@ -287,7 +287,7 @@ describe('#integration-rx transaction', () => { Notification.createError( jasmine.objectContaining({ message: jasmine.stringMatching( - /Cannot run statement in this transaction, because .* of an error/ + /Cannot run query in this transaction, because .* of an error/ ) }) ) @@ -406,12 +406,12 @@ describe('#integration-rx transaction', () => { ]) }) - it('should fail to run statement after committed transaction', async () => { - await verifyFailToRunStatementAfterTxcIsComplete(true) + it('should fail to run query after committed transaction', async () => { + await verifyFailToRunQueryAfterTxcIsComplete(true) }) - it('should fail to run statement after rollbacked transaction', async () => { - await verifyFailToRunStatementAfterTxcIsComplete(false) + it('should fail to run query after rolled back transaction', async () => { + await verifyFailToRunQueryAfterTxcIsComplete(false) }) it('should update bookmark', async () => { @@ -438,7 +438,7 @@ describe('#integration-rx transaction', () => { expect(bookmark2).not.toEqual(bookmark1) }) - it('should propagate failures from statements', async () => { + it('should propagate failures from queries', async () => { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -551,7 +551,7 @@ describe('#integration-rx transaction', () => { await verifyCanCommitOrRollback(txc, commit) } - async function verifyFailToRunStatementAfterTxcIsComplete (commit) { + async function verifyFailToRunQueryAfterTxcIsComplete (commit) { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -572,14 +572,14 @@ describe('#integration-rx transaction', () => { Notification.createError( jasmine.objectContaining({ message: jasmine.stringMatching( - /Cannot run statement in this transaction, because/ + /Cannot run query in this transaction, because/ ) }) ) ]) } - async function verifyCanRunMultipleStatements (commit) { + async function verifyCanRunMultipleQueries (commit) { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -603,7 +603,7 @@ describe('#integration-rx transaction', () => { await verifyCommittedOrRollbacked(commit) } - async function verifyCanRunMultipleStatementsWithoutWaiting (commit) { + async function verifyCanRunMultipleQueriesWithoutWaiting (commit) { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -629,7 +629,7 @@ describe('#integration-rx transaction', () => { await verifyCommittedOrRollbacked(commit) } - async function verifyCanRunMultipleStatementsWithoutStreaming (commit) { + async function verifyCanRunMultipleQueriesWithoutStreaming (commit) { if (serverVersion.compareTo(VERSION_4_0_0) < 0) { return } @@ -722,7 +722,7 @@ describe('#integration-rx transaction', () => { ]) } - async function verifyFailsWithWrongStatement (txc) { + async function verifyFailsWithWrongQuery (txc) { const result = await txc .run('RETURN') .records() diff --git a/test/session.test.js b/test/session.test.js index 64dc88b7f..ade93fff1 100644 --- a/test/session.test.js +++ b/test/session.test.js @@ -18,7 +18,7 @@ */ import neo4j from '../src' -import { statementType } from '../src/result-summary' +import { queryType } from '../src/result-summary' import Session from '../src/session' import { READ } from '../src/driver' import SingleConnectionProvider from '../src/internal/connection-provider-single' @@ -167,16 +167,16 @@ describe('#integration session', () => { }) }) - it('should accept a statement object ', done => { + it('should accept a query object ', done => { // Given - const statement = { + const query = { text: 'RETURN 1 = $param AS a', parameters: { param: 1 } } // When & Then const records = [] - session.run(statement).subscribe({ + session.run(query).subscribe({ onNext: record => { records.push(record) }, @@ -214,26 +214,26 @@ describe('#integration session', () => { it('should expose summarize method for basic metadata ', done => { // Given - const statement = 'CREATE (n:Label {prop: $prop}) RETURN n' + const query = 'CREATE (n:Label {prop: $prop}) RETURN n' const params = { prop: 'string' } // When & Then - session.run(statement, params).then(result => { + session.run(query, params).then(result => { const sum = result.summary - expect(sum.statement.text).toBe(statement) - expect(sum.statement.parameters).toBe(params) + expect(sum.query.text).toBe(query) + expect(sum.query.parameters).toBe(params) expect(sum.counters.containsUpdates()).toBe(true) expect(sum.counters.updates().nodesCreated).toBe(1) - expect(sum.statementType).toBe(statementType.READ_WRITE) + expect(sum.queryType).toBe(queryType.READ_WRITE) done() }) }) it('should expose server info on successful query', done => { // Given - const statement = 'RETURN 1' + const query = 'RETURN 1' // When & Then - session.run(statement).then(result => { + session.run(query).then(result => { const sum = result.summary expect(sum.server).toBeDefined() expect(sum.server.address).toEqual('localhost:7687') @@ -244,10 +244,10 @@ describe('#integration session', () => { it('should expose execution time information', done => { // Given - const statement = 'UNWIND range(1,10000) AS n RETURN n AS number' + const query = 'UNWIND range(1,10000) AS n RETURN n AS number' // When & Then - session.run(statement).then(result => { + session.run(query).then(result => { const sum = result.summary expect(result.records.length).toBe(10000) expect(sum.resultAvailableAfter.toInt()).not.toBeLessThan(0) @@ -258,21 +258,21 @@ describe('#integration session', () => { it('should expose empty parameter map on call with no parameters', done => { // Given - const statement = "CREATE (n:Label {prop:'string'}) RETURN n" + const query = "CREATE (n:Label {prop:'string'}) RETURN n" // When & Then - session.run(statement).then(result => { + session.run(query).then(result => { const sum = result.summary - expect(sum.statement.parameters).toEqual({}) + expect(sum.query.parameters).toEqual({}) done() }) }) it('should expose plan ', done => { // Given - const statement = 'EXPLAIN CREATE (n:Label {prop: $prop}) RETURN n' + const query = 'EXPLAIN CREATE (n:Label {prop: $prop}) RETURN n' const params = { prop: 'string' } // When & Then - session.run(statement, params).then(result => { + session.run(query, params).then(result => { const sum = result.summary expect(sum.hasPlan()).toBe(true) expect(sum.hasProfile()).toBe(false) @@ -286,10 +286,10 @@ describe('#integration session', () => { it('should expose profile ', done => { // Given - const statement = 'PROFILE MATCH (n:Label {prop: $prop}) RETURN n' + const query = 'PROFILE MATCH (n:Label {prop: $prop}) RETURN n' const params = { prop: 'string' } // When & Then - session.run(statement, params).then(result => { + session.run(query, params).then(result => { const sum = result.summary expect(sum.hasPlan()).toBe(true) // When there's a profile, there's a plan expect(sum.hasProfile()).toBe(true) @@ -304,9 +304,9 @@ describe('#integration session', () => { it('should expose cypher notifications ', done => { // Given - const statement = 'EXPLAIN MATCH (n:ThisLabelDoesNotExist) RETURN n' + const query = 'EXPLAIN MATCH (n:ThisLabelDoesNotExist) RETURN n' // When & Then - session.run(statement).then(result => { + session.run(query).then(result => { const sum = result.summary expect(sum.notifications.length).toBeGreaterThan(0) expect(sum.notifications[0].code).toBe( @@ -327,7 +327,7 @@ describe('#integration session', () => { // Then session.run('RETURN 42').catch(error => { expect(error.message).toBe( - 'Statements cannot be run directly on a ' + + 'Queries cannot be run directly on a ' + 'session with an open transaction; either run from within the ' + 'transaction or use a different session.' ) @@ -402,15 +402,15 @@ describe('#integration session', () => { throw Error() } - const statement = 'RETURN $param' + const query = 'RETURN $param' const params = { param: unpackable } // When & Then - session.run(statement, params).catch(ignore => { + session.run(query, params).catch(ignore => { done() }) }) - it('should fail nicely for illegal statement', () => { + it('should fail nicely for illegal query', () => { expect(() => session.run()).toThrowError(TypeError) expect(() => session.run(null)).toThrowError(TypeError) expect(() => session.run({})).toThrowError(TypeError) @@ -419,9 +419,7 @@ describe('#integration session', () => { expect(() => session.run('')).toThrowError(TypeError) expect(() => session.run(['CREATE ()'])).toThrowError(TypeError) - expect(() => session.run({ statement: 'CREATE ()' })).toThrowError( - TypeError - ) + expect(() => session.run({ query: 'CREATE ()' })).toThrowError(TypeError) expect(() => session.run({ cypher: 'CREATE ()' })).toThrowError(TypeError) }) diff --git a/test/summary.test.js b/test/summary.test.js index 35556bede..de543da41 100644 --- a/test/summary.test.js +++ b/test/summary.test.js @@ -97,10 +97,10 @@ describe('#integration result summary', () => { session.run("CREATE (p:Person { Name: 'Test'})").then(result => { const summary = result.summary - expect(summary.statement.text).toBe("CREATE (p:Person { Name: 'Test'})") - expect(summary.statement.parameters).toEqual({}) + expect(summary.query.text).toBe("CREATE (p:Person { Name: 'Test'})") + expect(summary.query.parameters).toEqual({}) - expect(summary.statementType).toBe('w') + expect(summary.queryType).toBe('w') expect(summary.plan).toBe(false) expect(summary.profile).toBe(false) expect(summary.notifications).toEqual([]) @@ -160,8 +160,8 @@ describe('#integration result summary', () => { }) } - function verifyNotifications (session, statement, done) { - session.run(statement).then(result => { + function verifyNotifications (session, query, done) { + session.run(query).then(result => { const summary = result.summary expect(summary.notifications).toBeDefined() expect(summary.notifications.length).toBe(1) diff --git a/test/transaction.test.js b/test/transaction.test.js index 74346edcd..2e989314f 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -146,7 +146,7 @@ describe('#integration transaction', () => { await expectAsync(tx.run('CREATE (:TXNode2)')).toBeRejectedWith( jasmine.objectContaining({ message: jasmine.stringMatching( - /Cannot run statement in this transaction, because .* error/ + /Cannot run query in this transaction, because .* error/ ) }) ) @@ -176,7 +176,7 @@ describe('#integration transaction', () => { ) }) - it('should handle when committing when another statement fails', async () => { + it('should handle when committing when another query fails', async () => { // When const tx = session.beginTransaction() @@ -242,13 +242,13 @@ describe('#integration transaction', () => { await expectAsync(tx.run('RETURN 42')).toBeRejectedWith( jasmine.objectContaining({ message: jasmine.stringMatching( - /Cannot run statement in this transaction, because .* rolled back/ + /Cannot run query in this transaction, because .* rolled back/ ) }) ) }) - it('should fail running when a previous statement failed', async () => { + it('should fail running when a previous query failed', async () => { const tx = session.beginTransaction() await expectAsync(tx.run('THIS IS NOT CYPHER')).toBeRejectedWith( @@ -258,7 +258,7 @@ describe('#integration transaction', () => { await expectAsync(tx.run('RETURN 42')).toBeRejectedWith( jasmine.objectContaining({ message: jasmine.stringMatching( - /Cannot run statement in this transaction, because .* an error/ + /Cannot run query in this transaction, because .* an error/ ) }) ) @@ -446,10 +446,10 @@ describe('#integration transaction', () => { }) it('should expose server info on successful query', done => { - const statement = 'RETURN 1' + const query = 'RETURN 1' const tx = session.beginTransaction() - tx.run(statement) + tx.run(query) .then(result => { const sum = result.summary expect(sum.server).toBeDefined() @@ -462,11 +462,11 @@ describe('#integration transaction', () => { it('should expose server info on successful query using observer', done => { // Given - const statement = 'RETURN 1' + const query = 'RETURN 1' // When & Then const tx = session.beginTransaction() - tx.run(statement).subscribe({ + tx.run(query).subscribe({ onNext: record => {}, onError: () => {}, onCompleted: summary => { @@ -481,7 +481,7 @@ describe('#integration transaction', () => { }) }) - it('should fail nicely for illegal statement', async () => { + it('should fail nicely for illegal query', async () => { const tx = session.beginTransaction() expect(() => tx.run()).toThrowError(TypeError) @@ -491,15 +491,15 @@ describe('#integration transaction', () => { expect(() => tx.run([])).toThrowError(TypeError) expect(() => tx.run(['CREATE ()'])).toThrowError(TypeError) - expect(() => tx.run({ statement: 'CREATE ()' })).toThrowError(TypeError) + expect(() => tx.run({ query: 'CREATE ()' })).toThrowError(TypeError) expect(() => tx.run({ cypher: 'CREATE ()' })).toThrowError(TypeError) }) - it('should accept a statement object ', done => { + it('should accept a query object ', done => { const tx = session.beginTransaction() - const statement = { text: 'RETURN 1 AS a' } + const query = { text: 'RETURN 1 AS a' } - tx.run(statement) + tx.run(query) .then(result => { expect(result.records.length).toBe(1) expect(result.records[0].get('a').toInt()).toBe(1) diff --git a/test/types/driver.test.ts b/test/types/driver.test.ts index 5ca333a36..418850fcc 100644 --- a/test/types/driver.test.ts +++ b/test/types/driver.test.ts @@ -26,7 +26,7 @@ import Driver, { TrustStrategy, WRITE } from '../../types/driver' -import { Parameters } from '../../types/statement-runner' +import { Parameters } from '../../types/query-runner' import Session from '../../types/session' import { Neo4jError } from '../../types/error' import { ServerInfo } from '../../types/result-summary' diff --git a/test/types/result-summary.test.ts b/test/types/result-summary.test.ts index 8f23fbed6..9b644c979 100644 --- a/test/types/result-summary.test.ts +++ b/test/types/result-summary.test.ts @@ -23,7 +23,7 @@ import ResultSummary, { Plan, ProfiledPlan, ServerInfo, - StatementStatistic + QueryStatistic } from '../../types/result-summary' import Integer from '../../types/integer' @@ -31,13 +31,13 @@ const dummy: any = null const sum1: ResultSummary = dummy -const stmt = sum1.statement +const stmt = sum1.query const stmtText: string = stmt.text const stmtParams: object = stmt.parameters -const str: string = sum1.statementType +const str: string = sum1.queryType -const counters: StatementStatistic = sum1.counters +const counters: QueryStatistic = sum1.counters const containsUpdates: boolean = counters.containsUpdates() const containsSystemUpdates: boolean = counters.containsSystemUpdates() diff --git a/test/types/session.test.ts b/test/types/session.test.ts index 162246e91..0c8181f00 100644 --- a/test/types/session.test.ts +++ b/test/types/session.test.ts @@ -20,7 +20,7 @@ import Session, { TransactionConfig } from '../../types/session' import Transaction from '../../types/transaction' import Record from '../../types/record' -import Result, { StatementResult } from '../../types/result' +import Result, { QueryResult } from '../../types/result' import ResultSummary from '../../types/result-summary' import Integer from '../../types/integer' @@ -80,7 +80,7 @@ const close2: Promise = session.close().then(() => { const result1: Result = session.run('RETURN 1') result1 - .then((res: StatementResult) => { + .then((res: QueryResult) => { const records: Record[] = res.records const summary: ResultSummary = res.summary console.log(records) @@ -107,7 +107,7 @@ result2.subscribe({ const result3: Result = session.run('RETURN $value', { value: '42' }) result3 - .then((res: StatementResult) => { + .then((res: QueryResult) => { const records: Record[] = res.records const summary: ResultSummary = res.summary console.log(records) @@ -134,7 +134,7 @@ result4.subscribe({ const result5: Result = session.run('RETURN $value', { value: '42' }, txConfig1) result5 - .then((res: StatementResult) => { + .then((res: QueryResult) => { const records: Record[] = res.records const summary: ResultSummary = res.summary console.log(records) diff --git a/test/types/transaction.test.ts b/test/types/transaction.test.ts index 4c05ba53f..173550690 100644 --- a/test/types/transaction.test.ts +++ b/test/types/transaction.test.ts @@ -19,7 +19,7 @@ import Transaction from '../../types/transaction' import Record from '../../types/record' -import Result, { StatementResult } from '../../types/result' +import Result, { QueryResult } from '../../types/result' import ResultSummary from '../../types/result-summary' const dummy: any = null @@ -31,7 +31,7 @@ console.log(isOpen) const result1: Result = tx.run('RETURN 1') result1 - .then((res: StatementResult) => { + .then((res: QueryResult) => { const records: Record[] = res.records const summary: ResultSummary = res.summary console.log(records) @@ -58,7 +58,7 @@ result2.subscribe({ const result3: Result = tx.run('RETURN $value', { value: '42' }) result3 - .then((res: StatementResult) => { + .then((res: QueryResult) => { const records: Record[] = res.records const summary: ResultSummary = res.summary console.log(records) diff --git a/types/driver.d.ts b/types/driver.d.ts index c4f9ffc39..214983057 100644 --- a/types/driver.d.ts +++ b/types/driver.d.ts @@ -19,7 +19,7 @@ import Session from './session' import RxSession from './session-rx' -import { Parameters } from './statement-runner' +import { Parameters } from './query-runner' import { Neo4jError } from './error' import { ServerInfo } from './result-summary' diff --git a/types/index.d.ts b/types/index.d.ts index f1be5959a..90b49f76b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -46,14 +46,14 @@ import { SERVICE_UNAVAILABLE, SESSION_EXPIRED } from './error' -import Result, { ResultObserver, StatementResult } from './result' +import Result, { ResultObserver, QueryResult } from './result' import ResultSummary, { Notification, NotificationPosition, Plan, ProfiledPlan, ServerInfo, - StatementStatistic + QueryStatistic } from './result-summary' import Record from './record' import Session from './session' @@ -68,7 +68,7 @@ import { WRITE } from './driver' import Transaction from './transaction' -import { Parameters } from './statement-runner' +import { Parameters } from './query-runner' declare const auth: { basic: (username: string, password: string, realm?: string) => AuthToken @@ -174,12 +174,12 @@ declare const forExport: { Integer: Integer Record: Record Result: Result - StatementResult: StatementResult + QueryResult: QueryResult ResultObserver: ResultObserver ResultSummary: ResultSummary Plan: Plan ProfiledPlan: ProfiledPlan - StatementStatistic: StatementStatistic + QueryStatistic: QueryStatistic Notification: Notification ServerInfo: ServerInfo NotificationPosition: NotificationPosition @@ -227,12 +227,12 @@ export { Integer, Record, Result, - StatementResult, + QueryResult, ResultObserver, ResultSummary, Plan, ProfiledPlan, - StatementStatistic, + QueryStatistic, Notification, ServerInfo, NotificationPosition, diff --git a/types/statement-runner.d.ts b/types/query-runner.d.ts similarity index 86% rename from types/statement-runner.d.ts rename to types/query-runner.d.ts index 026fe2258..6f019bf25 100644 --- a/types/statement-runner.d.ts +++ b/types/query-runner.d.ts @@ -21,10 +21,10 @@ import Result from './result' declare type Parameters = { [key: string]: any } -declare interface StatementRunner { - run(statement: string, parameters?: Parameters): Result +declare interface QueryRunner { + run(query: string, parameters?: Parameters): Result } export { Parameters } -export default StatementRunner +export default QueryRunner diff --git a/types/result-summary.d.ts b/types/result-summary.d.ts index 53100d850..a33923538 100644 --- a/types/result-summary.d.ts +++ b/types/result-summary.d.ts @@ -21,9 +21,9 @@ import Integer from './integer' import { NumberOrInteger } from './graph-types' declare interface ResultSummary { - statement: { text: string; parameters: { [key: string]: any } } - statementType: string - counters: StatementStatistic + query: { text: string; parameters: { [key: string]: any } } + queryType: string + counters: QueryStatistic plan: Plan profile: ProfiledPlan notifications: Notification[] @@ -59,7 +59,7 @@ declare interface ProfiledPlan { children: ProfiledPlan[] } -declare interface StatementStatistic { +declare interface QueryStatistic { containsUpdates(): boolean containsSystemUpdates(): boolean @@ -88,7 +88,7 @@ declare interface ServerInfo { version: string } -declare const statementType: { +declare const queryType: { READ_ONLY: 'r' READ_WRITE: 'rw' WRITE_ONLY: 'w' @@ -96,10 +96,10 @@ declare const statementType: { } export { - statementType, + queryType, Plan, ProfiledPlan, - StatementStatistic, + QueryStatistic, Notification, ServerInfo, NotificationPosition diff --git a/types/result.d.ts b/types/result.d.ts index 022f38a18..4b8ddb3e6 100644 --- a/types/result.d.ts +++ b/types/result.d.ts @@ -20,7 +20,7 @@ import ResultSummary from './result-summary' import Record from './record' -declare type StatementResult = { +declare type QueryResult = { records: Record[] summary: ResultSummary } @@ -32,9 +32,9 @@ declare type ResultObserver = { onError?(error: Error): void } -declare interface Result extends Promise { +declare interface Result extends Promise { subscribe(observer: ResultObserver): void } -export { StatementResult, ResultObserver } +export { QueryResult, ResultObserver } export default Result diff --git a/types/session-rx.d.ts b/types/session-rx.d.ts index ec6d4ee6a..5a2d76584 100644 --- a/types/session-rx.d.ts +++ b/types/session-rx.d.ts @@ -19,14 +19,14 @@ import RxResult from './result-rx' import RxTransaction from './transaction-rx' import { TransactionConfig } from './session' -import { Parameters } from './statement-runner' +import { Parameters } from './query-runner' import { Observable } from 'rxjs' declare type RxTransactionWork = (tx: RxTransaction) => Observable declare interface RxSession { run( - statement: string, + query: string, parameters?: Parameters, config?: TransactionConfig ): RxResult diff --git a/types/session.d.ts b/types/session.d.ts index 14b3d442e..3368a5ee6 100644 --- a/types/session.d.ts +++ b/types/session.d.ts @@ -18,7 +18,7 @@ */ import Transaction from './transaction' -import StatementRunner, { Parameters } from './statement-runner' +import QueryRunner, { Parameters } from './query-runner' import Result from './result' import { NumberOrInteger } from './graph-types' @@ -29,9 +29,9 @@ declare interface TransactionConfig { metadata?: object } -declare interface Session extends StatementRunner { +declare interface Session extends QueryRunner { run( - statement: string, + query: string, parameters?: Parameters, config?: TransactionConfig ): Result diff --git a/types/transaction-rx.d.ts b/types/transaction-rx.d.ts index a7719224a..b260776a3 100644 --- a/types/transaction-rx.d.ts +++ b/types/transaction-rx.d.ts @@ -17,11 +17,11 @@ * limitations under the License. */ import { Observable } from 'rxjs' -import { Parameters } from './statement-runner' +import { Parameters } from './query-runner' import RxResult from './result-rx' declare interface RxTransaction { - run(statement: string, parameters?: Parameters): RxResult + run(query: string, parameters?: Parameters): RxResult commit(): Observable diff --git a/types/transaction.d.ts b/types/transaction.d.ts index 9ae2ae749..ff1877ecc 100644 --- a/types/transaction.d.ts +++ b/types/transaction.d.ts @@ -18,9 +18,9 @@ */ import Result from './result' -import StatementRunner from './statement-runner' +import QueryRunner from './query-runner' -declare interface Transaction extends StatementRunner { +declare interface Transaction extends QueryRunner { commit(): Promise rollback(): Promise