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

lupdo-mysql

v2.0.0

Published

Mysql Driver For Lupdo

Downloads

17

Readme

Lupdo-mysql

Lupdo Driver For Mysql.
Api

Supported Databases

  • mysql (v5.6, 5.7, 8)
  • mariadb (v10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11)

Third Party Library

Lupdo-mysql, under the hood, uses stable and performant npm packages:

Usage

Base Example

const { createMysqlPdo } = require('lupdo-mysql');
// ES6 or Typescrypt
import { createMysqlPdo } from 'ludpo-mysql';

const pdo = createMysqlPdo(
    {
        host: 'localhost',
        port: 3306,
        user: 'user',
        password: 'password',
        database: 'database'
    },
    { min: 2, max: 3 }
);

const run = async () => {
    const statement = await pdo.query('SELECT 2');
    const res = statement.fetchArray().all();
    console.log(res);
    await pdo.disconnect();
};

run();

Driver Options

https://github.com/mysqljs/mysql#connection-options

Note The host option also accepts a list of host:port the pool will generate the connection using a random host from the list.

Mysql2 Overrides

By default Ludpo-mysql overrides user connection options with this:

{
    rowsAsArray: true,
    namedPlaceholders: true,
    dateStrings: false,
    supportBigNumbers: true,
    bigNumberStrings: true,
    decimalNumbers: false,
    typeCast: typeCast,
    timezone: 'Z',
    stringifyObjects: true,
    multipleStatements: false,
    trace: false,
    flags: [],
    queryFormat: undefined,
    debug: ${ATTR_DEBUG}
}

Lupdo-mysql has a custom type parser

  • boolean are returned as number 1 or 0.
  • bigint are returned as number or BigInt when necessary.
  • binary and blob are returned as Buffer.
  • zerofill numbers are returned as string.
  • all geometry are returned as json string, coordinates are identified as x,y.
  • all others types are always returned as string.

Parameters Binding

Lupdo-mysql ignore type definition of TypeBinding parameter.
Lupdo-mysql does not support array of parameters.

Mysql Named Parameter

Lupdo-mysql support named parameter with syntax :name, the support is guaranteed only if all placeholder have a binding.\

Mysql Numeric Parameter

Lupdo-mysql support numeric parameter with syntax ?.

Timezone and Charset

Lupdo-mysql default charset is UTF8MB4_UNICODE_CI, you can override through config.

Lupdo-mysql force mysql2 timezone to Z, javascript Date bindings for timestamp will be converted in String using UTC timezone.

Warning If you want to store an exact timestamp, you must bind a string or a UTC date like new Date(Date.UTC(2023, 0, 1, 23, 22, 20, 123)); using new Date('2023-01-01 23:22:20.123') will generate a UTC date based on OS timezone.

You can assign Mysql timezone through lupdo create callback in this way.

const { createMysqlPdo } = require('lupdo-mysql');
// ES6 or Typescrypt
import { createMysqlPdo } from 'ludpo-mysql';

const pdo = createMysqlPdo(
    {
        host: 'localhost',
        port: 3306,
        user: 'user',
        password: 'password',
        database: 'database'
    },
    {
        min: 2,
        max: 3,
        created: async (uuid, connection) => {
            await connection.query("SET time_zone='Europe/Rome';");
        }
    }
);

Kill Connection

Lupdo-mysql support kill query.