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

@itrocks/mysql

v0.1.2

Published

Transforms model objects to and from MySQL database records

Readme

npm version npm downloads GitHub issues discord

mysql

Transforms model objects to and from MySQL database records.

Summary

The @itrocks/mysql package provides a seamless integration with MySQL storage, supporting the common @itrocks/storage API while enabling advanced features for efficient data handling.

Standard API

The MySQL data source follows the standard @itrocks/storage API. For detailed usage, please refer to the official documentation

Advanced Features

To fully utilize MySQL storage capabilities, integrate and configure the following advanced features:

mysqlDependsOn

Configure custom behaviours for MySQL data operations. Example usage (the default):

import { mysqlDependsOn } from '@itrocks/mysql'

mysqlDependsOn({
	applyReadTransformer:   (record, property) => record[property],
	applySaveTransformer:   (object, property) => object[property],
	columnOf:               name => name.toLowerCase(),
	componentOf:            () => false,
	ignoreTransformedValue: Symbol('ignoreTransformedValue'),
	QueryFunction:          class {},
	queryFunctionCall:      () => [undefined, ' = ?'],
	storeOf:                target => typeOf(target).name.toLowerCase()
})

applyReadTransformer

applyReadTransformer: <T extends object>(record: AnyObject, property: KeyOf<T>, object: T) => any

Transforms a property value when reading data from the database, useful for deserialization or type conversion (e.g. string to Date).

Parameters:

  • record (AnyObject): The data record from MySQL.
  • property (KeyOf<T>): The property to transform.
  • object (T extends object): The object being constructed. It may be incomplete, as not all properties may have been transformed yet.

Return value:

  • The transformed value of property to assign to object.
  • Alternatively, return ignoreTransformedValue to leave the property value unchanged in object.

applySaveTransformer

applySaveTransformer: <T extends object>(object: T, property: KeyOf<T>, record: AnyObject) => any

Transforms a property value before saving to the database, e.g., for serialization (Date to string).

Parameters:

  • object (T extends object): The object being saved.
  • property (KeyOf<T>): The property to transform.
  • record (AnyObject): The database record to save. It may be incomplete, as not all properties may have been transformed yet.

Return value:

  • The transformed value of property to assign to record.
  • Alternatively, return ignoreTransformedValue to exclude the property and its value from record.

columnOf

columnOf: (property: string) => string

Maps a property name to a database column name, enabling custom naming conventions.

componentOf

componentOf: <T extends object>(target: T, property: KeyOf<T>) => boolean

Determines whether a property represents a tightly bound component relationship (e.g., one-to-one or many-to-one). Defining this function is highly recommended to ensure proper data access from your MySQL relational database.

By default, properties are assumed to represent related collections (e.g., many-to-many or one-to-many relationships).

ignoreTransformedValue

ignoreTransformedValue: any

This marker value is used to skip property transformation during read or save operations. It is returned by your implementation of applyReadTransformer and applySaveTransformer, as needed.

QueryFunction

QueryFunction: Type<QF>

Specificies a custom query function type for advanced search operations.

queryFunctionCall

queryFunctionCall: (value: QF) => [value: any, sql: string]

Processes custom query functions, returning the SQL fragment and associated values.

Parameters:

  • value: An object of a class derived from the one defined by QueryFunction.

Returns:

  • value: The value associated with the query function
  • sql: The corresponding SQL fragment

storeOf

storeOf: <T extends object>(target: ObjectOrType<T>) => string | false

Maps a class (ObjectOrType) to its corresponding database table name, allowing for custom naming conventions.