defined (keyword-) response model

This commit is contained in:
Baipyrus 2024-04-03 19:30:31 +02:00
parent 7b56d96c3c
commit 62cf257d73
2 changed files with 41 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import defineRoleEmojiPair from './models/roleEmojiPairs.js';
import defineVoiceChannel from './models/voiceChannels.js';
import defineResponse from './models/responses.js';
import defineMessage from './models/messages.js';
import defineKeyword from './models/keywords.js';
import defineGuild from './models/guilds.js';
@ -17,7 +18,10 @@ const sequelize = new Sequelize({
logging: false
});
const Response = defineResponse(sequelize);
const Keyword = defineKeyword(sequelize);
Keyword.hasMany(Response, { foreignKey: 'keyword', onDelete: 'CASCADE' });
const RoleEmojiPair = defineRoleEmojiPair(sequelize);

37
models/responses.js Normal file
View File

@ -0,0 +1,37 @@
import { DataTypes, Deferrable, Sequelize } from 'sequelize';
/**
* @typedef {Object} Response
* @property {string} id A universally unique id, generated by sequelize.
* @property {string} keyword A universally unique id referencing a `Keyword`.
* @property {string} name The name of the response.
* @property {string} response The response data itself.
*/
/**
* The definition of the `Response` table in the database.
* @param {Sequelize} sequelize
*/
export default function (sequelize) {
return sequelize.define('Responses', {
id: {
defaultValue: DataTypes.UUIDV4,
type: DataTypes.UUID,
primaryKey: true
},
keyword: {
type: DataTypes.UUID,
references: {
deferrable: Deferrable.INITIALLY_IMMEDIATE,
model: 'Keywords',
key: 'id'
}
},
name: {
type: DataTypes.STRING
},
response: {
type: DataTypes.STRING
}
});
}