Skip to content

feat: add @Attribute & @Table decorators - #15336

Merged
ephys merged 6 commits into
mainfrom
ephys/attribute-table-decorators
Nov 27, 2022
Merged

ephys merged 6 commits into
mainfrom
ephys/attribute-table-decorators

Conversation

@ephys

@ephys ephys commented Nov 26, 2022

Copy link
Copy Markdown
Member

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

This PR implements @Table & @Attribute from sequelize-typescript (see #15334). @Column has been included as well but is deprecated and renamed to @Attribute.

This PR also introduces the ability to load models through the Sequelize constructor:

new Sequelize({
  models: [User, Projects],
});

As well as through the sequelize.addModels method.

const sequelize = new Sequelize();

sequelize.addModels([User, Projects]);

This is necessary because decorated models are only initialized once they are attached to Sequelize using either solution.

Unlike sequelize-typescript, these two options/methods are unable to load models from the filesystem themselves. importModels must be used instead. This is because importModels is async, as it uses import instead of require to be ESM-ready.

import { importModels, Sequelize } from '@sequelize/core';

new Sequelize({
  models: await importModels([__dirname + '/**/*.ts'])
});

I've only imported the tests from sequelize-typescript that weren't redundant with our existing tests.

@ephys ephys self-assigned this Nov 26, 2022
@ephys ephys mentioned this pull request Nov 26, 2022
13 of 15 tasks
WikiRik
WikiRik previously approved these changes Nov 26, 2022

@WikiRik WikiRik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one small comment

Comment thread src/sequelize.js Resolved
Comment thread test/unit/decorators/table.test.ts Resolved
@ephys
ephys merged commit fb8603b into main Nov 27, 2022
@ephys
ephys deleted the ephys/attribute-table-decorators branch November 27, 2022 12:00
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.

3 participants