Znote (recipes)
  Get Znote  

🏠 Connect to a Local SQL Database

How to make SQL query on a local MySQL

 

🏠 Connect to a Local SQL Database

  • 🚀 Easily query your local database
  • 👉 Ensure you have installed the 🧩 Local SQL plugin

📦 Supported Database Drivers

  • ✅ MySQL / MariaDB
  • ✅ PostgreSQL
  • ✅ Microsoft SQL Server

🔌 Query a Local SQL Database

//exec:node
const query = "SELECT * FROM TABLE;";

const dbDialect = "mysql"; // Options: 'mysql' | 'postgres' | 'mssql'
const dbPort = 3306; // Default ports: MySQL/MariaDB=3306, PostgreSQL=5432, MSSQL=1433

const results = await getSQL(query, "localhost", dbPort, dbDialect, "user", "password", "database");

printTable(results); // Display as a table
//printJSON(results); // Uncomment to see raw JSON output

🔹 Using SQLite Instead?

//exec:node
const query = "SELECT * FROM TABLE;";
const dbPath = "/path/to/database.sqlite";

const results = await getSQLite(query, dbPath);

printTable(results);
  • You're now ready to interact with your local database!
  • 📖 More details available in the Local SQL plugin documentation

Related recipes