Skip to content

Commit 1171d64

Browse files
committed
Statement->Query
1 parent 0a9c7fc commit 1171d64

29 files changed

+172
-198
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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

src/internal/util.js

Lines changed: 5 additions & 5 deletions
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
}
@@ -51,7 +51,7 @@ function isObject (obj) {
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) {
54+
function validateQueryAndParameters (statement, parameters) {
5555
let query = statement
5656
let params = parameters || {}
5757

@@ -60,7 +60,7 @@ function validateStatementAndParameters (statement, parameters) {
6060
params = statement.parameters || {}
6161
}
6262

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

6666
return { query, params }
@@ -122,7 +122,7 @@ function assertValidDate (obj, objName) {
122122
return obj
123123
}
124124

125-
function assertCypherStatement (obj) {
125+
function assertCypherQuery (obj) {
126126
assertString(obj, 'Cypher statement')
127127
if (obj.trim().length === 0) {
128128
throw new TypeError(
@@ -154,7 +154,7 @@ export {
154154
assertNumber,
155155
assertNumberOrInteger,
156156
assertValidDate,
157-
validateStatementAndParameters,
157+
validateQueryAndParameters,
158158
ENCRYPTION_ON,
159159
ENCRYPTION_OFF
160160
}

src/result-summary.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ import { isInt } from './integer'
2626
class ResultSummary {
2727
/**
2828
* @constructor
29-
* @param {string} statement - The statement this summary is for
30-
* @param {Object} parameters - Parameters for the statement
31-
* @param {Object} metadata - Statement metadata
29+
* @param {string} query - The query this summary is for
30+
* @param {Object} parameters - Parameters for the query
31+
* @param {Object} metadata - Query metadata
3232
*/
33-
constructor (statement, parameters, metadata) {
33+
constructor (query, parameters, metadata) {
3434
/**
35-
* The statement and parameters this summary is for.
35+
* The query and parameters this summary is for.
3636
* @type {{text: string, parameters: Object}}
3737
* @public
3838
*/
39-
this.statement = { text: statement, parameters }
39+
this.statement = { text: query, parameters }
4040

4141
/**
42-
* The type of statement executed. Can be "r" for read-only statement, "rw" for read-write statement,
43-
* "w" for write-only statement and "s" for schema-write statement.
44-
* String constants are available in {@link statementType} object.
42+
* The type of query executed. Can be "r" for read-only query, "rw" for read-write query,
43+
* "w" for write-only query and "s" for schema-write query.
44+
* String constants are available in {@link queryType} object.
4545
* @type {string}
4646
* @public
4747
*/
48-
this.statementType = metadata.type
48+
this.queryType = metadata.type
4949

5050
/**
51-
* Counters for operations the statement triggered.
52-
* @type {StatementStatistics}
51+
* Counters for operations the query triggered.
52+
* @type {QueryStatistics}
5353
* @public
5454
*/
55-
this.counters = new StatementStatistics(metadata.stats || {})
55+
this.counters = new QueryStatistics(metadata.stats || {})
5656
// for backwards compatibility, remove in future version
5757
this.updateStatistics = this.counters
5858

5959
/**
60-
* This describes how the database will execute the statement.
61-
* Statement plan for the executed statement if available, otherwise undefined.
60+
* This describes how the database will execute the query.
61+
* Query plan for the executed query if available, otherwise undefined.
6262
* Will only be populated for queries that start with "EXPLAIN".
6363
* @type {Plan}
6464
*/
@@ -68,8 +68,8 @@ class ResultSummary {
6868
: false
6969

7070
/**
71-
* This describes how the database did execute your statement. This will contain detailed information about what
72-
* each step of the plan did. Profiled statement plan for the executed statement if available, otherwise undefined.
71+
* This describes how the database did execute your query. This will contain detailed information about what
72+
* each step of the plan did. Profiled query plan for the executed query if available, otherwise undefined.
7373
* Will only be populated for queries that start with "PROFILE".
7474
* @type {ProfiledPlan}
7575
* @public
@@ -198,7 +198,7 @@ class ProfiledPlan {
198198
* Get statistical information for a {@link Result}.
199199
* @access public
200200
*/
201-
class StatementStatistics {
201+
class QueryStatistics {
202202
/**
203203
* Structurize the statistics
204204
* @constructor

src/session-rx.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ export default class RxSession {
4646
* transaction configuration that applies to the underlying auto-commit transaction.
4747
*
4848
* @public
49-
* @param {string} statement - Statement to be executed.
50-
* @param {Object} parameters - Parameter values to use in statement execution.
49+
* @param {string} query - Query to be executed.
50+
* @param {Object} parameters - Parameter values to use in query execution.
5151
* @param {TransactionConfig} transactionConfig - Configuration for the new auto-commit transaction.
5252
* @returns {RxResult} - A reactive result
5353
*/
54-
run (statement, parameters, transactionConfig) {
54+
run (query, parameters, transactionConfig) {
5555
return new RxResult(
5656
new Observable(observer => {
5757
try {
58-
observer.next(
59-
this._session.run(statement, parameters, transactionConfig)
60-
)
58+
observer.next(this._session.run(query, parameters, transactionConfig))
6159
observer.complete()
6260
} catch (err) {
6361
observer.error(err)

src/session.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import Result from './result'
2424
import Transaction from './transaction'
2525
import { newError } from './error'
26-
import { validateStatementAndParameters } from './internal/util'
26+
import { validateQueryAndParameters } from './internal/util'
2727
import ConnectionHolder from './internal/connection-holder'
2828
import Driver from './driver'
2929
import { ACCESS_MODE_READ, ACCESS_MODE_WRITE } from './internal/constants'
@@ -89,22 +89,22 @@ class Session {
8989
* or with the statement and parameters as separate arguments.
9090
*
9191
* @public
92-
* @param {mixed} statement - Cypher statement to execute
92+
* @param {mixed} query - Cypher statement to execute
9393
* @param {Object} parameters - Map with parameters to use in statement
9494
* @param {TransactionConfig} [transactionConfig] - configuration for the new auto-commit transaction.
9595
* @return {Result} - New Result
9696
*/
97-
run (statement, parameters, transactionConfig) {
98-
const { query, params } = validateStatementAndParameters(
99-
statement,
97+
run (query, parameters, transactionConfig) {
98+
const { validatedQuery, params } = validateQueryAndParameters(
99+
query,
100100
parameters
101101
)
102102
const autoCommitTxConfig = transactionConfig
103103
? new TxConfig(transactionConfig)
104104
: TxConfig.empty()
105105

106-
return this._run(query, params, connection =>
107-
connection.protocol().run(query, params, {
106+
return this._run(validatedQuery, params, connection =>
107+
connection.protocol().run(validatedQuery, params, {
108108
bookmark: this._lastBookmark,
109109
txConfig: autoCommitTxConfig,
110110
mode: this._mode,
@@ -116,7 +116,7 @@ class Session {
116116
)
117117
}
118118

119-
_run (statement, parameters, customRunner) {
119+
_run (query, parameters, customRunner) {
120120
const connectionHolder = this._connectionHolderWithMode(this._mode)
121121

122122
let observerPromise
@@ -135,14 +135,14 @@ class Session {
135135
observerPromise = Promise.resolve(
136136
new FailedObserver({
137137
error: newError(
138-
'Statements cannot be run directly on a ' +
138+
'Queries cannot be run directly on a ' +
139139
'session with an open transaction; either run from within the ' +
140140
'transaction or use a different session.'
141141
)
142142
})
143143
)
144144
}
145-
return new Result(observerPromise, statement, parameters, connectionHolder)
145+
return new Result(observerPromise, query, parameters, connectionHolder)
146146
}
147147

148148
/**

src/transaction-rx.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ export default class RxTransaction {
3434
}
3535

3636
/**
37-
* Creates a reactive result that will execute the statement in this transaction, with the provided parameters.
37+
* Creates a reactive result that will execute the query in this transaction, with the provided parameters.
3838
*
3939
* @public
40-
* @param {string} statement - Statement to be executed.
41-
* @param {Object} parameters - Parameter values to use in statement execution.
40+
* @param {string} query - Query to be executed.
41+
* @param {Object} parameters - Parameter values to use in query execution.
4242
* @returns {RxResult} - A reactive result
4343
*/
4444

45-
run (statement, parameters) {
45+
run (query, parameters) {
4646
return new RxResult(
4747
new Observable(observer => {
4848
try {
49-
observer.next(this._txc.run(statement, parameters))
49+
observer.next(this._txc.run(query, parameters))
5050
observer.complete()
5151
} catch (err) {
5252
observer.error(err)
@@ -75,7 +75,7 @@ export default class RxTransaction {
7575
}
7676

7777
/**
78-
* Rollbacks the transaction.
78+
* Rolls back the transaction.
7979
*
8080
* @public
8181
* @returns {Observable} - An empty observable

src/transaction.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919
import Result from './result'
20-
import { validateStatementAndParameters } from './internal/util'
20+
import { validateQueryAndParameters } from './internal/util'
2121
import ConnectionHolder, {
2222
EMPTY_CONNECTION_HOLDER
2323
} from './internal/connection-holder'
@@ -82,10 +82,7 @@ class Transaction {
8282
* @return {Result} New Result
8383
*/
8484
run (statement, parameters) {
85-
const { query, params } = validateStatementAndParameters(
86-
statement,
87-
parameters
88-
)
85+
const { query, params } = validateQueryAndParameters(statement, parameters)
8986

9087
var result = this._state.run(query, params, {
9188
connectionHolder: this._connectionHolder,

test/internal/fake-connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class FakeConnection extends Connection {
3838

3939
this.resetInvoked = 0
4040
this.releaseInvoked = 0
41-
this.seenStatements = []
41+
this.seenQueries = []
4242
this.seenParameters = []
4343
this.seenProtocolOptions = []
4444
this._server = {}
@@ -72,7 +72,7 @@ export default class FakeConnection extends Connection {
7272
// return fake protocol object that simply records seen statements and parameters
7373
return {
7474
run: (statement, parameters, protocolOptions) => {
75-
this.seenStatements.push(statement)
75+
this.seenQueries.push(statement)
7676
this.seenParameters.push(parameters)
7777
this.seenProtocolOptions.push(protocolOptions)
7878
}

test/internal/routing-util.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('#unit RoutingUtil', () => {
101101
const session = FakeSession.withFakeConnection(connection)
102102

103103
callRoutingProcedure(session, '', {}).then(() => {
104-
expect(connection.seenStatements).toEqual([
104+
expect(connection.seenQueries).toEqual([
105105
'CALL dbms.cluster.routing.getRoutingTable($context)'
106106
])
107107
expect(connection.seenParameters).toEqual([{ context: {} }])
@@ -115,7 +115,7 @@ describe('#unit RoutingUtil', () => {
115115

116116
callRoutingProcedure(session, '', { key1: 'value1', key2: 'value2' }).then(
117117
() => {
118-
expect(connection.seenStatements).toEqual([
118+
expect(connection.seenQueries).toEqual([
119119
'CALL dbms.cluster.routing.getRoutingTable($context)'
120120
])
121121
expect(connection.seenParameters).toEqual([
@@ -131,7 +131,7 @@ describe('#unit RoutingUtil', () => {
131131
const session = FakeSession.withFakeConnection(connection)
132132

133133
callRoutingProcedure(session, '', {}).then(() => {
134-
expect(connection.seenStatements).toEqual([
134+
expect(connection.seenQueries).toEqual([
135135
'CALL dbms.cluster.routing.getRoutingTable($context)'
136136
])
137137
expect(connection.seenParameters).toEqual([{ context: {} }])
@@ -144,7 +144,7 @@ describe('#unit RoutingUtil', () => {
144144
const session = FakeSession.withFakeConnection(connection)
145145

146146
callRoutingProcedure(session, '', { key1: 'foo', key2: 'bar' }).then(() => {
147-
expect(connection.seenStatements).toEqual([
147+
expect(connection.seenQueries).toEqual([
148148
'CALL dbms.cluster.routing.getRoutingTable($context)'
149149
])
150150
expect(connection.seenParameters).toEqual([
@@ -181,7 +181,7 @@ describe('#unit RoutingUtil', () => {
181181

182182
await callRoutingProcedure(session, '', {})
183183

184-
expect(connection.seenStatements).toEqual([
184+
expect(connection.seenQueries).toEqual([
185185
'CALL dbms.routing.getRoutingTable($context, $database)'
186186
])
187187
expect(connection.seenParameters).toEqual([
@@ -208,7 +208,7 @@ describe('#unit RoutingUtil', () => {
208208

209209
await callRoutingProcedure(session, '', {})
210210

211-
expect(connection.seenStatements).toEqual([
211+
expect(connection.seenQueries).toEqual([
212212
'CALL dbms.routing.getRoutingTable($context, $database)'
213213
])
214214
expect(connection.seenParameters).toEqual([
@@ -234,7 +234,7 @@ describe('#unit RoutingUtil', () => {
234234

235235
await callRoutingProcedure(session, '', {})
236236

237-
expect(connection.seenStatements).toEqual([
237+
expect(connection.seenQueries).toEqual([
238238
'CALL dbms.routing.getRoutingTable($context, $database)'
239239
])
240240
expect(connection.seenParameters).toEqual([
@@ -407,7 +407,7 @@ describe('#unit RoutingUtil', () => {
407407
const session = FakeSession.withFakeConnection(connection)
408408

409409
callRoutingProcedure(session, database, context).then(() => {
410-
expect(connection.seenStatements).toEqual([
410+
expect(connection.seenQueries).toEqual([
411411
'CALL dbms.routing.getRoutingTable($context, $database)'
412412
])
413413
expect(connection.seenParameters).toEqual([
@@ -523,7 +523,7 @@ describe('#unit RoutingUtil', () => {
523523
return new FakeSession(null, connection)
524524
}
525525

526-
_run (ignoreStatement, ignoreParameters, statementRunner) {
526+
_run (ignoreQuery, ignoreParameters, statementRunner) {
527527
if (this._runResponse) {
528528
return this._runResponse
529529
}

0 commit comments

Comments
 (0)