4.0.1 • Published 5 months ago

@kiza/utils v4.0.1

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

Utils

Mostly mysql utilities for Node.js

npm install @kiza/utils

Setup connection string

Run once on startup:

const { connectionProvider } = require("@kiza/utils");
const config = require("config");
await connectionProvider.setConfig(config.database);

Where config.database is the object which will be passed to mysql2.createConnection

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:

const { mysqlBase } = require("@kiza/utils")

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

Transactions:

const { mysqlBase } = require("@kiza/utils")

module.exports = 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

v4

  • BIT maps to boolean automatically

v3

  • moved es6 imports
4.0.1

5 months ago

4.0.0

5 months ago

2.0.3

10 months ago

3.0.0

10 months ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.2.0

2 years ago

1.1.0

4 years ago

1.0.0

4 years ago