From f04bd627a94e5a9009945cae9498d2665cef93ce Mon Sep 17 00:00:00 2001 From: georgolden Date: Sat, 13 Aug 2022 03:59:53 +0200 Subject: [PATCH] Update plugin to work wit the impress application sandbox PR-URL: https://github.com/metarhia/metasql/pull/250 --- CHANGELOG.md | 3 +++ lib/plugins/.eslintrc.json | 19 +++++++++++++++++++ lib/{ => plugins}/crud.js | 14 ++++++++------ metasql.js | 2 +- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 lib/plugins/.eslintrc.json rename lib/{ => plugins}/crud.js (66%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6370a8b..b2a1d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased][unreleased] - Using optional chaining operator +- Update crud plugin to work wit the impress application sandbox ## [2.0.5][] - 2022-07-11 @@ -128,6 +129,8 @@ Code before fork from https://github.com/metarhia/sql [unreleased]: https://github.com/metarhia/metasql/compare/v2.0.2...HEAD +[2.0.5]: https://github.com/metarhia/metasql/compare/v2.0.4...v2.0.5 +[2.0.4]: https://github.com/metarhia/metasql/compare/v2.0.2...v2.0.4 [2.0.2]: https://github.com/metarhia/metasql/compare/v2.0.1...v2.0.2 [2.0.1]: https://github.com/metarhia/metasql/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/metarhia/metasql/compare/v1.5.0...v2.0.0 diff --git a/lib/plugins/.eslintrc.json b/lib/plugins/.eslintrc.json new file mode 100644 index 0000000..30e09c0 --- /dev/null +++ b/lib/plugins/.eslintrc.json @@ -0,0 +1,19 @@ +{ + "globals": { + "api": "readonly", + "application": "readonly", + "config": "readonly", + "context": "readonly", + "node": "readonly", + "npm": "readonly", + "lib": "readonly", + "db": "readonly", + "bus": "readonly", + "domain": "readonly", + "metarhia": "readonly" + }, + "rules": { + "no-loop-func": ["off"], + "no-unused-vars": ["off"] + } +} diff --git a/lib/crud.js b/lib/plugins/crud.js similarity index 66% rename from lib/crud.js rename to lib/plugins/crud.js index 70f628d..6a028a4 100644 --- a/lib/crud.js +++ b/lib/plugins/crud.js @@ -2,34 +2,36 @@ module.exports = (init) => () => { const iface = {}; - const { entities, database } = init; + const { entities } = init; + const database = db.pg; for (const [entity, methods] of Object.entries(entities)) { if (methods.includes('create')) { - iface['create' + entity] = async (record) => { + iface['create' + entity] = (context) => async (record) => { const result = await database.insert(entity, record); return { result }; }; } if (methods.includes('get')) { - iface['get' + entity] = async (conditions) => { + iface['get' + entity] = (context) => async (conditions) => { const result = await database.row(entity, conditions); return { result }; }; } if (methods.includes('select')) { - iface['select' + entity] = async (conditions) => { + iface['select' + entity] = (context) => async (conditions) => { const result = await database.select(entity, conditions); return { result }; }; } if (methods.includes('update')) { - iface['update' + entity] = async ({ delta, conditions }) => { + iface['update' + entity] = (context) => async (args) => { + const { delta, conditions } = args; const result = await database.update(entity, delta, conditions); return { result }; }; } if (methods.includes('delete')) { - iface['delete' + entity] = () => async (conditions) => { + iface['delete' + entity] = (context) => async (conditions) => { const result = await database.delete(entity, conditions); return { result }; }; diff --git a/metasql.js b/metasql.js index 88ee155..4ca564e 100644 --- a/metasql.js +++ b/metasql.js @@ -2,7 +2,7 @@ const database = require('./lib/database.js'); const dbms = require('./lib/dbms.js'); -const crud = require('./lib/crud.js'); +const crud = require('./lib/plugins/crud.js'); require('./lib/pg.js');