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

Sequelize v6 compatibility? #844

Closed
spinlud opened this issue Oct 14, 2020 · 20 comments
Closed

Sequelize v6 compatibility? #844

spinlud opened this issue Oct 14, 2020 · 20 comments

Comments

@spinlud
Copy link

spinlud commented Oct 14, 2020

Is sequelize v6 compatibility still in beta? Any ETA?

@goalia
Copy link

goalia commented Oct 21, 2020

+1

3 similar comments
@QuanticPotatoes
Copy link

+1

@dgomez-orangeloops
Copy link

+1

@thetminko
Copy link

+1

@goalia
Copy link

goalia commented Oct 29, 2020

Apparently @next allow sequelize v6 compatibility #787
Any update @RobinBuschmann ? 🙏🏼

@theoludwig
Copy link
Contributor

Most likely this pull request added support for v6 compatibility #807.
What need to be done, to fully release sequelize-typescript@2.0 (as a stable release) ? @RobinBuschmann
Maybe we can help, to get this thing done! 🚀

@lukashroch
Copy link
Collaborator

lukashroch commented Nov 14, 2020

#807 should be compatible with v6 up to v6.1 only.

v6.2 introduced some breaking changes to types mostly. You can try #856 for latest (v6.3.5) support

@goalia
Copy link

goalia commented Nov 14, 2020

We tried to work with sequelize-typescript@next (2.0-beta) with Nest-Js, it works with sequelize v6.1. @RobinBuschmann we can help you to release v6.3.5 compatibility @lukashroch @divlo 🤷🏼‍♂️

@theoludwig
Copy link
Contributor

As discussed in #871.
I installed sequelize-typescript@2.0.0-beta.1 in my project and I've got many TypeScript errors...
It seems like it stills doesn't work.

Capture1_6

@goalia
Copy link

goalia commented Dec 27, 2020

Can you show us the « Invitation » model ?
I think it’s because you extends Model in your file like extends Model

@lukashroch
Copy link
Collaborator

Looks like you're using old v5 class declaration. You must update all models to reflect v6 changes.

@theoludwig
Copy link
Contributor

Yes, am I doing something wrong ? @goalia

Capture1_7

@lukashroch
Copy link
Collaborator

@divlo, check out #865, it describes the changes for model declarations

@theoludwig
Copy link
Contributor

Thanks @lukashroch! It solves the problem. 👍

@spinlud
Copy link
Author

spinlud commented Jan 10, 2021

I was testing the latest beta 2.0.0-beta.1, the following works with just sequelize v6.3.5:

import { Sequelize, Optional, Model, DataTypes } from 'sequelize';

interface PersonAttributes {
    id: number;
    name: string;
    country?: string;
}

interface PersonCreationAttributes extends Optional<PersonAttributes, 'country'> {}

class Person extends Model<PersonAttributes, PersonCreationAttributes> implements PersonAttributes {
    id!: number;
    name!: string;
    country?: string;
}


(async () => {
    const sequelize =  new Sequelize({
        dialect: 'mysql',
        host: 'localhost',
        port: 3306,
        database: 'testdb',
        username: 'admin',
        password: 'admin',
        logQueryParameters: true,
        logging: true,
    });

    await sequelize.authenticate();

    Person.init({
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        country: {
            type: DataTypes.STRING,
            allowNull: true
        }
    }, {
        tableName: 'Person',
        sequelize
    });

    await sequelize.sync();

    const p = new Person({
        id: 1,
        name: 'Ken'
    });

    await p.save();

    const persons = await Person.findAll();
    console.log(persons);

    await sequelize.close();
})();

The following does not work, using sequelize-typscript:

import { Optional } from 'sequelize';
import { Sequelize, Model } from "sequelize-typescript";

interface PersonAttributes {
    id: number;
    name: string;
    country?: string;
}

interface PersonCreationAttributes extends Optional<PersonAttributes, 'country'> {}

class Person extends Model<PersonAttributes, PersonCreationAttributes> implements PersonAttributes {
    id!: number;
    name!: string;
    country?: string;
}


(async () => {
    const sequelize =  new Sequelize({
        dialect: 'mysql',
        host: 'localhost',
        port: 3306,
        database: 'testdb',
        username: 'admin',
        password: 'admin',
        logQueryParameters: true,
        logging: true,
    });

    await sequelize.authenticate();
    
    await sequelize.addModels([Person]); // <-- compiler complains

    await sequelize.sync();

    const p = new Person({
        id: 1,
        name: 'Ken'
    });

    await p.save();

    const persons = await Person.findAll();
    console.log(persons);

    await sequelize.close();
})();

image

Am I missing something?

@goalia
Copy link

goalia commented Jan 11, 2021

Hello @spinlud, you need to replace the following:
class Person extends Model<PersonAttributes, PersonCreationAttributes> implements PersonAttributes
by class Person extends Model implements PersonAttributes
Normally, it should work properly 🎉 (checkout #865 for more details)

@spinlud
Copy link
Author

spinlud commented Jan 11, 2021

@goalia thanks but this solution doesn't provide type checking on model creation, which I guess is the main reason to extends Model<ModelAttributes, ModelCreationAttributes> signature. Is there any ongoing work on this?

@antonstjernquist
Copy link

@spinlud sequelize/sequelize#11820

This PR was created a long time ago. I'm not sure what to do :/

@spinlud
Copy link
Author

spinlud commented Jan 17, 2021

@antonstjernquist it looks like that that PR was left unmerged, this one has been merged instead sequelize/sequelize#12405.

There is this other PR #868 which seems trying to fix issue about Model generics signature

@theoludwig
Copy link
Contributor

sequelize-typescript@2.0.0 has been released! 😄
If you encounter bugs, feel free to open new issues!

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

No branches or pull requests

8 participants