New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@pforth/dbfuncs

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pforth/dbfuncs

Useful async Database functions

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
0
Created
Source

This module lets you get async mysql database pool connections. Also has lots of cool helper query funcs.

Veradaccio

This project should be published in a locally running npm repo. You can do the following:

npm install -g verdaccio

nohup verdaccio --listen 4873

npm set registry http://localhost:4873/

You can also refer to here

Usage

const db=require("dbfuncs");

db.createPoolsFromFile(); // defaults to config.json
OR
db.createPoolsFromFile("config.json", {local: {password:"fred"}});  // Provide a default password of fred for the db "local"
OR
let pool=db.createPool(conName, host, user, password, database)

// If you create a pool called "local" then you can use
let conn=db.getConnLocal();
OR
let conn=db.getConn("local");
OR
let conn=db.getConn(localPool); // If you already got the local pool object from somewhere.
OR
let conn=db.getConn(); // To get the default pool (first one created or explicitly set)

await conn.query("DELETE FROM atable"); // Any query.  Returns a list of rows (dictionaries) if a select
await conn.getRow("SELECT field, field2 FROM hi WHERE id=1"); // Returns a single (or first) row as a dictionary
await conn.get("SELECT field FROM hi WHERE id=1;"); // Get the first field in the first row returned (synonym for getFirstField())
await conn.getField("one", "SELECT one, two FROM three"); // Returns a single field from the first row
await conn.getDictForField("id", "field", "SELECT id, field FROM hi"); // Returns a dictionary of key -> value
await conn.getDict("id", "SELECT id, field, another FROM hi"); // Returns a dictionary of keys -> each row of results.
await conn.getList("name", "SELECT name FROM users"); // Returns a list by taking the value of a single field from each row

await conn.getDictOfLists("nonuniqueId", "saleId", "SELECT userId, saleId FROM sales")
// Returns a dictionary of lists (in this case a list of all the sales for each user)
// If the second arg = null then each list item contains the entire row for that key

await conn.insert("users SET name=?", ["fred"]); // Does a sql insert

db.setDefPool(name); // Explicitly set the default pool to a pool with a different name

Keywords

database

FAQs

Package last updated on 14 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts