fastifysql
v1.0.4
Published
This package immediately prevents memory leaks, and speeds up the return of data.
Downloads
1
Readme
FastifySQL - How to use
This package immediately prevents memory leaks, and speeds up the return of data.
Installation
npm i fastifysql
Import -> Init
import fastifysql from "fastifysql";
fastifysql.initializeSQL("localhost", 3306, "root", "", "database") // To init environment
Use
Simple query:
const result = fastifysql.executeQuery("SELECT * FROM table", []) // Any query for the first argument and [] for the second
console.log(JSON.stringify(result)) // Result
Checking for existence:
const result = fastifysql.executeQuery("SELECT * FROM table WHERE id = 1", [])
if (result.length > 0) {
console.log(JSON.stringify(result))
} else {
console.error("Nothing here")
}
A query with params:
let id = 1
let name = "John"
const result = fastifysql.executeQuery("SELECT * FROM table WHERE id = ? AND name = ?", [id, name])
if (result.length > 0) {
console.log(JSON.stringify(result))
} else {
console.error("John doesn't exist")
}
Getting data from a specific column:
let id = 1
let name = "John"
const result = fastifysql.executeQuery("SELECT id, name, password, date FROM table WHERE id = ? AND name = ?", [id, name])
if (result.length > 0) {
console.log(result[0].name) // get name
console.log(result[0].date) // get date
} else {
console.error("John doesn't exist")
}