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

mysql2sheet

v1.1.0

Published

Does what it says on the tin. Takes data in your MySql database and uploads it to a Google Sheet.

Downloads

92

Readme

MySql2Sheet

Does what it says on the tin. Takes data in your MySql database and uploads it to a Google Sheet.

Multiple MySql servers? No problem. Multiple sheets? No problem.

Usage

npx

npx mysql2sheet --path=./your_config.js

Local

npm install mysql2sheet
mysql2sheet --path=./your_config.js 

Path

In the example above, the path parameter refers to a path to a file containing the tasks to execute.

Task Definition

Your task definition file defines one or more tasks to execute. Each task has the following fields:

  • name - the name of the task
  • connection - the name of the mysql connection to use
  • schema - the schema to execute your query against
  • sql - the sql query to execute and retrieve results
  • mapData - function to map sql results to what needs to be uploaded to your sheet, note that the last result in your sql query is mapped here - go wild :)
  • type - result type, either scalar (single value) or table
  • googleCredential - the name of the Google Credential to use
  • googleSheetId - the sheet identifier to use (you can get this from the Sheet URL)
  • googleSheetRange - where to map the MySql query results to, example YOUR_SHEET_NAME!A1:A2
  • clearRange - boolean (defaults to false) - if true, clears the googleSheetRange before uplaoding data
Example Task Definition
const tasks = [
    {
        name: "Total Hours",
        connection: "prodtime",
        schema: "projects",
        sql: `select sum(time) as hours from timeentries`,
        mapData: (x) => [x.hours],
        type: 'scalar',
        googleCredential: "gcred",
        googleSheetId: "grab-sheet-id-from-sheet-url",
        googleSheetRange: "Stats!B2:B2",
    },
    {
        name: "Project Times",
        connection: "prodtime",
        schema: "projects",
        sql: `select name, sum(time) as hours from timeentries group by name`,
        mapData: (x) => [x.name, x.hours],
        type: 'table',
        clearRange: true,
        googleCredential: "gcred",
        googleSheetId: "grab-sheet-id-from-sheet-url",
        googleSheetRange: "Stats!E2:F",
    }
];

module.exports = {
    tasks: tasks,
    settings: {
        mysql: {
            prodtime: {
                host: "localhost",
                user: "root",
                password: "root",
                port: "3306"
            }
        },
        google: {
            gcred: {
                "type": "service_account",
                // ...
            }
        }
    }
};

MySql Connections and Google Credential Settings

Note how in the above example, connection and googleCredential refer to keys defined in the settings object.

To set up your Google Credentials, see https://www.npmjs.com/package/googleapis#service-account-credentials Note: Make sure you share the sheet (with Editor rights) with the email address noted in the client_email param of the service account JSON.