mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add SQLite database
This commit is contained in:
parent
73a2a7955d
commit
0d58e073fd
5 changed files with 878 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
config/default.js
|
config/default.js
|
||||||
config/production.js
|
config/production.js
|
||||||
|
config/curate.sqlite
|
||||||
package-lock.json
|
package-lock.json
|
||||||
.idea/
|
.idea/
|
|
@ -18,7 +18,9 @@
|
||||||
"moment": "^2.27.0",
|
"moment": "^2.27.0",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"redis": "^3.0.2",
|
"redis": "^3.0.2",
|
||||||
"require-reload": "^0.2.2"
|
"require-reload": "^0.2.2",
|
||||||
|
"sequelize": "^6.3.4",
|
||||||
|
"sqlite3": "^5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.6.0"
|
"eslint": "^7.6.0"
|
||||||
|
|
|
@ -3,6 +3,7 @@ const Database = require('./database');
|
||||||
const EventHandler = require('./events');
|
const EventHandler = require('./events');
|
||||||
const CommandLoader = require('./commandloader');
|
const CommandLoader = require('./commandloader');
|
||||||
const MessageAwaiter = require('./messageawaiter');
|
const MessageAwaiter = require('./messageawaiter');
|
||||||
|
const SQLiteDB = require('./sqlitedb');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const CatLoggr = require('cat-loggr');
|
const CatLoggr = require('cat-loggr');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
@ -80,6 +81,7 @@ class CurateBot extends Eris.Client {
|
||||||
// Redis
|
// Redis
|
||||||
this.db = new Database(this);
|
this.db = new Database(this);
|
||||||
await this.db.connect(config.redis);
|
await this.db.connect(config.redis);
|
||||||
|
this.sqlite = new SQLiteDB(this);
|
||||||
|
|
||||||
// Discord
|
// Discord
|
||||||
await this.connect();
|
await this.connect();
|
||||||
|
|
47
src/sqlitedb.js
Normal file
47
src/sqlitedb.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
|
||||||
|
module.exports = class SQLiteDB {
|
||||||
|
constructor() {
|
||||||
|
this.sequelize = new Sequelize({
|
||||||
|
dialect: 'sqlite',
|
||||||
|
storage: 'config/curate.sqlite',
|
||||||
|
define: { timestamps: false }
|
||||||
|
});
|
||||||
|
|
||||||
|
class UserPair extends Sequelize.Model {}
|
||||||
|
|
||||||
|
UserPair.init({
|
||||||
|
discordID: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
primaryKey: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
lbryID: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
unique: true,
|
||||||
|
}
|
||||||
|
}, { sequelize: this.sequelize, modelName: 'user' });
|
||||||
|
|
||||||
|
this.model = UserPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a pair from a Discord ID
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
|
async get(id) {
|
||||||
|
const item = await this.model.findOne({ where: { discordID: id } });
|
||||||
|
return item ? item.get({ plain: true }) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an ID pair
|
||||||
|
* @param {string} discordID
|
||||||
|
* @param {string} lbryID
|
||||||
|
*/
|
||||||
|
pair(discordID, lbryID) {
|
||||||
|
return this.model.create({ discordID, lbryID });
|
||||||
|
}
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue