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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pma-network/sql

v1.1.0

Published

MySQL wrapper with promise-based async operations, connection pooling, and named parameters support

Readme

@pma-network/sql

MySQL wrapper built on mysql2 with promise-based async operations, connection pooling, and named parameter support.

Features

  • Auto-configuration from environment variables
  • Promise-based async operations
  • Connection pooling
  • Named parameters (:paramName) and positional (?) placeholders
  • Full TypeScript support
  • Transaction handling with automatic rollback
  • Resource-specific connection strings for FiveM

Installation

pnpm add @pma-network/sql

Or with npm:

npm install @pma-network/sql

Quick Start

Set the connection string environment variable:

# server.cfg (resource-specific):
set pma_characters_connection_string "mysql://user:password@localhost:3306/fivem"

# server.cfg (global fallback):
set mysql_connection_string "mysql://user:password@localhost:3306/fivem"

# Node.js:
export mysql_connection_string="mysql://user:password@localhost:3306/mydb"

Import and use:

import db from '@pma-network/sql';

const users = await db.query('SELECT * FROM users WHERE job_name = :job', { job: 'police' });
const insertId = await db.insert(
  'INSERT INTO users (identifier_id, char_data_id, first_name, last_name, inventory_id) VALUES (:identifier_id, :char_data_id, :first_name, :last_name, :inventory_id)',
  {
    identifier_id: 1,
    char_data_id: 1,
    first_name: 'John',
    last_name: 'Doe',
    inventory_id: 1
  }
);

Usage

Custom Instances

Create multiple database connections:

import { MySQL } from '@pma-network/sql';

const db1 = new MySQL({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'mydb',
});

const db2 = new MySQL({
  connectionString: 'mysql://user:password@remote:3306/otherdb',
});

API Reference

Configuration

Configuration is read using GetConvar (FiveM) with process.env fallback.

Priority order:

  1. Resource-specific: {resource_name}_connection_string

    • Resource name detected via GetCurrentResourceName()
    • Dashes converted to underscores: pma-characterspma_characters_connection_string
  2. Global fallback: mysql_connection_string

Connection string format: mysql://username:password@hostname:port/database

Required: mysql:// protocol, username, hostname, database name

Optional: password, port (default: 3306)

Examples

Named parameters:

await db.query('SELECT * FROM users WHERE first_name = :first_name AND job_name = :job', {
  first_name: 'John',
  job: 'police',
});

Positional parameters:

await db.query('SELECT * FROM users WHERE first_name = ? AND job_name = ?', ['John', 'police']);

Raw queries (no parameter processing - no named params, no @ conversion, no undefined->null):

// Use raw methods when you need direct control
const users = await db.rawQuery('SELECT * FROM users WHERE uid = ?', [1]);
const insertId = await db.rawInsert(
  'INSERT INTO users (identifier_id, char_data_id, first_name, last_name, inventory_id) VALUES (?, ?, ?, ?, ?)',
  [1, 1, 'John', 'Doe', 1]
);

// Regular methods process parameters automatically:
// - Convert @ to :
// - Support named parameters (:name)
// - Convert undefined to null
const users2 = await db.query('SELECT * FROM users WHERE uid = :uid', { uid: 1 });

TypeScript with type definitions:

import db from '@pma-network/sql';

interface User {
  uid: number;
  identifier_id: number;
  bank: number;
  char_data_id: number;
  first_name: string;
  last_name: string;
  job_name: string;
  job_rank: number;
  slot_id: number | null;
  model: string | null;
  inventory_id: number;
  x: number;
  y: number;
  z: number;
  is_deleted: boolean | null;
}

const users = await db.query<User[]>('SELECT * FROM users WHERE job_name = :job', { job: 'police' });
const user = await db.single<User>('SELECT * FROM users WHERE uid = :uid', { uid: 1 });

Transactions with success/failure:

const { success, result, error } = await db.transaction(async (execute) => {
  await execute('UPDATE users SET bank = bank + :amount WHERE uid = :uid', { amount: 1000, uid: 1 });
  await execute('UPDATE users SET job_name = :job, job_rank = :rank WHERE uid = :uid', {
    job: 'police',
    rank: 1,
    uid: 1
  });
  return { uid: 1 };
});

if (success) {
  console.log('Transaction committed:', result);
} else {
  console.error('Transaction rolled back:', error);
}

Batch operations for bulk inserts/updates:

const { success, result } = await db.batch([
  {
    query: 'INSERT INTO users (identifier_id, char_data_id, first_name, last_name, inventory_id) VALUES (:identifier_id, :char_data_id, :first_name, :last_name, :inventory_id)',
    parameters: { identifier_id: 1, char_data_id: 1, first_name: 'John', last_name: 'Doe', inventory_id: 1 }
  },
  {
    query: 'INSERT INTO users (identifier_id, char_data_id, first_name, last_name, inventory_id) VALUES (:identifier_id, :char_data_id, :first_name, :last_name, :inventory_id)',
    parameters: { identifier_id: 2, char_data_id: 2, first_name: 'Jane', last_name: 'Smith', inventory_id: 2 }
  },
  {
    query: 'UPDATE users SET job_name = :job WHERE uid = :uid',
    parameters: { job: 'police', uid: 1 }
  }
]);

if (success) {
  console.log(`Executed ${result.length} queries`);
}