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

lia-mysql

v1.0.1

Published

JavaScript library of data standards.

Downloads

5

Readme

Mysql Installer

Simplify the use of MySQL

Installer

Using npm:

$ npm install lia-mysql

How to Use MysqlInstaller

1.1 Mysql Initial (single mode)

import {MysqlInstaller,MysqlConfig} from "core-mysql";
const TARGET = {SQL: {}};
const config = {
    host: "127.0.0.1",
    port: 3306,
    user: "root",
    password: "root12345",
    database: "test"
}
const installer = new MysqlInstaller(config as MysqlConfig,TARGET,'sys|info');
await installer.load();

1.2 Mysql Use (single mode)

query

const result = await TARGET.SQL.query('select * from users where id=?', [100])
console.log(result);

Insert

const row = {
  name: 'fengmk2',
  otherField: 'other field value',
};
const result = await TARGET.SQL.insert('table-name', row);
console.log(result);
  • Insert multi rows
const rows = [{
    name: 'fengmk2',
    otherField: 'other field value',
}, {
    name: 'fengmk3',
    otherField: 'other field value',
}];
const result = await TARGET.SQL.insert('table-name', rows);
console.log(result);

Update

  • Update a row with primary key: id
const row = {
  id: 123,
  name: 'fengmk2',
  otherField: 'other field value',
};
const result = await TARGET.SQL.update('table-name', row);
console.log(result);
  • Update a row with options.where and options.columns
const row = {
  name: 'fengmk2',
  otherField: 'other field value',
};
const result = await TARGET.SQL.update('table-name', row, {
  where: { name: row.name },
  columns: [ 'otherField' ]
});
console.log(result);

Update multiple rows

  • Update multiple rows with primary key: id
const options = [{
  id: 123,
  name: 'fengmk2',
  email: '[email protected]',
  otherField: 'other field value',
}, {
   id: 124,
  name: 'fengmk2_2',
  email: 'm@fengmk2_2.com',
  otherField: 'other field value 2',
}]
const result = await TARGET.SQL.updateRows('table-name', options);
console.log(result);
  • Update multiple rows with row and where properties
const options = [{
  row: {
    email: '[email protected]',
    otherField: 'other field value',
  },
  where: {
    id: 123,
    name: 'fengmk2',
  }
}, {
  row: {
    email: 'm@fengmk2_2.com',
    otherField: 'other field value2',
  }, 
  where: {
    id: 124,
    name: 'fengmk2_2',
  }
}]
const result = await TARGET.SQL.updateRows('table-name', options);
console.log(result);

Get

  • Get a row
const row = await TARGET.SQL.get('table-name', { name: 'fengmk2' });

=> SELECT * FROM `table-name` WHERE `name` = 'fengmk2'

2.1 Mysql Initial (multi mode)

import {MysqlInstaller,MysqlConfig,MysqlConfigs} from "core-installer";
const TARGET = {SQL: {}};
const config = {
    APP1:{
        host: "127.0.0.1",
        port: 3306,
        user: "root",
        password: "root12345",
        database: "test"
    }
}
const installer = new MysqlInstaller(config as MysqlConfigs<MysqlConfig>,TARGET,'sys|info');
await installer.load();

2.2 Mysql Use (multi mode)

The multi-instance mode is basically the same as the single-instance mode, except that the database instance needs to be specified on the SQL instance, for example:

query

const result = await TARGET.SQL.APP1.query('select * from users where id=?', [100])
console.log(result);

For other operations, please refer to the single mode