FastORM
MySQL ORM (or wrapper) based on node-mysql2 client. Node MySQL2 is focus on performance, we focus on make easy get information on tables. Supports find, insert, delete, update and join methods with limit, order by and projection of columns.
Table of contents
- History and Why MySQL2
- Installation
- First Query
- Not only find method available
- Paginate results
- Authors
- Documentation
- Acknowledgements
- Contributing
History and Why MySQL2
FastORM project it is a necessity of have a fast and easy tool to work with MySQL in our company (and maintainable). We need migrate Sequalize (good ORM, but in our experience with great memory consumption). Our tool have great influence of MongoDB syntax.
FastORM is mostly compatible (and dependent) of node-mysql2 and supports majority of features. We also offers these features and more
- Faster / Low latency
- Multi-connections
- MySQL Binary Log Protocol
- Async/await support
- Extended support for Encoding and Collation
- Use objects as properties like some MongoDB ORM's
- Values as objects in where properties
- Compression (inherited from node-mysql2)
- Joins between two tables (for now)
- Common methods for MySQL (find, insert, delete...)
- Easy!
Installation
FastORM is free from native bindings and can be installed on Linux (tested), Mac OS or Windows without any issues.
npm install --save fastorm
First Query
// get the ORM; // create the connection to databaseconst connection = await ; // Create model to User tableconst User = 'User' connection; // Get all records on Userconst users = User; // Get one recordconst only_one_user = User; // Get all user with name Juan and aliveconst all_juanes = User // Same with limit 5 and order by age DESCconst only_five_juanes = User // Get all user with name not equal to Juan and dead// Accept $ne, $lt, $lte, $gt, $gte as properties in valueconst all_no_juanes = User
find
method available
Not only With FastORM you can also insert, delete and join records since the model. It's possible execute "raw" queries too, the module provides query
method to this.
FastORM provides insert
, delete
, join
and other methods within the model to work with the records on tables.
// get the ORM; // create the connection to databaseconst connection = await ; // create other connection to other database and serverconst other_connection = await ; // Create model to User tableconst User = 'User' connection; // Create model to Post tableconst Post = 'Post' connection; // Create model to Other table in other server (multiple connections, cool!)const Other = 'Other' other_connection; // Create user Maria with age 36 and not alive// IMPORTANT: automatically created_at and updated_at columns// are inserted, you must have these DATETIME columns on the tableconst users = await User; // Delete users with name pedro and not aliveconst deleted = await User // Get all posts of user juan with columns: name, title and descriptionconst posts = await User
Paginate results
We create a paginate
method to facilite managing cursors with lots of information or simply paginate results of any query. In a moment of this history we create an paginate to Sequalize available here.
// Paginate all posts of user juan with columns: name, title and description// Return { objects, nextCursor } when objects are data found, and nextCursor// is the property keyPaginated of the next row used to paginate again (sinceId)const juanes_paginated = await User
Authors
- Jinme Mirabal @mirabalj
- Leon Peña @ldpenal
- Sergio Cruz @sergiocruza
Documentation
You can find more detailed documentation here. You should also check various code examples to understand advanced concepts.
Acknowledgements
- To @sidorares and your team by node-mysql2 module node-mysql2
Contributing
Want to improve something in fastorm
. Please check Contributing.md for detailed instruction on how to get started.