Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an error when creating a structure file #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

turone
Copy link

@turone turone commented May 24, 2024

Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed ussues Metasql #291

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

turone added 2 commits May 23, 2024 18:51
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed ussues Metasql metarhia#291
@@ -201,6 +206,7 @@ const createEntity = (model, name) => {
}
sql[sql.length - 1] = sql[sql.length - 1].slice(0, -1);
sql.push(');');
if (delayedKeys[name]) idx.push(delayedKeys[name]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use intermediate variable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can:

const delayedKeyCurrent = delayedKeys[name];
  if (delayedKeyCurrent) idx.push(delayedKeyCurrent);

@@ -183,7 +183,12 @@ const createEntity = (model, name) => {
const ref = model.entities.get(def.type);
if (!ref) throw new Error(`Unknown schema: ${def.type}`);
const refId = ref.kind === 'registry';
idx.push(foreignKey(name, field, def, refId));
const fKey = foreignKey(name, field, def, refId);
if (def.type in delayedKeys && def.type !== name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite without in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delayedKeys is an object with fields filled with nulls, so reading the property via [ key ] will not work. Therefore, I can change it to hasOwnProperty or Object.prototype.hasOwnProperty.call. Or suggest something else? Because hasOwnProperty is almost 100 times slower, although it is not critical here, but this is system code - that's why I used 'in'. Write what to put.
in dbms.js

for (const key of model.order) {
    delayedKeys[key] = null;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants