Skip to content

Releases: vitaly-t/pg-promise

v.1.4.2

04 Jun 15:57
Compare
Choose a tag to compare

This is just a maintenance update:

  • Code refactoring
  • Adding new tests;
  • Improving error messages.

v.1.4.1

02 Jun 17:43
Compare
Choose a tag to compare

The following conversion helpers have been extended to accept the value passed in as a function that needs to be called in order to resolve the actual value:

  • as.bool
  • as.number
  • as.text
  • as.date
  • as.json
  • as.array
  • as.csv

Example:

var s = pgp.as.csv(function () {
    return [1, 'two', false];
});
console.log(s);
// prints: 1,'two',false

When the function-parameter returns a function again, it will be called repeatedly, till a non-function value is returned.

Tests have been modified and new ones added to account for the new feature.

1.4.0

31 May 14:49
Compare
Choose a tag to compare

Callback Context

Added this context to 3 cases where it is applicable, with reference to the protocol object:

  1. Transaction callback;
  2. Event extend
  3. Sequence factory

Where previously you had to rely on the object - parameter that provided access to the protocol, this can be used instead from now on.

NOTE: In order to keep compatibility with the existing code, the protocol object is still passed into those callbacks as before, so no changes required.

There is however a slight chance that it may break someone's code, if this was used within any of those callbacks, with reference to an outside object, which would be an exceptional case, and not a good example of code writing. This is the reason the version has been upped to 1.4, to emphasize that there is a small chance of breaking the existing code.

Transaction callback

Old syntax:
db.tx(function (t) {
    return t.query("select * from users");
})
    .then(function (data) {
        console.log(data); // print result;
    }, function (err) {
        console.log(err); // print error;
    });
New syntax:
db.tx(function () {
    return this.query("select * from users");
})
    .then(function (data) {
        console.log(data); // print result;
    }, function (err) {
        console.log(err); // print error;
    });

NOTE: Parameter t is still passed, for compatibility.

Event extend

Old syntax:
var options = {
    extend: function (obj) {
        obj.addImage = function (data) {
            return obj.one("insert into images(data) values($1) returning id",
                '\\x' + data);
        }
    }
};
New syntax:
var options = {
    extend: function () {
        this.addImage = function (data) {
            // note: the caller may switch 'this' context;
            // and it won't work for repository objects;
            return this.one("insert into images(data) values($1) returning id",
                '\\x' + data);
        }
    }
};

NOTE: Parameter obj is still passed, for compatibility.

Event extend received this context for consistency, but it is not as useful there as in other cases, because when setting up repositories of objects, the context changes (this changes to the repository instance), so you are likely to end up using the old syntax.

Sequence factory

Old syntax
db.tx(function (t) {
    return t.sequence(function (idx) {
        switch (idx) {
            case 0:
                return t.query("select 0");
            case 1:
                return t.query("select 1");
            case 2:
                return t.query("select 2");
        }
    });
})
    .then(function (data) {
        console.log(data); // print result;
    }, function (reason) {
        console.log(reason); // print error;
    });
New syntax
db.tx(function () {
    return this.sequence(function (idx) {
        switch (idx) {
            case 0:
                return this.query("select 0");
            case 1:
                return this.query("select 1");
            case 2:
                return this.query("select 2");
        }
    });
})
    .then(function (data) {
        console.log(data); // print result;
    }, function (reason) {
        console.log(reason); // print error;
    });

NOTE: The old syntax remains to be valid, for compatibility.

Other changes

  • Code refactoring
  • Test updates
  • Documentation updates

v.1.3.3

30 May 13:15
Compare
Choose a tag to compare

Minor code + tests refactoring.

Added property pgp.version, for easier integration with other libraries:

var pgp = require("pg-promise")(/*options*/);
console.log(pgp.version);
// prints: { major: 1, minor: 3, patch: 3 }

v.1.3.2

24 May 20:38
Compare
Choose a tag to compare

Added comprehensive tests for the recently modified Named Parameters feature, which in turn revealed one small bug in the variable detection, allowing invalid syntax $/varName}, which is now fixed, hence the update.

v.1.3.1

24 May 16:38
Compare
Choose a tag to compare

Flexible Named Parameters

Support for Named Parameters has been changed to a more generic one.

Historically, only ${propName} was supported, and then extended with $(propName) for compatibility with ES6 template strings.

From now on Named Parameters are defined using syntax $*propName*, where * is any of the following open-close pairs: {}, (), [], <>, //, so you can use one to your liking, and just to remember that {} won't work within ES6 template strings.

As before, combinations of different open-close symbols are not allowed. Raw-text variables aren't affected by this change, it is still the same $*propName^*.

v.1.3.0

23 May 17:53
Compare
Choose a tag to compare

Error Handling

This release is a major re-work on the error handling mechanism within the library, with focus on errors related to failed database connections, to make sure they are rejected and reported just the same as the rest of the errors.

Any connection-related error is now reported within the error event, and always rejected correctly.

There has been an overall change in the way errors are reported through events and as rejections. All errors and on all levels are now reported with the original Error object, and not just its text message as it was before, giving you access to the calling stack, among other useful attributes of the object.

Despite the huge scope of changes, none should break the existing code, they only provide more detail and better error handling.

Other Changes

  • Method tx has received alias transact;
  • Method queryRaw has received alias raw;
  • Lots of new tests written for connection and error handling;
  • Improved code samples;

Other than that, some major code refactoring was done, with improvements ranging from promises reuse (to avoid anti-pattern), to protocol instantiation.

Notes

The only kicking issue that remains around connections is one within node-postgres: Unhandled errors during connection.

It is because of this long ongoing bug this library has 3 tests commented out, unfortunately.

Basically, node-postgres throws an unhandled error in the following cases:

  • Invalid user name in the connection;
  • Invalid password in the connection;
  • Invalid connection string passed.

I'm just waiting for the node-postgres author to fix it, same as everybody else.

v.1.2.3

19 May 18:55
Compare
Choose a tag to compare
  • Revised error handling during event notifications;
  • Regular expression search optimizations;

NOTE: v.1.2.2 came out broken and was deleted.

v.1.2.1

17 May 17:01
Compare
Choose a tag to compare
  • code refactoring and documentation;
  • adding examples to the library;
  • improving tests.

v.1.2.0

16 May 14:08
Compare
Choose a tag to compare

Named Parameters extended

Named Parameters feature has been extended to include syntax $(propName), as an addition to the original ${propName} syntax.

It was done to be able to avoid conflicts when formatting queries with ES6 template strings, and in response to issue #24

Learn by Example tutorial has been updated.