Skip to content

Commit dfc4b83

Browse files
authored
Merge pull request #503 from zhenlineo/4.0-renaming
Renamed Statement to Query
2 parents 0a9c7fc + bca7222 commit dfc4b83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+406
-433
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ var rxSession = driver.rxSession({
173173
})
174174
```
175175

176-
### Executing Statements
176+
### Executing Queries
177177

178178
#### Consuming Records with Streaming API
179179

examples/node.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
var neo4j = require('neo4j')
2121

22-
var statement = [
22+
var query = [
2323
'MERGE (alice:Person {name:{name_a},age:{age_a}})',
2424
'MERGE (bob:Person {name:{name_b},age:{age_b}})',
2525
'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)',
@@ -36,7 +36,7 @@ var params = {
3636
var driver = neo4j.driver('bolt://localhost')
3737

3838
var streamSession = driver.session()
39-
var streamResult = streamSession.run(statement.join(' '), params)
39+
var streamResult = streamSession.run(query.join(' '), params)
4040
streamResult.subscribe({
4141
onNext: function (record) {
4242
// On receipt of RECORD
@@ -58,7 +58,7 @@ streamResult.subscribe({
5858
})
5959

6060
var promiseSession = driver.session()
61-
var promiseResult = promiseSession.run(statement.join(' '), params)
61+
var promiseResult = promiseSession.run(query.join(' '), params)
6262
promiseResult
6363
.then(function (records) {
6464
records.forEach(function (record) {

src/driver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let idGenerator = 0
5858

5959
/**
6060
* A driver maintains one or more {@link Session}s with a remote
61-
* Neo4j instance. Through the {@link Session}s you can send statements
61+
* Neo4j instance. Through the {@link Session}s you can send queries
6262
* and retrieve results from the database.
6363
*
6464
* Drivers are reasonably expensive to create - you should strive to keep one

src/internal/bolt-protocol-v1.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ export default class BoltProtocol {
217217
}
218218

219219
/**
220-
* Send a Cypher statement through the underlying connection.
221-
* @param {string} statement the cypher statement.
222-
* @param {Object} parameters the statement parameters.
220+
* Send a Cypher query through the underlying connection.
221+
* @param {string} query the cypher query.
222+
* @param {Object} parameters the query parameters.
223223
* @param {Object} param
224224
* @param {Bookmark} param.bookmark the bookmark.
225225
* @param {TxConfig} param.txConfig the transaction configuration.
@@ -235,7 +235,7 @@ export default class BoltProtocol {
235235
* @returns {StreamObserver} the stream observer that monitors the corresponding server response.
236236
*/
237237
run (
238-
statement,
238+
query,
239239
parameters,
240240
{
241241
bookmark,
@@ -267,7 +267,7 @@ export default class BoltProtocol {
267267
assertDatabaseIsEmpty(database, this._connection, observer)
268268

269269
this._connection.write(
270-
RequestMessage.run(statement, parameters),
270+
RequestMessage.run(query, parameters),
271271
observer,
272272
false
273273
)

src/internal/bolt-protocol-v3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
141141
}
142142

143143
run (
144-
statement,
144+
query,
145145
parameters,
146146
{
147147
bookmark,
@@ -171,7 +171,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
171171
assertDatabaseIsEmpty(database, this._connection, observer)
172172

173173
this._connection.write(
174-
RequestMessage.runWithMetadata(statement, parameters, {
174+
RequestMessage.runWithMetadata(query, parameters, {
175175
bookmark,
176176
txConfig,
177177
mode

src/internal/bolt-protocol-v4.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
5555
}
5656

5757
run (
58-
statement,
58+
query,
5959
parameters,
6060
{
6161
bookmark,
@@ -89,7 +89,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
8989

9090
const flushRun = reactive
9191
this._connection.write(
92-
RequestMessage.runWithMetadata(statement, parameters, {
92+
RequestMessage.runWithMetadata(query, parameters, {
9393
bookmark,
9494
txConfig,
9595
database,

src/internal/request-message.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { assertString } from './util'
2626
const INIT = 0x01 // 0000 0001 // INIT <user_agent> <authentication_token>
2727
const ACK_FAILURE = 0x0e // 0000 1110 // ACK_FAILURE - unused
2828
const RESET = 0x0f // 0000 1111 // RESET
29-
const RUN = 0x10 // 0001 0000 // RUN <statement> <parameters>
29+
const RUN = 0x10 // 0001 0000 // RUN <query> <parameters>
3030
const DISCARD_ALL = 0x2f // 0010 1111 // DISCARD_ALL - unused
3131
const PULL_ALL = 0x3f // 0011 1111 // PULL_ALL
3232

@@ -68,15 +68,15 @@ export default class RequestMessage {
6868

6969
/**
7070
* Create a new RUN message.
71-
* @param {string} statement the cypher statement.
72-
* @param {Object} parameters the statement parameters.
71+
* @param {string} query the cypher query.
72+
* @param {Object} parameters the query parameters.
7373
* @return {RequestMessage} new RUN message.
7474
*/
75-
static run (statement, parameters) {
75+
static run (query, parameters) {
7676
return new RequestMessage(
7777
RUN,
78-
[statement, parameters],
79-
() => `RUN ${statement} ${JSON.stringify(parameters)}`
78+
[query, parameters],
79+
() => `RUN ${query} ${JSON.stringify(parameters)}`
8080
)
8181
}
8282

@@ -146,27 +146,25 @@ export default class RequestMessage {
146146

147147
/**
148148
* Create a new RUN message with additional metadata.
149-
* @param {string} statement the cypher statement.
150-
* @param {Object} parameters the statement parameters.
149+
* @param {string} query the cypher query.
150+
* @param {Object} parameters the query parameters.
151151
* @param {Bookmark} bookmark the bookmark.
152152
* @param {TxConfig} txConfig the configuration.
153153
* @param {string} database the database name.
154154
* @param {string} mode the access mode.
155155
* @return {RequestMessage} new RUN message with additional metadata.
156156
*/
157157
static runWithMetadata (
158-
statement,
158+
query,
159159
parameters,
160160
{ bookmark, txConfig, database, mode } = {}
161161
) {
162162
const metadata = buildTxMetadata(bookmark, txConfig, database, mode)
163163
return new RequestMessage(
164164
RUN,
165-
[statement, parameters, metadata],
165+
[query, parameters, metadata],
166166
() =>
167-
`RUN ${statement} ${JSON.stringify(parameters)} ${JSON.stringify(
168-
metadata
169-
)}`
167+
`RUN ${query} ${JSON.stringify(parameters)} ${JSON.stringify(metadata)}`
170168
)
171169
}
172170

@@ -239,7 +237,7 @@ function buildTxMetadata (bookmark, txConfig, database, mode) {
239237

240238
/**
241239
* Create an object that represents streaming metadata.
242-
* @param {Integer|number} stmtId The statement id to stream its results.
240+
* @param {Integer|number} stmtId The query id to stream its results.
243241
* @param {Integer|number} n The number of records to stream.
244242
* @returns {Object} a metadata object.
245243
*/

src/internal/stream-observers.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ResultStreamObserver extends StreamObserver {
9292
this._beforeComplete = beforeComplete
9393
this._afterComplete = afterComplete
9494

95-
this._statementId = null
95+
this._queryId = null
9696
this._moreFunction = moreFunction
9797
this._discardFunction = discardFunction
9898
this._discard = false
@@ -140,7 +140,7 @@ class ResultStreamObserver extends StreamObserver {
140140
// Extract server generated query id for use in requestMore and discard
141141
// functions
142142
if (meta.qid) {
143-
this._statementId = meta.qid
143+
this._queryId = meta.qid
144144

145145
// remove qid from metadata object
146146
delete meta.qid
@@ -236,11 +236,11 @@ class ResultStreamObserver extends StreamObserver {
236236
this._streaming = true
237237

238238
if (this._discard) {
239-
this._discardFunction(this._connection, this._statementId, this)
239+
this._discardFunction(this._connection, this._queryId, this)
240240
} else {
241241
this._moreFunction(
242242
this._connection,
243-
this._statementId,
243+
this._queryId,
244244
this._fetchSize,
245245
this
246246
)
@@ -261,7 +261,7 @@ class ResultStreamObserver extends StreamObserver {
261261

262262
/**
263263
* Stream observer defaults to handling responses for two messages: RUN + PULL_ALL or RUN + DISCARD_ALL.
264-
* Response for RUN initializes statement keys. Response for PULL_ALL / DISCARD_ALL exposes the result stream.
264+
* Response for RUN initializes query keys. Response for PULL_ALL / DISCARD_ALL exposes the result stream.
265265
*
266266
* However, some operations can be represented as a single message which receives full metadata in a single response.
267267
* For example, operations to begin, commit and rollback an explicit transaction use two messages in Bolt V1 but a single message in Bolt V3.

src/internal/util.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function isEmptyObjectOrNull (obj) {
3131
return false
3232
}
3333

34-
for (let prop in obj) {
34+
for (const prop in obj) {
3535
if (obj.hasOwnProperty(prop)) {
3636
return false
3737
}
@@ -45,25 +45,25 @@ function isObject (obj) {
4545
}
4646

4747
/**
48-
* Check and normalize given statement and parameters.
49-
* @param {string|{text: string, parameters: object}} statement the statement to check.
48+
* Check and normalize given query and parameters.
49+
* @param {string|{text: string, parameters: object}} query the query to check.
5050
* @param {Object} parameters
5151
* @return {{query: string, params: object}} the normalized query with parameters.
5252
* @throws TypeError when either given query or parameters are invalid.
5353
*/
54-
function validateStatementAndParameters (statement, parameters) {
55-
let query = statement
54+
function validateQueryAndParameters (query, parameters) {
55+
let validatedQuery = query
5656
let params = parameters || {}
5757

58-
if (typeof statement === 'object' && statement.text) {
59-
query = statement.text
60-
params = statement.parameters || {}
58+
if (typeof query === 'object' && query.text) {
59+
validatedQuery = query.text
60+
params = query.parameters || {}
6161
}
6262

63-
assertCypherStatement(query)
63+
assertCypherQuery(validatedQuery)
6464
assertQueryParameters(params)
6565

66-
return { query, params }
66+
return { validatedQuery, params }
6767
}
6868

6969
function assertObject (obj, objName) {
@@ -122,12 +122,10 @@ function assertValidDate (obj, objName) {
122122
return obj
123123
}
124124

125-
function assertCypherStatement (obj) {
126-
assertString(obj, 'Cypher statement')
125+
function assertCypherQuery (obj) {
126+
assertString(obj, 'Cypher query')
127127
if (obj.trim().length === 0) {
128-
throw new TypeError(
129-
'Cypher statement is expected to be a non-empty string.'
130-
)
128+
throw new TypeError('Cypher query is expected to be a non-empty string.')
131129
}
132130
}
133131

@@ -154,7 +152,7 @@ export {
154152
assertNumber,
155153
assertNumberOrInteger,
156154
assertValidDate,
157-
validateStatementAndParameters,
155+
validateQueryAndParameters,
158156
ENCRYPTION_ON,
159157
ENCRYPTION_OFF
160158
}

src/record.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function generateFieldLookup (keys) {
2929

3030
/**
3131
* Records make up the contents of the {@link Result}, and is how you access
32-
* the output of a statement. A simple statement might yield a result stream
32+
* the output of a query. A simple query might yield a result stream
3333
* with a single record, for instance:
3434
*
3535
* MATCH (u:User) RETURN u.name, u.age
3636
*
3737
* This returns a stream of records with two fields, named `u.name` and `u.age`,
38-
* each record represents one user found by the statement above. You can access
38+
* each record represents one user found by the query above. You can access
3939
* the values of each field either by name:
4040
*
4141
* record.get("u.name")
@@ -147,7 +147,7 @@ class Record {
147147
"This record has no field with index '" +
148148
index +
149149
"'. Remember that indexes start at `0`, " +
150-
'and make sure your statement returns records in the shape you meant it to.'
150+
'and make sure your query returns records in the shape you meant it to.'
151151
)
152152
}
153153

src/result-rx.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export default class RxResult {
5656

5757
/**
5858
* Returns an observable that exposes a single item containing field names
59-
* returned by the executing statement.
59+
* returned by the executing query.
6060
*
61-
* Errors raised by actual statement execution can surface on the returned
61+
* Errors raised by actual query execution can surface on the returned
6262
* observable stream.
6363
*
6464
* @public
@@ -69,7 +69,7 @@ export default class RxResult {
6969
}
7070

7171
/**
72-
* Returns an observable that exposes each record returned by the executing statement.
72+
* Returns an observable that exposes each record returned by the executing query.
7373
*
7474
* Errors raised during the streaming phase can surface on the returned observable stream.
7575
*
@@ -89,7 +89,7 @@ export default class RxResult {
8989

9090
/**
9191
* Returns an observable that exposes a single item of {@link ResultSummary} that is generated by
92-
* the server after the streaming of the executing statement is completed.
92+
* the server after the streaming of the executing query is completed.
9393
*
9494
* *Subscribing to this stream before subscribing to records() stream causes the results to be discarded on the server.*
9595
*

0 commit comments

Comments
 (0)