3.0.0 β€’ Published 3 months ago

mysql2-orm v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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)
πŸ’Ύdatadado
🎲dicedado

Acknowledgements

3.0.0

3 months ago

2.1.4

12 months ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

2.0.0-next.1

1 year ago

2.0.0-next.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago