Installation
We will explain in this post how to simply configure your Znote to use it as a cross-platform SQL client with sequelize.
Prerequisite: configure a custom environment
- Install your SQL JS Driver
# One of the following:
npm install --save pg pg-hstore # Postgres
npm install --save mysql2
npm install --save mariadb
npm install --save sqlite3
npm install --save tedious # Microsoft SQL Server
npm install --save sequelize
npm install --save tablify # Display JSON into Table
- Create the shortcut function
async function printSQL(sqlQuery) {
const tablify = require('tablify').tablify
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize("", "root", "root", {
dialect: "mysql"/* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */,
host: "localhost"
});
sequelize.authenticate();
const [results, metadata] = await sequelize.query(sqlQuery);
sequelize.close()
print(tablify(results));
}
Usage in your note
printSQL("select * from book.vente_order");
Isn't that cool? 😎
You could find more information about Sequelize directly on the website