123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- const { Sequelize, Model, DataTypes } = require("sequelize");
- const sequelize = new Sequelize("distrohard", "graukatze", "1234", {
- host: "localhost",
- dialect: "postgres",
- });
- let logIN = true;
- class User extends Model {}
- User.init(
- {
- login: {
- type: DataTypes.STRING(12),
- primaryKey: true,
- },
- pass: DataTypes.STRING(50),
- },
- {
- sequelize,
- modelName: "Users",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class Vendor extends Model {}
- Vendor.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- companyName: DataTypes.STRING(50),
- },
- {
- sequelize,
- modelName: "Vendors",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class Processor extends Model {}
- Processor.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- modelName: DataTypes.STRING(50),
- vendor_id: {
- type: DataTypes.INTEGER,
- references: { model: Vendor, key: "id" },
- },
- },
- {
- sequelize,
- modelName: "Processors",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class VideoCard extends Model {}
- VideoCard.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- modelName: DataTypes.STRING(50),
- vendor_id: {
- type: DataTypes.INTEGER,
- references: { model: Vendor, key: "id" },
- },
- },
- {
- sequelize,
- modelName: "VideoCards",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class DistroLinux extends Model {}
- DistroLinux.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- vendor: DataTypes.STRING(50),
- version: DataTypes.STRING(50),
- },
- {
- sequelize,
- modelName: "DistroLinux",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class Errors extends Model {}
- Errors.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- codeCVE: {
- type: DataTypes.STRING(20),
- },
- },
- {
- sequelize,
- modelName: "Errors",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class ProcessorStatusOnLinux extends Model {}
- ProcessorStatusOnLinux.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- Processor_id: {
- type: DataTypes.INTEGER,
- references: { model: Processor, key: "id" },
- },
- DistLinux_id: {
- type: DataTypes.INTEGER,
- references: { model: DistroLinux, key: "id" },
- },
- Status: DataTypes.STRING(25),
- },
- {
- sequelize,
- modelName: "ProcessorStatusOnLinux",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class VideoCardStatusOnLinux extends Model {}
- VideoCardStatusOnLinux.init(
- {
- id: {
- type: DataTypes.INTEGER,
- autoIncrement: true,
- primaryKey: true,
- },
- VideoCard_id: {
- type: DataTypes.INTEGER,
- references: { model: VideoCard, key: "id" },
- },
- DistLinux_id: {
- type: DataTypes.INTEGER,
- references: { model: DistroLinux, key: "id" },
- },
- Status: DataTypes.STRING(25),
- },
- {
- sequelize,
- modelName: "VideoCardStatusOnLinux",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class ErrorStatusOnProcessor extends Model {}
- ErrorStatusOnProcessor.init(
- {
- Error_id: {
- type: DataTypes.INTEGER,
- references: { model: Errors, key: "id" },
- },
- Processor_id: {
- type: DataTypes.INTEGER,
- references: { model: Processor, key: "id" },
- },
- Status: DataTypes.STRING(25),
- },
- {
- sequelize,
- modelName: "ErrorStatusOnProcessor",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class ErrorStatusOnVideoCard extends Model {}
- ErrorStatusOnVideoCard.init(
- {
- Error_id: {
- type: DataTypes.INTEGER,
- references: { model: Errors, key: "id" },
- },
- VideoCard_id: {
- type: DataTypes.INTEGER,
- references: { model: VideoCard, key: "id" },
- },
- Status: DataTypes.STRING(25),
- },
- {
- sequelize,
- modelName: "ErrorStatusOnVideoCard",
- timestamps: false,
- freezeTableName: true,
- }
- );
- class ErrorStatusOnLinux extends Model {}
- ErrorStatusOnLinux.init(
- {
- Error_id: {
- type: DataTypes.INTEGER,
- references: { model: Errors, key: "id" },
- },
- DistroLinux_id: {
- type: DataTypes.INTEGER,
- references: { model: DistroLinux, key: "id" },
- },
- Status: DataTypes.STRING(25),
- },
- {
- sequelize,
- modelName: "ErrorStatusOnLinux",
- timestamps: false,
- freezeTableName: true,
- }
- );
- async function syncDataBase() {
- await sequelize.sync({ alter: true }).then(() => {
- console.log("\n================Basa was sync================");
- });
- }
- //===========================
- //-----FUNC FOR DATABASE-----
- //===========================
- //work
- function insertData(Model, jsonData) {
- Model.create(jsonData);
- }
- async function updateData(Model, modelID, jsonData) {
- Model.update(jsonData, { where: { id: modelID } });
- }
- //work
- async function deleteData(Model, jsonData) {
- Model.destroy({ where: jsonData });
- }
- //work
- async function selectDataAll(Model) {
- return Model.findAll({ raw: true });
- }
- async function selectDataAllFiltr(Model, jsonData) {
- return Model.findAll({ raw: true, where: jsonData });
- }
- async function selectDataOne(Model, jsonData) {
- return Model.findOne({ raw: true, where: jsonData });
- }
- module.exports = {
- User,
- logIN,
- sequelize,
- syncDataBase,
- DistroLinux,
- selectDataAll,
- insertData,
- deleteData,
- Vendor,
- Processor,
- VideoCard,
- selectDataAllFiltr,
- selectDataOne,
- ProcessorStatusOnLinux,
- VideoCardStatusOnLinux,
- Errors,
- updateData,
- ErrorStatusOnLinux,
- ErrorStatusOnVideoCard,
- ErrorStatusOnProcessor,
- VideoCardStatusOnLinux,
- ProcessorStatusOnLinux,
- };
|