Skip to content

Commit

Permalink
add inferred attributes, remove old model definition, remove decorato…
Browse files Browse the repository at this point in the history
…rs from PK
  • Loading branch information
johneatmon committed Feb 19, 2024
1 parent 37339a0 commit b6c9bef
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/sscce-sequelize-7.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreationOptional, DataTypes, Model } from '@sequelize/core';
import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from '@sequelize/core';
import {
Attribute,
AutoIncrement,
Expand Down Expand Up @@ -27,28 +27,15 @@ export async function run() {
},
});

class Foo extends Model {}

Foo.init({
name: DataTypes.TEXT,
}, {
sequelize,
modelName: 'Foo',
});

// You can also use the new decorators model definition
class Bar extends Model {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
class Foo extends Model<InferAttributes<Foo>, InferCreationAttributes<Foo>> {
declare id: CreationOptional<number>;

@Attribute(DataTypes.TEXT)
@NotNull
declare name: string;
}

sequelize.addModels([Bar]);
sequelize.addModels([Foo]);

// You can use sinon and chai assertions directly in your SSCCE.
const spy = sinon.spy();
Expand Down

0 comments on commit b6c9bef

Please sign in to comment.