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

toubkal_mysql

v0.1.25

Published

Reactive MySQL library for Toubkal

Downloads

8

Readme

Reactive MySQL library

Build Status

npm version

API Stability: Unstable (API is under active development)

Install

$ npm install toubkal_mysql

Features

  • Reactive Toubkal pipelet: get updates in real-time, improves productivity
  • Hides MySQL credentials in JSON configuration file
  • Automatically reconnects to server, on disconnection-related errors while:
    • there are network issues
    • restarting MySQL server
    • rebooting server hosting MySQL server
    • prolongued shutdown of server hosting MySQL server
  • Waits indefinitely for ready MySQL (re)connection to process operations
  • Stateless, does not keep anything in memory, relies on MySQL cache
  • Can be cached explitity using set() pipelet
  • Dynamically creates optimized MySQL queries:
    • SELECT queries from downsteam pipelet queries provided by Toubkal filter() pipelets
    • DELETE queries from upstream remove operations using "key" option
    • INSERT queries from upstream add opeations using "columns" parameter
  • Allows column name aliases
  • Allows to define value converters per column:
    • from UUID to BINARY(16)
    • Toubkal timestamps to TIMESTAMP(3)
    • JSON to TEXT() or VARCHAR()
  • Emits detailled errors in error dataflow for downstream error reporting and recovery by reverting failed operations

Usage

Reading 'test.users' table

Getting a dataflow from "users" table in the "test" database using the "root" MySQL account:

var rs = require( 'toubkal' );

require( 'toubkal_mysql' )( rs );

rs.mysql( 'test.users',
    , [ 'id', 'email', 'first_name', 'last_name', 'city' ]
  )
  
  .filter( [ { city: 'NYC' } ] ) // Query using SELECT * FROM users WHERE city = "NYC"

  .trace( 'users' )              // displays users' from NYC

  .set()                         // Cache NYC users for downstream consumption
;

Updating 'test.users' Table

Updating users table only requires to connect a dataflow upstream of mysql - e.g. connecting authorized clients upstream of mysql():

var rs = require( 'toubkal_mysql' );

authorized_clients
    
  // Upstream (of mysql): updates, for DELETE and INSERT
  
  .mysql( 'test.users',
    [ 'id', 'email', 'first_name', 'last_name', 'city' ]
  )
  
  // Downstream (of mysql): fetching, and real-time updates
  
  ._add_destination( authorized_clients )
;

Where "authorized_clients" is a dataflow of authorized updates from clients;

Account Credentials Hiding in Configuration

The "root" account is defined in configuration file "~/config.rs.json", hiding credentials, e.g.

[
  {
    "id"      : "toubkal_mysql#root",
    "module"  : "toubkal_mysql",
    "name"    : "root",

    "mysql": {
      "host"    : "localhost",
      "user"    : "root",
      "password": "<password for root account>"
    }
  }
]

Where "mysql" object provides options for connecting to MySQL database. All connection options are from "mysql" npm module.

Many MySQL servers configurations can be defined simultaneously in the JSON configuration file by adding objects with a unique "id" assigned with the value "toubkal_mysql#<account name>".

Reference

mysql( table, columns, options )

Provides a Toubkal dataflow for MySQL "table".

Parameters:

  • table (String): MySQL table name. The table must exist in MySQL and must have a primary key that will be identical to the Pipelet's key unless aliased (see columns definition bellow).

  • columns (Array): defines all desired columns, and MUST include the primary key, to create SELECT, DELETE and INSERT queries. Each column is defined as:

    • (String): column name
    • (Object):
      • id: MySQL column name
      • as: dataflow attribute name, default is id
      • converter: to convert values of this column to/from mysql driver types. For more information on further mysql driver type convertions with MySQL types see Type casting. A converter can be specified as a string for built-in converters or an Object:
        • (String): a built-in converter, supported converters are:
          • "uuid_b16": converts a UUID to/from MySQL BINARY(16)
          • "timestamp_t3": converts Toubkal timestamp into TIMESTAMP(3) (requires MySQL 5.6.4 and up)
          • "json": converts JSON values to/from MySQL strings for TEXT() or VARCHAR()
        • (Object): Providing the following functions:
          • parse (Function): parse( value ) -> value to mysql driver
          • serialize (Function): serialize( <value from mysql driver> ) -> value
  • options (Object): optional attributes:

    • connection (String): "name" in configuration file, default is "root"
    • configuration (String): filename of configuration file, default is "~/config.rs.json"
    • mysql (Object): connection options for "mysql" npm module. These options supercede those from the configuration file, main options are:
      • host (String): e.g. "localhost"
      • user (String): e.g. "root"
      • password (String): e.g. "therootpassword"
      • database (String): e.g. "test"
    • key (Array of Strings): defines the primary key, may be aliased with columns parameter definition. default is [ 'id' ]

Licence

The MIT License (MIT)

Copyright (c) 2015-2018, Reactive Sets

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.