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

tson-sql

v1.0.0

Published

Advanced TSON to SQL Query Generator & ORM Payload Parser. Converts TSON responses from LLMs directly into parameterized INSERT statements, UPDATE queries, WHERE filters, and ORM objects (Knex, Prisma, Drizzle).

Readme

tson-sql 🚀

npm version license bundle size TypeScript

Advanced TSON to SQL Query Generator & ORM Payload Parser.

Convert TSON (Token-Structured Object Notation) responses from LLMs like Gemini, OpenAI GPT-4o, Claude, and Llama directly into Parameterized SQL Queries (INSERT, UPDATE, WHERE) and ORM payloads (Knex, Prisma, Drizzle).

Cut AI output generation costs & latency by 30% to 50%!


💡 Why tson-sql?

When forcing LLMs to output database payloads or SQL inserts:

  • Expensive Output Tokens: LLM output tokens cost 3x to 4x more than input prompt tokens.
  • Slow Output Speed: Generating full JSON arrays or raw SQL strings with repeating column names doubles generation latency.
  • SQL Injection Risk: Direct raw SQL string output from LLMs can expose your database to injection vulnerabilities.

tson-sql instructs your AI model to reply in compact TSON format, and safely generates parameterized SQL queries ($1, $2, ?) for PostgreSQL, MySQL, SQLite, and MSSQL.


📊 Token Savings & Speed Benchmark

| LLM Output Target | Standard JSON Output | TSON Output | Output Tokens Saved | Speedup | | :--- | :--- | :--- | :--- | :--- | | Extract 10 Rows | ~1,200 tokens | ~610 tokens | 590 tokens | ~2.0x Faster ⚡ | | Extract 50 Rows | ~5,800 tokens | ~2,350 tokens | 3,450 tokens | ~2.2x Faster ⚡ | | SQL Update Payload | ~250 tokens | ~120 tokens | 130 tokens | ~1.9x Faster ⚡ |


📦 Installation

npm install tson-sql
# or
yarn add tson-sql
# or
pnpm add tson-sql

⚡ Quick Start

1. Generate Parameterized PostgreSQL INSERT Query

import { tsonToSqlInsert } from 'tson-sql';
import { Pool } from 'pg';

const pool = new Pool();

// TSON response received from LLM
const llmTsonOutput = `
first_name: Abhi, Sarah
last_name: Asok, Chen
email: [email protected], [email protected]
role: Architect, AI Engineer
`;

// Generate Parameterized Query
const query = tsonToSqlInsert(llmTsonOutput, {
  tableName: 'users',
  dialect: 'postgres',
  returning: true
});

console.log(query.text);
// Output: INSERT INTO "users" ("first_name", "last_name", "email", "role") VALUES ($1, $2, $3, $4), ($5, $6, $7, $8) RETURNING *;

console.log(query.values);
// Output: ['Abhi', 'Asok', '[email protected]', 'Architect', 'Sarah', 'Chen', '[email protected]', 'AI Engineer']

// Execute safely with pg pool!
const result = await pool.query(query.text, query.values);

2. Generate Parameterized MySQL INSERT Query

import { tsonToSqlInsert } from 'tson-sql';

const query = tsonToSqlInsert(llmTsonOutput, {
  tableName: 'users',
  dialect: 'mysql'
});

console.log(query.text);
// Output: INSERT INTO `users` (`first_name`, `last_name`, `email`, `role`) VALUES (?, ?, ?, ?), (?, ?, ?, ?);

3. Generate Parameterized UPDATE Query

import { tsonToSqlUpdate } from 'tson-sql';

const tsonUpdate = `
id: 42
status: completed
paidAt: 2026-08-27T16:50:00.000Z
`;

const updateQuery = tsonToSqlUpdate(tsonUpdate, {
  tableName: 'orders',
  whereColumns: ['id'],
  dialect: 'postgres'
});

console.log(updateQuery.text);
// Output: UPDATE "orders" SET "status" = $1, "paidAt" = $2 WHERE "id" = $3;

4. Generate SQL WHERE Clauses from LLMs

import { tsonToSqlWhere } from 'tson-sql';

const tsonWhere = `
status: active, pending
role: Architect
`;

const where = tsonToSqlWhere(tsonWhere, { dialect: 'postgres' });
console.log(where.text);
// Output: WHERE "status" IN ($1, $2) AND "role" = $3

5. Interactive Terminal Demo

Run the interactive CLI demonstration:

npm run demo

🛠️ API Reference

| Function | Output | Description | | :--- | :--- | :--- | | tsonToSql(tsonStr, options?) | Record<string, any>[] | Parses TSON string into JavaScript SQL row objects. | | tsonToSqlInsert(tsonStr, options?) | { text, values, columns } | Generates parameterized SQL INSERT statements ($1, ?, @p1). | | tsonToSqlUpdate(tsonStr, options?) | { text, values } | Generates parameterized SQL UPDATE statements. | | tsonToSqlWhere(tsonStr, options?) | { text, values } | Generates parameterized SQL WHERE filter clauses. |


👤 Author & Contact

Developed with ❤️ by Abhi Asok.

For business inquiries, collaboration, or support:


📄 License

MIT © Abhi Asok