Add SQLite database

This commit is contained in:
Snazzah 2020-08-12 00:55:44 -05:00
parent 73a2a7955d
commit 0d58e073fd
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
5 changed files with 878 additions and 10 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
node_modules
config/default.js
config/production.js
config/curate.sqlite
package-lock.json
.idea/

View file

@ -18,7 +18,9 @@
"moment": "^2.27.0",
"node-fetch": "^2.3.0",
"redis": "^3.0.2",
"require-reload": "^0.2.2"
"require-reload": "^0.2.2",
"sequelize": "^6.3.4",
"sqlite3": "^5.0.0"
},
"devDependencies": {
"eslint": "^7.6.0"

View file

@ -3,6 +3,7 @@ const Database = require('./database');
const EventHandler = require('./events');
const CommandLoader = require('./commandloader');
const MessageAwaiter = require('./messageawaiter');
const SQLiteDB = require('./sqlitedb');
const path = require('path');
const CatLoggr = require('cat-loggr');
const config = require('config');
@ -80,6 +81,7 @@ class CurateBot extends Eris.Client {
// Redis
this.db = new Database(this);
await this.db.connect(config.redis);
this.sqlite = new SQLiteDB(this);
// Discord
await this.connect();

47
src/sqlitedb.js Normal file
View 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 });
}
};

834
yarn.lock

File diff suppressed because it is too large Load diff