Skip to content

Renamed Statement to Query #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var rxSession = driver.rxSession({
})
```

### Executing Statements
### Executing Queries

#### Consuming Records with Streaming API

Expand Down
6 changes: 3 additions & 3 deletions examples/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/internal/bolt-protocol-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -235,7 +235,7 @@ export default class BoltProtocol {
* @returns {StreamObserver} the stream observer that monitors the corresponding server response.
*/
run (
statement,
query,
parameters,
{
bookmark,
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions src/internal/bolt-protocol-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
}

run (
statement,
query,
parameters,
{
bookmark,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/internal/bolt-protocol-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
}

run (
statement,
query,
parameters,
{
bookmark,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 12 additions & 14 deletions src/internal/request-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { assertString } from './util'
const INIT = 0x01 // 0000 0001 // INIT <user_agent> <authentication_token>
const ACK_FAILURE = 0x0e // 0000 1110 // ACK_FAILURE - unused
const RESET = 0x0f // 0000 1111 // RESET
const RUN = 0x10 // 0001 0000 // RUN <statement> <parameters>
const RUN = 0x10 // 0001 0000 // RUN <query> <parameters>
const DISCARD_ALL = 0x2f // 0010 1111 // DISCARD_ALL - unused
const PULL_ALL = 0x3f // 0011 1111 // PULL_ALL

Expand Down Expand Up @@ -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)}`
)
}

Expand Down Expand Up @@ -146,27 +146,25 @@ 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.
* @param {string} mode the access mode.
* @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)}`
)
}

Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/internal/stream-observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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.
Expand Down
30 changes: 14 additions & 16 deletions src/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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.')
}
}

Expand All @@ -154,7 +152,7 @@ export {
assertNumber,
assertNumberOrInteger,
assertValidDate,
validateStatementAndParameters,
validateQueryAndParameters,
ENCRYPTION_ON,
ENCRYPTION_OFF
}
6 changes: 3 additions & 3 deletions src/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.'
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/result-rx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -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.*
*
Expand Down
Loading