Skip to content

Commit

Permalink
Update plugin to work wit the impress application sandbox
Browse files Browse the repository at this point in the history
PR-URL: #250
  • Loading branch information
georgolden authored and tshemsedinov committed Aug 13, 2022
1 parent 5e379cd commit f04bd62
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lib/plugins/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
14 changes: 8 additions & 6 deletions lib/crud.js → lib/plugins/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
Expand Down
2 changes: 1 addition & 1 deletion metasql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit f04bd62

Please sign in to comment.