Skip to content

Releases: vitaly-t/pg-promise

v.1.1.5

11 May 20:39
Compare
Choose a tag to compare
  • Code refactoring and documentation.
  • Adding console output for some impossible (broken) scenarios.

v.1.1.4

04 May 12:18
Compare
Choose a tag to compare
  • Improved parameter validation;
  • Adding new tests;
  • Code refactoring.

v.1.1.2

04 May 11:03
Compare
Choose a tag to compare
  • Improved error messages
  • Added new tests
  • Code refactoring

v.1.1.1

04 May 01:17
Compare
Choose a tag to compare

this for functions-parameters

This is an improvement on the most recent feature - Functions as Parameters.

When formatting a query with a variable-function from an object, the library will now call the function with the same object being the calling context (this), so the previous code example can be changed to the following:

var account = {
    balance: 123.45,
    expenses: 2.7,
    margin: 0.1,
    total: function () {
        var t = this.balance + this.expenses;
        return this.margin ? (t + t * this.margin / 10) : t;
    }
};

db.none("insert into activity values(${balance},${expenses},${total})", account)
    .then(function () {
        // success;
    }, function (reason) {
        // error;
    });

i.e. where we had to use account variable before, we now can use this instead, which is far more convenient, especially when using inline formatting objects that have no names.

It is important to understand that this change has no effect when using simple variable syntax of $1, $2, etc.., because in this case there is no context object that can be used.

Method as.func was extended with optional parameter obj for consistent protocol and testability, with additional tests added.

v.1.1.0

03 May 21:12
Compare
Choose a tag to compare

Functions as Parameters

This release is a major non-breaking change, adding support for parameters - functions.

Previously, passing a function as a parameter when formatting a query would have resulted in an error/reject. Now when the parser encounters a function among parameters, it will call the function to get the actual value, and then process the returned value according to its type.

Here's an example:

var account = {
    balance: 123.45,
    expenses: 2.7,
    margin: 0.1,
    total: function () {
        var t = account.balance + account.expenses;
        return account.margin ? (t + t * account.margin / 10) : t;
    }
};

db.none("insert into activity values(${balance},${expenses},${total})", account)
    .then(function () {
        // success;
    }, function (reason) {
        // error;
    });

and the same with simple parameter syntax:

db.none("insert into activity values($1,$2,$3)",
    [account.balance, account.expenses, account.total])
    .then(function () {
        // success;
    }, function (reason) {
        // failed;
    });

NOTE: If function total() in the example were to throw an error, it would have been handled and resulted in a reject.

As part of this change the library has undergone a significant refactoring towards simplification, because now when formatting queries all existing data types are supported.

The protocol has been extended with method as.func(func, raw) that's consistent with the library's usage pattern.

P.S. This feature should open many interesting variations in query formatting, making it ultimately flexible.

v.1.0.10

03 May 14:17
Compare
Choose a tag to compare
  • Event notification system has been rewritten (refactored from scratch).
  • Some error message changes;
  • Code documentation.

v.1.0.9

02 May 23:21
Compare
Choose a tag to compare
  • Adding tests;
  • Code refactoring;
  • Documentation updates;

v.1.0.8

02 May 19:37
Compare
Choose a tag to compare

Code refactoring + documentation updates.

v.1.0.7

28 Apr 18:56
Compare
Choose a tag to compare

Mostly just code refactoring and documentation updates.

Also, added method queue for transactions as an alias for method sequence.

v.1.0.6

26 Apr 22:36
Compare
Choose a tag to compare

This is a quick follow-up on the new Synchronous Transactions feature, reversing parameters passed into the factory function, so the transaction context doesn't need to be re-declared for an inline factory.

See Synchronous Transactions updated with an inline demo.

  • Tests updated for the changes;
  • Documentation updates.

Update: Renamed the feature into Synchronous Transactions