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

  1. Install your SQL JS Driver
BASH
# 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
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");

sql example

Isn't that cool? 😎

You could find more information about Sequelize directly on the website


WRITTEN BY

@alagrede

The note-taking app for JS Developers


Š 2021 - Znote. Created by Anthony Lagrede Consulting