UNPKG

@breautek/storm

Version:

Object-Oriented REST API framework

82 lines (79 loc) 2.63 kB
"use strict"; /* Copyright 2017-2021 Norman Breau Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Query = void 0; class Query { constructor(parameters) { this.$params = parameters; } /** * @returns parameters that was passed into the constructor. */ getParameters() { return this.$params; } /** * Query implementations may override this API to augment the parameters. * * @returns parameters that will be used when this query is ran. */ getParametersForQuery() { return this.$params; } getQuery(connection) { return this._getQuery(connection); } /** * Overridable to execute statements before the main query. * Can be used to set session variables or create temporary tables, etc. * * @param connection * @returns */ onPreQuery(connection) { return Promise.resolve(); } /** * Overridable to execute statements after the main query. * Can be used to clean up session variables or temporary tables, etc * * Unlike {@link onPostProcess}, this hook does not provide the result set, * and will be invoked even if the main query produces an error. * * @since 8.3.0 * * @param connection * @returns {void} */ onPostQuery(connection) { return Promise.resolve(); } /** * Override to augment/manipulate the returned result set. * * @deprecated - Streaming queries does not support post processing, creating a confusing API * * @param connection The connection object used for this query execution. Useful if further queries are required. * @param resultset The original result set */ async onPostProcess(connection, resultSet) { // By default, simply return the result set without any post processing. return Promise.resolve(resultSet); } async execute(connection) { return connection.query(this); } } exports.Query = Query; //# sourceMappingURL=Query.js.map