-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
96 lines (83 loc) · 2.37 KB
/
db.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var Sequelize = require('sequelize')
const Op = Sequelize.Op;
const dbname = process.env.DB_DBNAME || 'traderbirdbot';
const dbuser = process.env.DB_USERNAME || 'root';
const dbpass = process.env.DB_PASSWORD || null;
const dbhost = process.env.DB_HOSTNAME;
const sequelize = new Sequelize(dbname, dbuser, dbpass, {
host: dbhost,
dialect: 'mysql',
dialectOptions: {
charset: 'utf8mb4',
},
});
const Account = sequelize.define('account', {
username: Sequelize.STRING,
userid: Sequelize.STRING
});
const Filter = sequelize.define('filter', {
keyword: Sequelize.STRING
});
const Channel = sequelize.define('channel', {
chatid: {
type: Sequelize.STRING,
},
buySize: {
type: Sequelize.FLOAT,
defaultValue: 1.0
},
buyQuote: {
type: Sequelize.STRING,
defaultValue: 'BTC'
}
});
const Order = sequelize.define('order', {
buySize: Sequelize.FLOAT,
buyQuote: Sequelize.STRING,
buyBase: Sequelize.STRING,
buyTime: Sequelize.DATE,
buyId: Sequelize.STRING,
buyPrice: Sequelize.STRING,
buyOrigQty: Sequelize.STRING,
buyExecQty: Sequelize.STRING,
buyType: Sequelize.STRING,
buyRemainingBalance: Sequelize.STRING,
sellSize: Sequelize.FLOAT,
sellQuote: Sequelize.STRING,
sellBase: Sequelize.STRING,
sellTime: Sequelize.DATE,
sellId: Sequelize.STRING,
sellPrice: Sequelize.STRING,
sellOrigQty: Sequelize.STRING,
sellExecQty: Sequelize.STRING,
sellType: Sequelize.STRING,
sellRemainingBalance: Sequelize.STRING
})
const Tweet = sequelize.define('tweet', {
text: Sequelize.TEXT,
isQuote: Sequelize.BOOLEAN,
isReply: Sequelize.BOOLEAN,
isRetweet: Sequelize.BOOLEAN,
userid: Sequelize.TEXT,
timestamp_ms: Sequelize.STRING,
},
{
charset: 'utf8',
collate: 'utf8_unicode_ci'
});
const ChannelAccount = sequelize.define('channelaccount', {});
const ChannelFilter = sequelize.define('channelfilter', {});
// Channel.hasMany(Account);
Account.hasMany(Tweet);
Tweet.belongsTo(Account);
// Channel.hasMany(Filter);
Account.belongsToMany(Channel, { through: ChannelAccount } );
Channel.belongsToMany(Account, { through: ChannelAccount } );
Filter.belongsToMany(Channel, { through: ChannelFilter } );
Channel.belongsToMany(Filter, { through: ChannelFilter } );
Order.belongsTo(Tweet);
Order.belongsTo(Channel);
async function sync() {
return await sequelize.sync();
}
module.exports = { Channel, Tweet, Filter, Account, Order, sync, Op };