Skip to content

Commit 60f8447

Browse files
author
Manuel Ortiz
committed
support for transactions
1 parent 78b8ffb commit 60f8447

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Fork with transaction handling
2+
Do not do anything extra, work out of the box
3+
4+
15
## loopback-connector-sqlite [![Build Status](https://travis-ci.org/Synerzip/loopback-connector-sqlite.svg)](https://travis-ci.org/Synerzip/loopback-connector-sqlite)
26
[**LoopBack**](http://loopback.io/) is a highly-extensible, open-source Node.js framework that enables you to create dynamic end-to-end REST APIs with little or no coding. It also enables you to access data from major relational databases, MongoDB, SOAP and REST APIs.
37

lib/sqlite3db.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,3 +999,4 @@ if (!String.prototype.startsWith) {
999999
}
10001000

10011001
require('./migration')(SQLiteDB);
1002+
require('./transactions')(SQLiteDB);

lib/transactions.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Created by manuel.ortiz@fluxit.com.ar
3+
*/
4+
5+
var async = require('async');
6+
var sqlite3 = require("sqlite3");
7+
var TransactionDatabase = require("sqlite3-transactions").TransactionDatabase;
8+
9+
module.exports = mixinTransactions;
10+
11+
function mixinTransactions(SQLiteDB) {
12+
13+
SQLiteDB.prototype.beginTransaction = (isolation, cb) => {
14+
var db = new TransactionDatabase(new sqlite3.Database(":memory:", sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE));
15+
return db.beginTransaction(cb);
16+
}
17+
18+
SQLiteDB.prototype.rollback = (tx, cb) => tx.rollback(cb);
19+
20+
SQLiteDB.prototype.commit = (tx, cb) => tx.commit(cb);
21+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "loopback-connector-sqlite",
3-
"version": "1.4.5",
3+
"version": "1.5.0",
44
"description": "LoopBack SQLite3 Database Connector. LoopBack is an API Mgmt/MBaas platform built on top of express by StrongLoop. It supports the notion of connectors to connect to databases, restful web services, soap web services etc.",
55
"main": "index.js",
66
"scripts": {
@@ -27,7 +27,8 @@
2727
"async": "^0.9.0",
2828
"debug": "^2.1.3",
2929
"loopback-connector": "2.x",
30-
"sqlite3": "^3.1.1"
30+
"sqlite3": "^3.1.1",
31+
"sqlite3-transactions": "^0.0.5"
3132
},
3233
"devDependencies": {
3334
"chai": "^2.1.2",

0 commit comments

Comments
 (0)