Hide meta object data in mariaDB when using nodejs

1.2k Views Asked by At

I'm logging the result of some certain query and it's working fine, but I have noticed there are too much metadata are logged as well, how can I disable these metadata from being logged in?

screenshot

    const pool = mariadb.createPool({
        host: 'localhost',
        port: 3306,
        user: 'example',
        password: 'pass',
        waitForConnections: true,
        connectionLimit: 10
    });

    async function asyncFunction () {
        let conn;
        try {
            conn = await pool.getConnection();
            const queryResult = await conn.query('select * from test.sb__user where id=94');
            console.log(queryResult); // [ {val: 1}, meta: ... ]
        } catch (err) {
            throw err;
        } finally {
            if (conn) return conn.end();
        }
    }
3

There are 3 best solutions below

0
Tomas B On

Using lodash exclude the meta value from the queryResult array:

_.difference(queryResult, ['meta'])
0
JoeCrash On

I used the delete keyword to remove the meta, following Tomas B's example but using Vanilla JS instead.

delete queryResult.meta;
0
Tabea On

As of 2023 you can use the option metaAsArray.

const mariadb = require('mariadb');
const pool = mariadb.createPool({
    host: 'mydb.com', 
    user:'myUser', 
    password: 'myPassword',
    connectionLimit: 5,
    metaAsArray: false //hide 'meta' fields
});

const connection = await pool.getConnection()

Reference from the docs, chapter Other Options.