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

@itrocks/mysql

v0.1.7

Published

Transforms model objects to and from MySQL database records

Readme

mysql

Transforms model objects to and from MySQL database records.

Summary

The @itrocks/mysql package provides integration with MySQL storage and implements the standard @itrocks/storage DataSource API.

Standard API

The MySQL data source follows the standard @itrocks/storage API. Refer to the storage documentation for generic behaviours.

Advanced Features

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

mysqlDependsOn

Configure custom behaviours for MySQL data operations.

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 => target.constructor.name.toLowerCase()
})

applyReadTransformer

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

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

Parameters:

  • record (AnyObject): The data record from MySQL.
  • property (KeyOf<T>): The name of the property.
  • object (T extends object): The object the property value must be written to. It may be partially initialised.

Returns:

  • The transformed value of property to assign to object.
  • Returning ignoreTransformedValue leaves the property unchanged.

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 which property value must be transformed.
  • property (KeyOf<T>): The name of the property.
  • record (AnyObject): The data record for MySQL writing. It may be partially set.

Returns:

  • The transformed value of property to assign to record.
  • Returning ignoreTransformedValue excludes the property from persistence.
  • Returning an array schedules a collection save.
  • Returning a function schedules a deferred operation.

Deferred operation (returning a function):

When applySaveTransformer() returns a function, it is not written to the SQL record.
Instead, it is stored and executed after the object save operation completes.

The callback will receive the persisted object as first argument.

columnOf

(property: string) => string

Maps an object property name to a database column name.

componentOf

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

Indicates whether a collection property is stored as components (one-to-many / owned) instead of a link table.

ignoreTransformedValue

Marker value used by transformers to prevent persistence or assignment after the callback is executed.

QueryFunction

Type<QF>

Base class for custom query functions.

queryFunctionCall

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

Converts a query function into a SQL fragment and its bound value.

Parameters:

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

Returns:

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

storeOf

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

Maps a class or object to its table name. Returning false disables persistence for that type.