sscce.ts 879 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { DataTypes, Model } from '@sequelize/core';
  2. import { Attribute } from '@sequelize/core/decorators-legacy';
  3. import { SqliteDialect } from '@sequelize/sqlite3';
  4. import { expect } from 'chai';
  5. import { createSequelizeInstance } from './dev/sscce-helpers';
  6. class User extends Model {
  7. @Attribute({
  8. type: DataTypes.STRING,
  9. allowNull: false,
  10. })
  11. declare username: string;
  12. @Attribute({
  13. type: DataTypes.DATE,
  14. allowNull: false,
  15. })
  16. declare birthday: Date;
  17. }
  18. const sequelize = createSequelizeInstance({
  19. dialect: SqliteDialect,
  20. benchmark: true,
  21. models: [User],
  22. });
  23. (async () => {
  24. await sequelize.sync({ force: true });
  25. const jane = await User.create({
  26. username: 'janedoe',
  27. birthday: new Date(1980, 6, 20),
  28. });
  29. console.log('\nJane:', jane.toJSON());
  30. await sequelize.close();
  31. expect(jane.username).to.equal('janedoe');
  32. })();