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

mysql-update-query-builder

v2.0.0

Published

Simplify MySQL record updates with targeted precision using the mysql-update-query-builder library.

Downloads

7

Readme

mysql-update-query-builder

Simplifying Patch Updates for MySQL Records

Have you ever been frustrated by the process of updating a single field in a MySQL record? I certainly was. As a developer, I found myself facing a common issue: every time I needed to update just one field in a record, I had to send the entire payload back to the server, even if only one value had changed. This not only felt inefficient but also cluttered the data transfer unnecessarily.

I knew there had to be a better way. That's why I created mysql-update-query-builder. This lightweight JavaScript library was born out of the need for a more elegant solution to the common problem of updating records with precision.

The Solution: Fluent and Targeted Updates

With mysql-update-query-builder, you're no longer constrained by the traditional approach of sending a barrage of fields for a single update. Instead, you can take a more targeted approach. If you only need to update a single field, you can now send just that field's new value, keeping your data transfers lean and efficient.

Installation

You can install mysql-update-query-builder using npm:

npm install mysql-update-query-builder

Usage

const mysqlUpdate = require("mysql-update-query-builder");

const body = { username: "ali", age: 55 };
const updateQuery = mysqlUpdate.update("users").set(body).where({ id: 1 }).build();

console.log(updateQuery); // UPDATE users SET username = 'ali', age = 55 WHERE id = 1

Methods

  • update(table)

Initialize the query with the specified table for the UPDATE operation.

table (String): The name of the table to perform the update on.

Returns the mysqlUpdate object for method chaining.

  • set(body, filter)

Specify the columns and values to be updated in the query.

body (Object): An object containing the columns and values to be updated.

filter (Object, optional): An optional filter configuration object with properties like ignore and add to customize column updates. If provided, the ignore property should be an array of column names that you want to exclude from the update, and the add property should be an array of column names that you want only to include in the update.

For example, if you have a body object with several columns and you only want to update specific columns while ignoring others, you can use the filter parameter to achieve that. Here's how you can use it:

const body = { username: "ali", age: 55, email: "[email protected]" };

const filter = {
    ignore: ["age", "email"], // Columns to ignore during update
};

// OR

const filter = {
    add: ["username", "age"] // Columns to only include for update
};

const updateQuery = mysqlUpdate.update("users").set(body, filter).where({ id: 1 }).build();
  • where(identifier)

Specify the condition for the WHERE clause in the query.

identifier (Object): An object representing the condition for the WHERE clause.

  • build()

Returns the complete query string.

License

This project is licensed under the MIT License.