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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tezx/sqlx

v1.0.1

Published

A universal SQL query builder for Node.js, Bun, and Deno with TypeScript support.

Readme

@tezx/sqlx

High-performance TypeScript SQL builder for MySQL / MariaDB. Supports dynamic queries, inserts, updates, deletes, complex filtering, aggregates, joins, sorting, pagination, and safe SQL utilities. Works in Node.js, Deno, and Bun.


🔹 Installation

# Node.js / Bun
npm install @tezx/sqlx

# Deno
import { insert, find, update, destroy, condition, escape, format } from "https://esm.sh/@tezx/sqlx/mysql";

1️⃣ Insert Queries

import { insert } from "@tezx/sqlx/mysql";

// Insert a single row
const singleRow = insert<["name","email","created_at"]>(
  "users",
  { name: "Rakibul Islam", email: "[email protected]", created_at: "CURRENT_TIMESTAMP" }
);

// Insert multiple rows
const multipleRows = insert<["name","email","created_at"]>(
  "users",
  [
    { name: "Alice", email: "[email protected]", created_at: "CURRENT_TIMESTAMP" },
    { name: "Bob", email: "[email protected]", created_at: "CURRENT_TIMESTAMP" },
  ]
);

// Insert with INSERT IGNORE
const insertIgnore = insert<["email","name"]>(
  "users",
  { email: "[email protected]", name: "Alice Updated" },
  { uniqueColumn: "email" }
);

// Insert with ON DUPLICATE KEY UPDATE
const insertDuplicate = insert<["email","name"]>(
  "users",
  { email: "[email protected]", name: "Bob Updated" },
  { onDuplicateUpdateFields: ["name"] }
);

2️⃣ Dynamic WHERE / HAVING Conditions

import { condition } from "@tezx/sqlx/mysql";

const filters = {
  status: "active",
  age: { gte: 18, lte: 65 },
  country: { in: ["US","CA"] },
  $or: { title: { like: "%manager%" }, department: { eq: "HR" } },
  last_login: { isNull: true }
};

const whereClause = condition(filters);

3️⃣ Delete Queries (destroy)

import { destroy } from "@tezx/sqlx/mysql";

// Simple delete
const simpleDelete = destroy("posts", { where: "user_id = 5" });

// Delete with join
const deleteJoin = destroy("posts", {
  where: "users.status = 'inactive' AND posts.user_id = users.id",
  joins: [{ type: "INNER JOIN", table: "users", on: "posts.user_id = users.id" }],
});

// Delete with sort and limit
const deleteLimit = destroy("posts", { where: "user_id = 5", sort: { column: "created_at", order: "ASC" }, limit: 10 });

4️⃣ Update Queries (update)

import { update } from "@tezx/sqlx/mysql";

// Simple update
const simpleUpdate = update("users", { values: { status: "active", points: 100 }, where: "id = 5" });

// Update with CASE expression
const caseUpdate = update("users", {
  values: { 
    status: { case: [{ when: "points > 1000", then: "gold" }, { when: "points > 500", then: "silver" }], default: "bronze" }, 
    last_login: null 
  },
  where: "status != 'inactive'",
});

// Update with JOIN, sort, limit
const updateJoin = update("users", {
  values: { status: "inactive" },
  joins: [{ type: "INNER JOIN", table: "orders", on: "users.id = orders.user_id" }],
  where: "orders.created_at < '2024-01-01'",
  sort: { column: "users.last_login", order: "ASC" },
  limit: 10,
});

// Update default values and calculations
const updateDefaults = update("users", {
  defaultValues: ["points"],
  setCalculations: { last_login: "NOW()" },
  where: "id IN (1,2,3)",
});

5️⃣ Find / Select Queries (find)

import { find } from "@tezx/sqlx/mysql";

const selectQuery = find<["users","orders"]>("users", {
  distinct: true,
  columns: { users: ["id","name","age","city"], orders: ["status"] },
  aggregates: [{ SUM: "orders.total", alias: "totalSpent" }, { COUNT: "orders.id", alias: "orderCount" }],
  joins: [{ type: "LEFT JOIN", table: "orders", on: "users.id = orders.user_id" }],
  where: "users.age > 18",
  groupBy: { users: ["id","name","age","city"] },
  sort: { column: "totalSpent", order: "DESC" },
  limitSkip: { limit: 10, skip: 0 },
});

6️⃣ Date & Datetime Helpers

import { mysql_datetime, mysql_date } from "@tezx/sqlx/mysql";

mysql_datetime(); // current datetime "YYYY-MM-DD HH:mm:ss"
mysql_date("1990-05-23"); // "1990-05-23"
mysql_datetime(new Date("2023-01-15T10:20:30Z")); // "2023-01-15 10:20:30"

7️⃣ SQL Utilities

import { escape, format, sanitize, parseMySQLUrl } from "@tezx/sqlx/mysql";

escape("O'Reilly"); // 'O\'Reilly'
format("SELECT * FROM users WHERE name=? AND age>?", ["Alice", 30]);
sanitize("some input"); // alias for escape
parseMySQLUrl("mysql://user:pass@localhost:3306/mydb?charset=utf8mb4");

✅ Summary

  • Dynamic queries: insert, update, destroy, find, condition
  • SQL safety: escape, sanitize, format
  • Date helpers: mysql_date, mysql_datetime
  • MySQL URL parsing: parseMySQLUrl