Sequelize

오픈소스·2022년 12월 3일
0
post-thumbnail

https://sequelize.org/

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

const sequelize = new Sequelize('sqlite::memory:');
const User = sequelize.define('User', {
  username: DataTypes.STRING,
  birthday: DataTypes.DATE,
});

(async () => {
  await User.sync();

  const jane = await User.create({
    username: 'janedoe',
    birthday: new Date(1980, 6, 20),
  });

  const users = await User.findAll();
  console.log(users);
})();
Executing (default): SELECT name FROM sqlite_master WHERE type='table' AND name='Users';
Executing (default): CREATE TABLE IF NOT EXISTS `Users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `username` VARCHAR(255), `birthday` DATETIME, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
Executing (default): PRAGMA INDEX_LIST(`Users`)
Executing (default): INSERT INTO `Users` (`id`,`username`,`birthday`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3,$4);
Executing (default): SELECT `id`, `username`, `birthday`, `createdAt`, `updatedAt` FROM `Users` AS `User`;
[
  User {
    dataValues: {
      id: 1,
      username: 'janedoe',
      birthday: 1980-07-19T15:00:00.000Z,
      createdAt: 2022-12-03T07:09:56.050Z,
      updatedAt: 2022-12-03T07:09:56.050Z
    },
    _previousDataValues: {
      id: 1,
      username: 'janedoe',
      birthday: 1980-07-19T15:00:00.000Z,
      createdAt: 2022-12-03T07:09:56.050Z,
      updatedAt: 2022-12-03T07:09:56.050Z
    },
    uniqno: 1,
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      raw: true,
      attributes: [Array]
    },
    isNewRecord: false
  }
]

0개의 댓글