npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

unified-sql-client

v2.1.1

Published

Universal SQL + fetcher client supporting MySQL, MariaDB, PostgreSQL and Neon, including React hook support

Readme

unified-sql-client

unified-sql-client is a universal SQL and data-fetching library for Node.js and React applications. It supports MySQL, MariaDB, PostgreSQL, and Neon serverless, making it suitable for both traditional and serverless environments. It also includes a built-in fetcher React hook for easy data fetching from REST APIs.


📦 Installation

npm install unified-sql-client

🌐 Environment Setup

Make sure your .env file is configured correctly to support dynamic environment-based connections.

✅ For PostgreSQL / Neon:

DATABASE_URL=postgres://user:password@hostname:port/database
USE_NEON_DRIVER=true

The USE_NEON_DRIVER flag can also be automatically detected if your URL includes .neon.tech.

✅ For MySQL / MariaDB:

# Production
DB_HOST=your-production-host
DB_USER=your-production-user
DB_PASSWORD=your-production-password
DB_NAME=your-production-db

# Development (fallback)
DEV_DB_HOST=localhost
DEV_DB_USER=root
DEV_DB_PASSWORD=
DEV_DB_NAME=local_db

The driver is auto-configured depending on NODE_ENV.


🚀 Usage

1. Backend SQL Queries (useDb)

queryEx – safe result + error return:

import { useEnvConnection, queryEx } from "unified-sql-client/server";

useEnvConnection("pg"); // Or MySQL

const [result, error] = await queryEx("SELECT * FROM users WHERE id = $1", [1]);

if (error) {
  console.error("DB Error:", error);
} else {
  console.log("Data:", result);
}

query – direct result:

import { query } from "unified-sql-client/server";

const users = await query("SELECT * FROM users");
console.log(users);

2. Frontend React Hook (fetcher)

import { useFetcher, HttpMethod } from "unified-sql-client/fetcher";

const { data, error, isLoading } = useFetcher({
  method: HttpMethod.GET,
  url: "/api/posts",
});

For mutations (POST/PUT/DELETE):

const { trigger } = useFetcher({
  method: HttpMethod.POST,
  url: "/api/post",
  payload: { title: "Hello", content: "World" },
});

await trigger();

⚙️ Configuration Options

You can also manually set a custom connection:

import { setConnection } from "unified-sql-client/server";

setConnection({
  host: "localhost",
  user: "admin",
  password: "secret",
  database: "mydb",
  driver: "pg",
});

✅ Features

  • 🔄 Dynamic .env config based on environment
  • 🧩 MySQL / MariaDB / PostgreSQL / Neon support
  • 🚀 Type-safe wrapper with queryEx<T>()
  • 🔗 React useFetcher hook for API fetches
  • 🔒 Safe error handling for SQL operations
  • ⚡ Works in serverless environments like Vercel

📘 API Reference

server (server-side)

  • query(query: string, args: any[]): Promise<any>
  • queryEx<T>(query: string, args: any[]): Promise<[T | null, DbError | null]>
  • useEnvConnection(driver?: "mysql" | "pg")
  • setConnection(config: DbConnectionConfig)
  • beginTransaction(), commit(), rollback() (MySQL only)

fetcher (client-side)

  • useFetcher<T>(options: { method, url, payload? })

    • GET: returns { data, error, isLoading }
    • POST/PUT/DELETE: returns { trigger }

🧪 Example .env (for Neon)

DATABASE_URL=postgres://user:[email protected]/dbname?sslmode=require
USE_NEON_DRIVER=true

📝 License

MIT License © 2025 slynxcz