UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

83 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SqlApiBase = exports.SqlApiModelBase = void 0; /** * Base class for the API's model. * * Inherit this to create a model for the API. * * APIのモデルの基底クラス。 * * これを継承してAPIのモデルを作成します。 */ class SqlApiModelBase { } exports.SqlApiModelBase = SqlApiModelBase; /** * Base class for the API. * * Inherit this to create an API. * * APIの基底クラス。 * * これを継承してAPIを作成します。 */ class SqlApiBase { /** * * @param {string} table * Table Name. * * テーブル名。 * * @param {"GET" | "POST" | "DELETE" | "PUT" | "COUNT"} method * Specify the method to be used. * * 使用するメソッドを指定します。 * * @param {{ [key: string]: any }[]} where * Specify the conditions for retrieving data from Sql. * * Sqlからデータを取得するための条件を指定します。 * * @param {{ [key: string]: any } | undefined} value * Data to be added to the table. * * テーブルに追加するデータ。 * * @returns {Promise<{ [key: string]: any }[] | number | null>} * When [null] is returned, the condition is not met. * * Otherwise, it returns the retrieved data. * * [null]が返却されたときは条件に一致しないとき。 * * その他の場合は取得されたデータを返します。 */ async process({ table, method, where, value, }) { if (table !== this.table) { return null; } switch (method) { case "GET": { return (await this.get(where ?? [])).map((e) => { return e.toJson(); }); } case "COUNT": { await this.count(where ?? []); return []; } case "POST": { return [(await this.post(value ?? {}, where ?? [])).toJson()]; } case "PUT": { return [(await this.put(value ?? {}, where ?? [])).toJson()]; } case "DELETE": { await this.delete(where ?? []); return []; } } } } exports.SqlApiBase = SqlApiBase; //# sourceMappingURL=sql_api_base.js.map