UNPKG

@xuda.io/xuda-dbs-plugin-mysql

Version:

Xuda Database Socket for MySql

110 lines (95 loc) 2.73 kB
// const { Sequelize, DataTypes } = require("sequelize"); // const sequelize = new Sequelize( // "sample_student_db", // "doadmin", // "AVNS_edKcU1421OaM8uKospL", // { // host: "db-mysql-nyc3-95324-do-user-774134-0.b.db.ondigitalocean.com", // dialect: "mysql", // port: "25060", // } // ); // sequelize // .authenticate() // .then(() => { // console.log("Connection has been established successfully."); // }) // .catch((error) => { // console.error("Unable to connect to the database: ", error); // }); // // const Student = sequelize.define("students", { // // student_id: { // // type: DataTypes.UUID, // // defaultValue: DataTypes.UUIDV4, // // primaryKey: true, // // }, // // name: { // // type: DataTypes.STRING, // // allowNull: false // // } // // }); // // const student_data = [ // // {name : "John Baker"}, // // {name : "Max Butler"}, // // {name : "Ryan Fisher"}, // // {name : "Robert Gray"}, // // {name : "Sam Lewis"} // // ] // // sequelize.sync({ force: true }).then(() => { // // Student.bulkCreate(student_data, { validate: true }).then((result) => { // // console.log(result); // // }).catch((error) => { // // console.log(error); // // }); // // }).catch((error) => { // // console.error('Unable to create table : ', error); // // }); var mysql = require("mysql"); var connection = mysql.createConnection({ host: "db-mysql-nyc3-95324-do-user-774134-0.b.db.ondigitalocean.com", user: "test", password: "AVNS_9747YuXgwpqxrc-v4rH", database: "defaultdb", port: "25060", }); connection.connect(); connection.query("SELECT 1 + 1 AS solution", function (error, results, fields) { if (error) throw error; console.log("The solution is: ", results[0].solution); }); connection.end(); ////////////////////////////////////// // var db = require("node-mysql"); // var DB = db.DB; // var BaseRow = db.Row; // var BaseTable = db.Table; // var box = new DB({ // host: "db-mysql-nyc3-95324-do-user-774134-0.b.db.ondigitalocean.com", // user: "test", // password: "AVNS_edKcU1421OaM8uKospL", // database: "defaultdb", // connectionLimit: 50, // port: "25060", // useTransaction: { // connectionLimit: 1, // }, // }); // var basicTest = function (cb) { // box.connect(function (conn, cb) { // cps.seq( // [ // function (_, cb) { // conn.query("select * from users limit 1", cb); // }, // function (res, cb) { // console.log(res); // cb(); // }, // ], // cb // ); // }, cb); // }; // basicTest(function (res) { // console.log(res); // });