@niledatabase/server 3.0.0-alpha.24 → 3.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -605,8 +605,8 @@ function getDbHost(cfg) {
|
|
|
605
605
|
}
|
|
606
606
|
if (process.env.NILEDB_POSTGRES_URL) {
|
|
607
607
|
var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
|
|
608
|
-
logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.
|
|
609
|
-
return pgUrl.
|
|
608
|
+
logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
|
|
609
|
+
return pgUrl.hostname;
|
|
610
610
|
}
|
|
611
611
|
if (process.env.NILEDB_HOST) {
|
|
612
612
|
logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
|
|
@@ -799,7 +799,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
799
799
|
_this.databaseId = id;
|
|
800
800
|
_this.databaseName = name;
|
|
801
801
|
dburl = new URL(dbHost);
|
|
802
|
-
configuredHost = dburl.
|
|
802
|
+
configuredHost = dburl.hostname;
|
|
803
803
|
}
|
|
804
804
|
case 49:
|
|
805
805
|
_this.api = new ApiConfig({
|
|
@@ -1020,7 +1020,7 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1020
1020
|
remaining = _objectWithoutPropertiesLoose(poolConfig, _excluded$1);
|
|
1021
1021
|
config.db = poolConfig;
|
|
1022
1022
|
this.config = config;
|
|
1023
|
-
debug(JSON.stringify(this.config.db));
|
|
1023
|
+
debug("Connection pool config " + JSON.stringify(this.config.db));
|
|
1024
1024
|
this.pool = createProxyForPool(new pg.Pool(remaining), this.config);
|
|
1025
1025
|
if (typeof afterCreate === 'function') {
|
|
1026
1026
|
warn('Providing an pool configuration will stop automatic tenant context setting.');
|
|
@@ -1033,7 +1033,7 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1033
1033
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1034
1034
|
while (1) switch (_context.prev = _context.next) {
|
|
1035
1035
|
case 0:
|
|
1036
|
-
debug(
|
|
1036
|
+
debug("pool connected " + _this.id);
|
|
1037
1037
|
_this.startTimeout();
|
|
1038
1038
|
afterCreate = makeAfterCreate(config, _this.id + "-" + _this.timer);
|
|
1039
1039
|
afterCreate(client, function (err) {
|
|
@@ -1066,6 +1066,13 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1066
1066
|
});
|
|
1067
1067
|
evictPool(_this.id);
|
|
1068
1068
|
});
|
|
1069
|
+
this.pool.on('release', function (destroy) {
|
|
1070
|
+
if (destroy) {
|
|
1071
|
+
clearTimeout(_this.timer);
|
|
1072
|
+
evictPool(_this.id);
|
|
1073
|
+
debug("destroying pool " + _this.id);
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1069
1076
|
}
|
|
1070
1077
|
var _proto = NileDatabase.prototype;
|
|
1071
1078
|
_proto.startTimeout = function startTimeout() {
|
|
@@ -1120,12 +1127,6 @@ function makeAfterCreate(config, id) {
|
|
|
1120
1127
|
}
|
|
1121
1128
|
// in this example we use pg driver's connection API
|
|
1122
1129
|
conn.query(query.join(';'), function (err) {
|
|
1123
|
-
if (query.length === 1) {
|
|
1124
|
-
debug("connection context set: tenantId=" + config.tenantId);
|
|
1125
|
-
}
|
|
1126
|
-
if (query.length === 2) {
|
|
1127
|
-
debug("connection context set: tenantId=" + config.tenantId + " userId=" + config.userId);
|
|
1128
|
-
}
|
|
1129
1130
|
if (err) {
|
|
1130
1131
|
error('query connection failed', {
|
|
1131
1132
|
cause: err.cause,
|
|
@@ -1134,6 +1135,13 @@ function makeAfterCreate(config, id) {
|
|
|
1134
1135
|
name: err.name,
|
|
1135
1136
|
id: id
|
|
1136
1137
|
});
|
|
1138
|
+
} else {
|
|
1139
|
+
if (query.length === 1) {
|
|
1140
|
+
debug("connection context set: tenantId=" + config.tenantId);
|
|
1141
|
+
}
|
|
1142
|
+
if (query.length === 2) {
|
|
1143
|
+
debug("connection context set: tenantId=" + config.tenantId + " userId=" + config.userId);
|
|
1144
|
+
}
|
|
1137
1145
|
}
|
|
1138
1146
|
done(err, conn);
|
|
1139
1147
|
});
|