Skip to content

Commit

Permalink
Merge pull request #58 from cyjake/release-v1.2.0
Browse files Browse the repository at this point in the history
release: v1.2.0
  • Loading branch information
JimmyDaddy authored Dec 10, 2020
2 parents b1e2a0b + 44d51ff commit f7e47bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
8 changes: 8 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.2.0 / 2020-12-10
==================

* Feat: `Realm.prototype.transaction()` with async function support
* Feat: `Realm.prototype.query()` for raw queries
* Feat: `logger.logQuery(sql, duration, { Model, command })`
* Feat: `logger.logQueryError(sql, err, duration, { Model, command })`

1.1.0 / 2020-11-23
==================

Expand Down
2 changes: 1 addition & 1 deletion lib/bone.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ class Bone {
connection.release();
}
} else if (callback.constructor.name === 'GeneratorFunction') {
const gen = callback();
const gen = callback({ connection });
let result;

try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leoric",
"version": "1.1.0",
"version": "1.2.0",
"description": "JavaScript Object-relational mapping alchemy",
"main": "index.js",
"types": "index.d.ts",
Expand Down
38 changes: 8 additions & 30 deletions test/unit/test.realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,10 @@ describe('=> Realm', () => {
// clean all prev data in users
await realm.query('TRUNCATE TABLE users');
assert.rejects(async () => {
await realm.transaction(function *() {
yield realm.query(`INSERT INTO
users (gmt_create, email, nickname)
VALUES (?, ?, ?)`, [
new Date(),
email,
'Thor',
]);
yield realm.query(`INSERT INTO
users (gmt_create, email, nickname)
VALUES (?, ?, ?)`,[
new Date(),
email,
'Loki',
]);
await realm.transaction(function *({ connection }) {
const sql = 'INSERT INTO users (gmt_create, email, nickname) VALUES (?, ?, ?)';
yield realm.query(sql, [ new Date(), email, 'Thor' ], { connection });
yield realm.query(sql, [ new Date(), email, 'Loki' ], { connection });
}, `Error: ER_DUP_ENTRY: Duplicate entry '${email}' for key 'users.email'`); // rollback
});
const { rows } = await realm.query(`SELECT * FROM users WHERE email = '${email}'`);
Expand All @@ -139,21 +128,10 @@ describe('=> Realm', () => {
// clean all prev data in users
await realm.query('TRUNCATE TABLE users');
assert.rejects(async () => {
await realm.transaction(async () => {
await realm.query(`INSERT INTO
users (gmt_create, email, nickname)
VALUES (?, ?, ?)`, [
new Date(),
email,
'Thor',
]);
await realm.query(`INSERT INTO
users (gmt_create, email, nickname)
VALUES (?, ?, ?)`,[
new Date(),
email,
'Loki',
]);
await realm.transaction(async ({ connection }) => {
const sql = 'INSERT INTO users (gmt_create, email, nickname) VALUES (?, ?, ?)';
await realm.query(sql, [ new Date(), email, 'Thor' ], { connection });
await realm.query(sql, [ new Date(), email, 'Loki' ], { connection });
}, `Error: ER_DUP_ENTRY: Duplicate entry '${email}' for key 'users.email'`); // rollback
});
const { rows } = await realm.query(`SELECT * FROM users WHERE email = '${email}'`);
Expand Down

0 comments on commit f7e47bd

Please sign in to comment.