Socket
Socket
Sign inDemoInstall

mysql2-orm

Package Overview
Dependencies
11
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
3
Maintainers
1
Install size
2.03 MB
Created
Weekly downloads
 

Changelog

Source

3.0.0 (2024-02-06)

⚠ BREAKING CHANGES

  • upgrade to v3 (#3)

Features

Miscellaneous Chores

Readme

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

FAQs

Last updated on 06 Feb 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc