I have been working on a web application that utilizes boardgame.io's Tic-Tac-Toe tutorial game, with a twist - the results of each match are saved to a MySQL database. The current state of my code involves trying to establish a connection to the database, with the expected outcome being displayed in the browser's console.
import { Client } from 'boardgame.io/client';
import { TicTacToe } from './Game';
class TicTacToeClient {
constructor(rootElement) {
this.client = Client({ game: TicTacToe });
this.client.start();
this.rootElement = rootElement;
this.createBoard();
this.attachListeners();
this.client.subscribe(state => this.update(state));
const { Sequelize, DataTypes } = require("sequelize");
const sequelize = new Sequelize(
'tictactoetest',
'xxxx',
'xxxx',
{
host: 'localhost',
dialect: 'mysql',
dialectModule: require('mysql2')
}
);
sequelize.authenticate().then(() =>
{
console.log('Connection has been established successfully.');
}).catch((error) => {
console.error('Unable to connect to the database: ', error);
});
const Record = sequelize.define("record",
{
log:
{
type: DataTypes.STRING,
allowNull: false
},
winner:
{
type: DataTypes.STRING,
allowNull: false
}
}, {
tableName: 'record'
});
sequelize.sync().then(() => {
console.log('Record table created successfully!');
}).catch((error) => {
console.error('Unable to create table : ', error);
});
}
createBoard()
{
//Irrelevant
}
attachListeners()
{
//Irrelevant
}
update(state)
{
//Irrelevant
}
}
const appElement = document.getElementById('app');
const app = new TicTacToeClient(appElement);
Despite the game functioning as intended, I'm encountering an error message
"Uncaught TypeError: LRU is not a constructor"
instead of the expected success/failure confirmation. I've attempted to install various LRU libraries using NPM, to no avail. Interestingly, the same code for establishing DB connection works flawlessly in a separate file using "node"
. It's puzzling where the problem lies.