Tuto Lab 💡 - Use Znote as SQL client

June 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

  1. 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
  1. 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");

sql example

Isn't that cool? 😎

You could find more information about Sequelize directly on the website