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 🙏

© 2024 – Pkg Stats / Ryan Hefner

squeakql

v0.0.4

Published

Squeakql is a SQL query builder and utility library that combines best practices, security, and a fluent API for effortlessly building SQL queries. Optimized for TypeScript, Squeakql is designed to be simple, efficient, and powerful, making database inter

Downloads

17

Readme

Squeakql: The Fluent SQL Builder for JavaScript

Squeakql is a SQL query builder and utility library that combines best practices, security, and a fluent API for effortlessly building SQL queries. Optimized for TypeScript, Squeakql is designed to be simple, efficient, and powerful, making database interactions more robust and developer-friendly.

Features

  • Type Safety: Full TypeScript support for static type checking.
  • Fluent API: Effortlessly chain methods to build SQL queries.
  • SQL Injection Prevention: Enhanced security measures to protect against SQL injections.
  • String Interpolation: Utilize JavaScript template literals for cleaner code.
  • Built-In Helper Functions: Easily insert, update, and select records with minimal code.

Quickstart

installation

bun add squeakql
# or
npm install squeakql

quick usage

import { sql } from "squeakql";

const query = sql`SELECT * FROM users WHERE id=${userId}`;

API Highlights

SQL Insert Helper

const [queryStr, values] = insert("users", { username: "johndoe", age: 25 });

Generates: INSERT INTO users (username, age) VALUES ($1, $2) RETURNING *

Template Tag

Squeakql uses template string literals to interpolate values safely preventing sql injection while allowing you to write readable sql!

const query = sql`SELECT * FROM table WHERE a=${val} and b=${val2}`;

Example SQL Injections prevention

Squeakql protects against SQL injections both in literals and values.

injectCode = "abc' OR 1=1;--";
const query = sql`SELECT * from tables WHERE col=${injectCode}`.render();

Will return a properly escaped query:

SELECT * from tables WHERE col='abc'' OR 1=1;--'

sql helpers

  • insert(table: string, vals: Dictionary|Dictionary[], ignorConflict = false)
  • update(table: string, vals: Dictoinary, id: string)
  • sql.basicSelect()
  • sql.unsafe()
  • sql.merge()
  • sql.values()
  • sql.setters()
  • sql.columns()
  • sql.insert()
  • sql.basicUpdate()
  • sql.updateMany()

Query Builder

Use query builder to build sql selects:

import { sql } from "squeakql";

qb = new QueryBuilder("table_name");
console.log(qb.compile().render());
// returns> SELECT t.* FROM ONLY table_name AS t

Use for out-of-order query building

qb = new QueryBuilder("table_name");
qb.addOrderBy(sql`created_ts DESC`);
qb.addWhereClause(sql`a = ${one}`);
qb.addSelectableColumn("created_ts");
console.log(qb.compile().render());

query builder functions

qb.addSelectableColumn(column: string | SqueakqlQuery, as?: string)
qb.addWhereClause(clause: SqueakqlQuery)
qb.addHavingClause(clause: SqueakqlQuery)
qb.addWithClause(name: string, clause: SqueakqlQuery)
qb.addDistinctColumn(column: string | SqueakqlQuery)
qb.addSearchTerm(clause: SqueakqlQuery) // basically a where clause, but gets "OR"d
qb.addOrderBy(orderBy: SqueakqlQuery)
qb.addRawJoin(sqlJoinClause: SqueakqlQuery)
qb.joinTables(
    tableA: BaseTable,
    tableB: BaseTable,
    joinColumnOfTableB: string,
    useLeft = true
  )
qb.addGroupBy(groupByClause: SqueakqlQuery)
qb.baseTable.tableName // "table_name"
qb.baseTable.alias // "t"