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

mysql2-orm

v3.0.0

Published

🎲 An ORM built on MySQL2, designed to be intuitive, productive and focused on essential functionality

Downloads

27

Readme

MySQL2 ORM

An ORM built on MySQL2, designed to be intuitive, productive and focused on essential functionality.

NPM Version NPM Downloads GitHub Workflow Status (with event) License

  • This project uses mysql2/promise, createPool and execute behind the scenes.

🎲 Documentation Website


Table of Contents


Why

  • An user-friendly ORM for INSERT, SELECT, UPDATE, DELETE and WHERE clauses.
  • Automatic Prepared Statements (including LIMIT and OFFSET).
  • You can also simply use QueryBuilder to mount your queries and use them in your original MySQL2 connection.
  • It will smartly detect and release the connection when using commit or rollback in a transaction.
  • It exposes the execute and query original methods from MySQL2 Pool class.
  • Strictly Typed: No usage of any, as neither satisfies at all.

Documentation

See detailed specifications and usage in Documentation section for queries, advanced concepts and much more.


Quickstart

Installation

npm i mysql2-orm

If you are using TypeScript, you will need to install @types/node.

npm i -D @types/node

Import

import { MySQL } from 'mysql2-orm';

Connect

const pool = new MySQL({
  host: '',
  user: '',
  database: '',
  // ...
});

Basic Usage Example

The following example is based on TypeScript and ES Modules, but you can also use JavaScript and CommonJS.

const user = await pool.select({
  table: 'users',
  where: OP.eq('id', 16),
  limit: 1,
});
  • See all available operators (OP) here.
  • Due to limit: 1, it returns a direct object with the row result.
  • The result of getUser will be a RowDataPacket or false.

It's equivalent to:

import mysql, { RowDataPacket } from 'mysql2/promise';

const pool = mysql.createPool({
  // ...
});

const [users] = execute<RowDataPacket[]>(
  'SELECT * FROM `users` WHERE `id` = ? LIMIT ?',
  [16, '1']
);

const user = users?.[0] || false;

Close the Connection

await pool.end();

Curiosity

Why a dice?

While in English dice and data each have their own word, in Brazil, both the dice and "data" are called "dado" even though they refer to different things:

| | 🇺🇸 English | 🇧🇷 Portuguese (BR) | | --- | ---------- | ------------------ | | 💾 | data | dado | | 🎲 | dice | dado |


Acknowledgements