RSSAmplifier

Znote Blog RSS Feed · Jun 15, 2021

Tuto Lab 💡 - Use Znote as SQL client

0
Sign in to vote or save

This page did not load. You can still read it on the original site — the toolbar below keeps your place in the directory.

Installation We will explain in this post how to simply configure your Znote to use it as a cross-platform SQL client with sequelize…

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

Read on znote.io

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.