New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details → →
Socket
Book a DemoSign in
Socket

mysql2-orm

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql2-orm

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

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
29
-21.62%
Maintainers
1
Weekly downloads
 
Created
Source

MySQL2 ORM

Logo

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)
đź’ľdatadado
🎲dicedado

Acknowledgements

Keywords

mysql

FAQs

Package last updated on 06 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts