1.0.4 • Published 2 years ago

fastifysql v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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")
}

by Alyasha

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago