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

de-identify-sql

v1.0.4

Published

De-identify data in SQL statements

Downloads

8

Readme

De-identify SQL

De-identify data in SQL statements.

De-identify data in SQL example

About

De-identify SQL removes protected data from a .sql file or piped input (e.g. mysqldump) and sends results to stdout or a new .sql file. De-identify SQL replaces protected data / PII / PHI using the following techniques:

  • Replacing data with a fabricated value.
  • Redacting data with a constant value.
  • Generating new data (customizable JavaScript).

De-identify SQL supports:

  • Reading from piped input or a passed-in file.
  • Writing to piped output or creating a file.

Installation

Install globally using npm i -g de-identify-sql

Usage

> de-identify-sql -h
Options:
  -v, --version            Show version number                         [boolean]
  -h, --help               Show help                                   [boolean]
  -o, --outputFile         Output to file instead of stdout             [string]
  -i, --inputFile          Read from file instead of stdin              [string]
  -s, --strategyDirectory  Location of SQL strategy files
                                   [string] [default: {installed-dir}/strategy}]
  -f, --functionsFile      Location of file that contains all custom functions
                           (optional, overwrites .js per table)         [string]

Examples

# Read from piped input, write to piped output ...
> mysqldump my-database | de-identify-sql | gzip > de-id-mysqldump.sql.gz
# Read from piped input, write to .sql ...
> mysqldump my-database | de-identify-sql -o de-id-mysqldump.sql
# Read from .sql, write to piped output ...
> de-identify-sql -i mysqldump.sql | gzip > de-id-mysqldump.sql.gz
# Read from .sql, write to .sql ...
> de-identify-sql -i mysqldump.sql -o de-id-mysqldump.sql
# Read from .sql, write to screen (test de-identification) ...
> de-identify-sql -i mysqldump.sql
# or
> cat mysqldump.sql | de-identify-sql

De-identifying data within SQL

De-identify SQL uses strategy files which are mapped to tables to modify SQL statements. Strategy files should be placed in the /strategy folder (configurable) and named after the table they act on. If the incoming SQL contains USING the format is DATABASE_NAME.TABLE_NAME.json otherwise the format is TABLE_NAME.json. A CREATE TABLE statement must be part of the input file.

Example: /strategy/user.json

{
  "columns": [
    {
      "redactWith": "internet.email",
      "columnKey": "email",
      "tracked": false
    },
    {
      "redactWith": "NAME REMOVED",
      "columnKey": "name",
      "tracked": false
    },
    {
      "redactWith": "generateDatetime",
      "columnKey": "last_visit",
      "tracked": false
    },
    {
      "redactWith": "{{datatype.number({\"min\":18,\"max\":90})}}",
      "columnKey": "age",
      "tracked": false
    }
  ]   
}

The columns array describes how each SQL column should be modified. Omitted columns pass-through without modification.

  • columnKey - (string) The column to be modified by de-identify-sql.

  • redactWith - (string) There are four ways to de-identify data:

    • A faker function - Possible functions : e.g. name.lastName or phone.phoneNumber
    • A faker template - A mustache template of faker methods: e.g. {{name.firstName}} {{name.lastName}}, {{name.jobTitle}} or {{address.streetAddress}} {{address.city}}
    • Custom JavaScript - You can call a function to create a value, these are defined in a .js file that matches the name of the .json file
    • A constant value - Replace with a constant, e.g. VALUE REMOVED
  • tracked - (boolean) Tracking preserves data relationships while de-identifying SQL.

Tracking: Data Relationships

De-identify SQL can preserve relationships within data. If original data repeats, de-identify SQL recognizes and replaces it with the same value it previously used.

This allows the generated SQL to retain its structure while removing protected data. For example, if there are multiple INSERTs which contain the same email address these would become different email addresses. However, if the tracked parameter is true, then every instance will be replaced with the same made-up value.