@MikeShi42/

sequelize test

Nodejs

No description

fork
loading
Files
  • index.js
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var sqlite = require("sqlite3")
var Sequelize = require("sequelize")

const sequelize = new Sequelize({
  database: 'db_name',
  username: 'username',
  password: null,
  dialect: 'sqlite',
  storage: ':memory:'
});

// const Foo = sequelize.define('foo', {
//  id: { type: Sequelize.UUIDV4, defaultValue: Sequelize.UUIDV4, primaryKey: true },
//  user: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
// });

// const FooRoo = sequelize.define('fooRoos', {
//   FooId: { type: Sequelize.UUIDV4 }

// });


// const Roo = sequelize.define('roo', {
//  // instantiating will automatically set the flag to true if not set
//  id: { type: Sequelize.UUIDV4, defaultValue: Sequelize.UUIDV4, primaryKey: true },
//  user: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
// });

// Foo.associate = (models) => {
//   Foo.
// }

// sequelize.sync({ force: true });

// Foo.

class User extends Sequelize.Model {}
User.init({
  username: Sequelize.STRING,
  birthday: Sequelize.DATE
}, { sequelize, modelName: 'user' });

sequelize.sync()
  .then(() => User.create({
    username: 'janedoe',
    birthday: new Date(1980, 6, 20)
  }))
  .then(jane => {
    console.log(jane.toJSON());
  })
  .then(() => User.findOne({ where: { username: 'asdf' }}))
  .then(console.log);
node v10.16.0