-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.09 KB
/
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
import "dotenv/config";
import { DataTypes, Sequelize } from "@sequelize/core";
const schema = "dev";
const sequelize = new Sequelize({
dialect: "postgres",
host: process.env.PGHOST,
port: process.env.PGPORT,
username: process.env.PGUSER,
password: process.env.PGPASSWORD,
database: process.env.PGDATABASE,
schema,
});
await sequelize.createSchema(schema);
const Entity = sequelize.define(
"entity",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
},
},
{ tableName: "entity", timestamps: false, paranoid: false }
);
const Relation = sequelize.define(
"relation",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
},
},
{ tableName: "relation", timestamps: false, paranoid: false }
);
Entity.hasMany(Relation);
await sequelize.sync();
// BUG: will execute a select query that incorrectly prefixes
// the aliased table name in the on clause with the schema.
await Relation.findAll({ include: [Entity] });
await sequelize.close();