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

@mahudas/mariadb

v0.0.4

Published

mariadb plugin for mahudas

Downloads

3

Readme

@mahudas/mariadb

Dependencies

  • mahudas^0.1.2
  • mariadb^3.1.1

As a plugin

如同一般的plugin,透過npm安裝之後,在Application的plugin.env.js裡設定啟用。

npm i @mahudas/mariadb -s
// config/plugin.deafult.js
module.exports = {
  mariadb: {
    enable: true,
    package: '@mahudas/mariadb',
  },
}

設定

// config/config.default.js
module.exports = {
  mariadb: {
    host: '127.0.0.1',
    port: 3306,
    user: 'user',
    password: 'password',
    database: '',
    charset: 'utf8mb4',
    timezone: '+08:00',
    acquireTimeout: 20000,
  },
}

參數

請參考 Mariadb Pool options

Example

get 和 find, insert, update, delete 是擴充的 function

Get/Find

// controller.js or service.js or middleware.js
await app.mariadb.get('SELECT NOW() AS currentTime;');
// > { currentTime: 2023-03-20T03:11:13.000Z }
await app.mariadb.find('SELECT NOW() AS currentTime;');
// > [{ currentTime: 2023-03-20T03:11:13.000Z }, meta: []]

Insert

const insert_data = {
    foo: 'bar',
}
await app.mariadb.insert('table_name', insert_data);
// > { status: true, insertId: 1 }

Update

const update_data = {
    foo: 'barU',
}
const where = {
    id: 1
}
await app.mariadb.update('table_name', update_data, where);
// > true

Delete

const delete_where = {
    id: 1
}
await app.mariadb.delete('table_name', delete_where);
// > true

Transaction

const transactionConn = await app.mariadb.beginTransaction();
const insert_data = {
    foo: 'bar',
}
await app.mariadb.insert('table_name', insert_data);
await transactionConn.commit();

// 因為 transactionConn 已經 commit,為了重複使用connection,所以用參數的方式帶入現有的 connection
const deleteTransactionConn = await app.mariadb.beginTransaction(transactionConn);
const delete_where = {
    id: 2
}
await app.mariadb.delete('table_name', delete_where);
deleteTransactionConn.rollback();
// > no delete

// 最後記得要手動釋出 connection
deleteTransactionConn.end();

一般使用

// 要先取得 connection,在用 conn 去 query
// 最後記得要 conn.end();
const conn = await app.mariadb.getConnection();
try{
    return await conn.query('SELECT NOW() AS currentTime;');
}catch (e) {
    await conn.end();
    throw e;
}finally {
    await conn.end();
}