Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Gorm | 33,712 | 5,368 | 2 days ago | 267 | June 10, 2023 | 282 | mit | Go | ||
The fantastic ORM library for Golang, aims to be developer friendly | ||||||||||
Mikro Orm | 6,495 | 157 | 18 hours ago | 2,010 | August 07, 2023 | 74 | mit | TypeScript | ||
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases. | ||||||||||
Sequelize Docs Zh Cn | 2,949 | 3 months ago | 26 | gpl-2.0 | ||||||
Sequelize 文档的中文版本: v7.0.0-alpha.18 | v6.32.0 | ||||||||||
Kiss Orm | 458 | 6 months ago | 13 | January 03, 2021 | mit | TypeScript | ||||
An extremely simple and explicit ORM for TypeScript | ||||||||||
Rdb | 378 | 3 | 1 | 3 days ago | 178 | November 17, 2022 | 6 | isc | JavaScript | |
The ultimate ORM for Node and Typescript | ||||||||||
Sequelizer | 316 | 7 months ago | 6 | other | JavaScript | |||||
A GUI Desktop App for export sequelize models from database automatically. | ||||||||||
Crud | 300 | 1 | 2 years ago | 25 | November 29, 2021 | 1 | mit | Go | ||
Relational database library for SQL databases & Go. | ||||||||||
Gosql | 288 | 7 | 5 months ago | 37 | June 29, 2022 | 12 | mit | Go | ||
🐥The very simple ORM library for Golang | ||||||||||
Mysql | 252 | 14 days ago | 19 | mit | TypeScript | |||||
MySQL driver for Deno | ||||||||||
Sails Mysql Transactions | 58 | 2 | 1 | 2 years ago | 33 | September 26, 2019 | 75 | apache-2.0 | JavaScript | |
sails/waterline ORM with mySQL transaction support |
sails-mysql-transaction
is a Sails ORM Adapter for MySQL with transaction and replication cluster support.
This adapter essentially wraps around the popular sails-mysql
adapter and provides additional API to perform
operations that ties around a database transaction. It also provides to read from a cluster of read-replicas in a
load-balanced fashion.
Add sails-mysql-transactions
to your application’s package.json
. Do not run install directly if sails
is not
already installed in your package.
If you already have sails-mysql
installed, it might interfere with operations of this module. Remove it from your
package.json
and uninstall the same using npm remove sails-mysql
.
This package installs successfully only when sails is already installed in the package. If the package is already
installed, then simply run npm install sails-mysql-transactions --save
, otherwise run npm install
and it will take
care of rest.
If npm install
seems erratic to install dependencies in order, you could add the following in your package.json
as
a postinstall script of npm. This would ensure that this module is installed after
sails has been completely installed. Note that in this method, you would not need to add sails-mysql-transactions
as a
dependency in your package.json
{
"scripts": {
"postinstall": "npm install sails-mysql-transactions"
}
}
This package overwrites the waterline
module inside Sails with a fork of Waterline maintained by Postman. As such,
if you ever re-install or update sails, ensure you re-install this adapter right after it.
Do check SailsJS compatibility list before upgrading your Sails version while already using this adapter.
The integration test Sails App located in tests/integration/app
directory of this repository has a fully functional
installation. Simply run npm install
within test/integration/app
directory.
module.exports = {
/* your other config stay as is */
connections: {
mySQLT: {
adapter: 'sails-mysql-transactions',
host: '{{your-db-host}}',
user: '{{your-db-username}}',
password: '{{your-db-password}}',
database: '{{your-db-tablename}}',
transactionConnectionLimit: 10,
rollbackTransactionOnError: true,
queryCaseSensitive: false,
/* this section is needed only if replication feature is required */
replication: {
enabled: true,
inheritMaster: true,
canRetry: true,
removeNodeErrorCount: 5,
restoreNodeTimeout: 1000 * 60 * 5,
defaultSelector: 'RR', // 'RANDOM' or 'ORDER'
sources: {
readonly: {
enabled: true,
host: '{{replica-1-host}}',
user: '{{replica-1-user}}',
password: '{{replica-1-password}}'
}
}
}
}
},
models: {
connection: 'mySQLT'
}
}
var Transaction = require('sails-mysql-transactions').Transaction;
module.exports = {
create: function (req, res) {
// start a new transaction
Transaction.start(function (err, transaction) {
if (err) {
// the first error might even fail to return a transaction object, so double-check.
transaction && transaction.rollback();
return res.serverError(err);
}
OneModel.transact(transaction).create(req.params.all(), function (err, modelInstance) {
if (err) {
transaction.rollback();
return res.serverError(err);
}
// using transaction to update another model and using the promises architecture
AnotherModel.transact(transaction).findOne(req.param('id')).exec(function (err, anotherInstance) {
if (err) {
transaction.rollback();
return res.serverError(err);
}
// using update and association changes
modelInstance.someAssociatedModel.remove(req.param('remove_id'));
// standard .save() works when in transaction
modelInstance.save(function (err, savedModel) {
if (err) {
transaction.rollback();
return res.serverError(err);
}
// finally commit the transaction before sending response
transaction.commit();
return res.json({
one: savedModel,
another: anotherInstance
});
});
});
});
});
}
};
route = function (req, res) {
Transaction.start(function (err, transaction) {
OneModel.transact(transaction).create(/* ... */);
OneModel.transact(transaction).update(/* ... */);
OneModel.transact(transaction).find(/* ... */);
OneModel.transact(transaction).findOrCreate(/* ... */);
OneModel.transact(transaction).findOne(/* ... */);
OneModel.transact(transaction).destroy(/* ... */);
OneModel.transact(transaction).count(/* ... */);
});
};
Other than those, update
, save
and association operations on instance methods work within transaction provided they
were either stemmed from the same transaction or wrapped (transaction.wrap(instance)
) by a transaction.
In cases where you are performing model instance opertaions such as save
, destroy
, etc on instances that has been
stemmed from a .populate
, transaction might fail. In such scenarios, performing a transaction.wrap(instance);
before
doing instance operations should fix such errors.
If you want to selectively intercept errors from this module, compare using instanceof Transaction.AdapterError
.
Note that this adapter adds an additional auto column called transactionId
. If you do not want to use transaction on
a particular model, you can turn off creation of this column by setting autoTK: false
in your model.
When one or more read replica sources are provded, the following API can be used to access data from one of the defined replication source databases. This distributes your database workloads across multiple systems.
Readonly still works without read replica using the normal non-transactional connection set.
action = function (req, res) {
OneModel.readonly().find();
OneModel.readonly().findOne();
OneModel.readonly().count();
};
Since sails-mysql
makes a SELECT
query before every update; it makes sense that the query results can be utilised to
return the changeset when a model is updated. The third parameter of .update
returns an array having objects that
contain only the fields that have changed and that too with their original values.
queryCaseSensitive
when set to true, disables the feature where waterline performs case insensitive queries. (Note
that it ises wlNext
options for waterline-sequel.)
The bundled waterline adds additional feature to do the following
Model.<function:operate>().populateSome(Object<association:criteria>);
allows you to populate multiple
associations in one call. It also accepts array of associations as argument.populate
on Models accepts select: []
as part of criteria parameter.fromObject()
which creates a model instance based on the model attributes.OneModel.fromObject(attributesObject, function (err, instance) {
if (err) { return Error; }
// instance is the required object
});
Contribution is accepted in form of Pull Requests that passes Travis CI tests. You should install this repository using
npm install -d
and run npm test
locally before sending Pull Request.