5.1.0 • Published 12 months ago

@kiza/utils v5.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
12 months ago

Utils

Mostly mysql utilities for Node.js

npm install @kiza/utils

Setup connection string

Run once on startup:

import { poolProvider } from "@kiza/utils";
import mysql from 'mysql2/promise';
import config from "config";

await poolProvider.setPool(() => mysql.createPool(config.database));

Example of config:

{
    "host": "localhost",
    "user": "root",
    "password": "password",
    "database": "mydb",
    "dateStrings": true,
    "port": 3306,
    "charset": "utf8mb4"
}

Use mysqlBase

See example in testApp.js

Create your repositories like:

import { mysqlBase } from "@kiza/utils";

export default class extends mysqlBase {
    static getJobs(siteId) {
        return this.all("SELECT * FROM job WHERE siteId = ? ORDER BY posted DESC", [siteId]);
    }
}

Transactions:

import { mysqlBase } from "@kiza/utils";

export default class extends mysqlBase {
    static addJobs(job, job2) {
        return this.inTransacation(async con => {
            await this.insert("INSERT INTO job SET ?", job, con);
            await this.insert("INSERT INTO job SET ?", job2, con);
        });
    }
}

Publish package

Note to self

npm publish --access public

Change log

v5

  • Remove dep on mysql2 package, pool should be provided by consumer. This lets the consumer manage the mysql version
  • Remove guid util. node:crypto should be used instead

v4

  • BIT maps to boolean automatically

v3

  • moved es6 imports
5.1.0

12 months ago

5.0.0

12 months ago

4.0.1

2 years ago

4.0.0

2 years ago

2.0.3

2 years ago

3.0.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

3 years ago

1.1.0

5 years ago

1.0.0

5 years ago