How to chart data stored in a database table (dynamically) in Drupal 8?

I found these instructions for using the Charts module to display data from a database for Drupal 7: https://www.drupal.org/docs/8/modules/charts/charts-howtos/chart-some-data-stored-in-a-database-table-dynamically

Has anyone tried this in Drupal 8? Are there any instructions for doing this in Drupal 8? Thanks!

how to implemented a MyS database HA when the candidate node already is a multi-source replication node?

MySQL 5.7.21 Community Version.

  1. Our node have a MySQL instance base on multi-source replication from 5 replication source.
  2. but this node does not fit HA purpose with single point failure.
  3. when we try to build master-slave or dual master on it, it can not be done with reset master process.

how to implemented the HA on this kind of MySQL instance?

Database listing delays

I am having issues with below code which display the news added in the database after few hours, the news is added straight away in the database once created and not sure if i need to make any changes in below code so it fetches the updated

<? $  query="SELECT SQL_CALC_FOUND_ROWS *, id, title, valid_from FROM news WHERE active AND '$  date_now'>=news.valid_from ORDER BY valid_from DESC LIMIT 4"; @$  result=mysql_query($  query); $  num_rows=mysql_num_rows($  result);  $  query_count="SELECT FOUND_ROWS() as no_results_total"; @$  result_count=mysql_query($  query_count); @$  row_count=mysql_fetch_assoc($  result_count); @$  no_results_total=$  row_count['no_results_total'];  while(@$  row=mysql_fetch_assoc($  result))     {     $  news[$  row['id']]=$  row;     }  $  query="SELECT *                 FROM                     (                     SELECT id,ext,database_id                     FROM images                     WHERE database_name='news' AND database_id IN(" . implode(',',array_keys($  news)) . ")                     ORDER BY role                     ) AS images2                 GROUP BY database_id"; @$  result=mysql_query($  query); while(@$  row=mysql_fetch_assoc($  result))     {     $  news[$  row['database_id']]['img']=$  row;     }  foreach($  news as $  val)     {     $  last=$  val['valid_from']; 

?> ‘);”> &ext=&th=n” />

At what point in design do you create a new database or just keep adding tables

My question is at what point should you create a new database and why?

So after many years of creating small projects I have come to the realization that I have way to many db’s. Now it’s not a ridiculous amount as in greater than 10 but it’s enough that its recognizable. I got to this point primarily because for every project or task that I was working on I would just create a new db add the tables and work with long object names to query data from other db’s if needed. So I’m starting to see the folly in my ways because now I have a multitude of db’s with 5-8 tables when I should have just added the tables to a main/master db. I understand that programs that use a relational db will have 1 db with hundreds of tables but that is what is to be expected. I mainly did it this way so if something happened to the data or if I was working on a project and something disastrous happened it only effected one project not all of them.

how to Import custom CSV in magento 2 and insert in database Table

Here am added import custom upload drop down to magento backend succesfully. while am importing data its not getting insert into database, its showing Please enter a correct entity model. error

class CustomImport extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity {     const ID = 'p_id';     const STORE = 'store_id';     const SDATE = 'pstart_date';     const EDATE = 'pend_date';      const TABLE_Entity = 'retailinsights_promostoremapp'; //table name mayBE     /**      * Validation failure message template definitions      *      * @var array      */     protected $  _messageTemplates = [     ValidatorInterface::ERROR_MESSAGE_IS_EMPTY => 'Message is empty',     ];      protected $  _permanentAttributes = [self::ID];     /**      * If we should check column names      *      * @var bool      */     protected $  needColumnCheck = true;     /**      * Valid column names      *      * @array      */     protected $  validColumnNames = [     self::ID,     self::STORE,     self::SDATE,     self::EDATE,      // self::MESSAGE,     // self::DATE,     ];     /**      * Need to log in import history      *      * @var bool      */     protected $  logInHistory = true;     protected $  _validators = [];     /**      * @var \Magento\Framework\Stdlib\DateTime\DateTime      */     protected $  _connection;     protected $  _resource;     /**      * @SuppressWarnings(PHPMD.CouplingBetweenObjects)      */     public function __construct(     \Magento\Framework\Json\Helper\Data $  jsonHelper,     \Magento\ImportExport\Helper\Data $  importExportData,     \Magento\ImportExport\Model\ResourceModel\Import\Data $  importData,     \Magento\Framework\App\ResourceConnection $  resource,     \Magento\ImportExport\Model\ResourceModel\Helper $  resourceHelper,     \Magento\Framework\Stdlib\StringUtils $  string,     ProcessingErrorAggregatorInterface $  errorAggregator     ) {     $  this->jsonHelper = $  jsonHelper;     $  this->_importExportData = $  importExportData;     $  this->_resourceHelper = $  resourceHelper;     $  this->_dataSourceModel = $  importData;     $  this->_resource = $  resource;     $  this->_connection = $  resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);     $  this->errorAggregator = $  errorAggregator;     }     public function getValidColumnNames()     {         return $  this->validColumnNames;     }     /**      * Entity type code getter.      *      * @return string      */     public function getEntityTypeCode()     {         return 'messages';     }     /**      * Row validation.      *      * @param array $  rowData      * @param int $  rowNum      * @return bool      */     public function validateRow(array $  rowData, $  rowNum)     {     $  title = false;     if (isset($  this->_validatedRows[$  rowNum])) {         return !$  this->getErrorAggregator()->isRowInvalid($  rowNum);     }     $  this->_validatedRows[$  rowNum] = true;     return !$  this->getErrorAggregator()->isRowInvalid($  rowNum);     }     /**      * Create Advanced message data from raw data.      *      * @throws \Exception      * @return bool Result of operation.      */     protected function _importData()     {         $  this->saveEntity();         return true;     }     /**      * Save Message      *      * @return $  this      */     public function saveEntity()     {     $  this->saveAndReplaceEntity();     return $  this;     }     /**      * Save and replace data message      *      * @return $  this      * @SuppressWarnings(PHPMD.CyclomaticComplexity)      * @SuppressWarnings(PHPMD.NPathComplexity)      */     protected function saveAndReplaceEntity()     {     $  behavior = $  this->getBehavior();     $  listTitle = [];     while ($  bunch = $  this->_dataSourceModel->getNextBunch()) {         $  entityList = [];         foreach ($  bunch as $  rowNum => $  rowData) {             if (!$  this->validateRow($  rowData, $  rowNum)) {                 $  this->addRowError(ValidatorInterface::ERROR_TITLE_IS_EMPTY, $  rowNum);                 continue;             }             if ($  this->getErrorAggregator()->hasToBeTerminated()) {                 $  this->getErrorAggregator()->addRowToSkip($  rowNum);                 continue;             }             $  rowTtile= $  rowData[self::ID];             $  listTitle[] = $  rowTtile;             $  entityList[$  rowTtile][] = [                 self::ID => $  rowData[self::ID],                 self::STORE  => $  rowData[self::STORE],                 self::SDATE => $  rowData[self::SDATE],                 self::EDATE => $  rowData[self::EDATE],                   // self::MESSAGE => $  rowData[self::MESSAGE],                 // self::DATE => $  rowData[self::DATE],             ];         }         if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $  behavior) {             if ($  listTitle) {                 if ($  this->deleteEntityFinish(array_unique(  $  listTitle), self::TABLE_Entity)) {                     $  this->saveEntityFinish($  entityList, self::TABLE_Entity);                 }             }         } elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $  behavior) {             $  this->saveEntityFinish($  entityList, self::TABLE_Entity);         }     }     return $  this;     }     /**      * Save message to customtable.      *      * @param array $  priceData      * @param string $  table      * @return $  this      */     protected function saveEntityFinish(array $  entityData, $  table)     {     if ($  entityData) {         $  tableName = $  this->_connection->getTableName($  table);         $  entityIn = [];         foreach ($  entityData as $  id => $  entityRows) {                 foreach ($  entityRows as $  row) {                     $  entityIn[] = $  row;                 }         }         if ($  entityIn) {             $  this->_connection->insertOnDuplicate($  tableName, $  entityIn,[                 self::ID,                 self::STORE,                 self::SDATE,                 self::EDATE,                  // self::MESSAGE,                 // self::DATE,         ]);         }     }     return $  this;     } 

this is my table retailinsights_promostoremapp columns are p_id,store_id,rule_id,pstart_date,pend_date . thank you in advance

Designing database relationships for a voting application

So I designed database relationships for a voting/polling application. I want a user to only be able to pick 1 option on a poll. I want multiple options per poll.

enter image description here

So what I have here is this.

User

  • has an id, username, email, password
  • the primary key is its id

Poll

  • has a title and an id
  • the primary key is its id

Option

  • has a text, and an id and holds a reference to the id of the poll that it belongs to
  • its primary key is its id PLUS the id of its parent poll

Vote

  • holds a reference to the id of the user that voted
  • holds a references to the selected option

So how does this look? I have set up these tables and I can insert records for polls, options and users but when I want to add a vote the options I get are not what I expected. I want to add a vote per poll where I can pick exactly 1 option.

This is my first time designing a database, any help would be great.

MongoDB db._____.find() is only returning entries when I am using a different database in the shell

I am designing a dynamic server using node.js and express. For persistence I am using MongoDB.

I have a register page that takes the form data and enters it into the database known as user.

A login page that checks the users password/username with that on the database, if it matches let them in.

I am also making an email esque service that allows communication between different accounts, I am doing this using a second database called message.

I have added a few entries to the users database and have logged in successfully, however after attempting to add the secondary mongodb database it is no longer working in a way that I would expect.

Firstly when adding data to the message database, attempting to view the contents leads to an empty response. Secondly, when using the command use users in the mongo shell and then db.users.find() it returns nothing. However if I go into use message and then repeat the command db.users.find() it returns all the data I would expect.

Using the command db.message.find() returns nothing regardless of what use I use.

This is how I am connecting to the databases:

const mongoose = require('mongoose').Mongoose; const User = require('./models/schema.js'); const Message = require('./models/msgSchema.js')  // connecting to the MongoDB data base var users = new mongoose(); users.connect('mongodb://localhost/users')  // connecting to the MongoDB data base var users = new mongoose(); users.connect('mongodb://localhost/users') 

My 2 schemas are schema.js && msgSchema.js

msgSchema:

const mongoose = require('mongoose'), Schema = mongoose.Schema;  // Connect to database mongoose.connect('mongodb://localhost/message');  var msgSchema = new mongoose.Schema ({     user: {         type: String,         required: true,     },     message: {         type: String,         required: true,     } });  var Message = mongoose.model('Message', msgSchema); module.exports = Message; 

schema:

const mongoose = require('mongoose'), Schema = mongoose.Schema; const bcrypt = require('bcrypt');  // Connect to database mongoose.connect('mongodb://localhost/users');  var userSchema = new mongoose.Schema ({     username: {         type: String,         unique: true,         required: true,         trim: true     },     password: {         type: String,         required: true,     },     email: {         type: String,         required: true     } });  var User = mongoose.model('User', userSchema); module.exports = User; 

There is more in schema but it is just hashing/authentication so not important

My POST for register

app.post('/register', (req, res) => {     if(req.body.email && req.body.username && req.body.password) {         var userData = {             email: req.body.email,             username: req.body.username,             password: req.body.password,         }          User.create(userData, function(err, user) {             if(err) {                 return console.log(err.message);             } else {                 console.log("Adding data to users was successful...");                 req.session.userId = user._id;                 return res.redirect('/login');             }         });     } }); 

My POST for the messaging system

app.post('/MembersArea', (req, res) => {     console.log("POSTS FINE");      if(req.body.message && req.body.user) {         var userMessage = {             message: req.body.message,             user: req.body.user,         }          Message.create(userMessage, function(err) {             if(err) {                 console.log(err.message)                  return res.redirect('/MembersArea');             } else {                 console.log("Adding data to message was successful...");                 return res.redirect('/MembersArea');             }          })     } })