Tuto Lab đĄ - Use Znote as SQL client
js
sql
06/15/2021
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
BASH
# One of the following:npm install --save pg pg-hstore # Postgresnpm install --save mysql2npm install --save mariadbnpm install --save sqlite3npm install --save tedious # Microsoft SQL Servernpm install --save sequelizenpm install --save tablify # Display JSON into Table
- Create the shortcut function
JS
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
JS
printSQL("select * from book.vente_order");
Isn't that cool? đ
You could find more information about Sequelize directly on the website