orange-orm 4.4.1 → 4.4.2

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.
package/README.md CHANGED
@@ -359,6 +359,11 @@ npm install pg
359
359
  import map from './map';
360
360
  const db = map.postgres('postgres://postgres:postgres@postgres/postgres');
361
361
  ```
362
+ With schema
363
+ ```javascript
364
+ import map from './map';
365
+ const db = map.postgres('postgres://postgres:postgres@postgres/postgres?search_path=custom');
366
+ ```
362
367
  __Oracle__
363
368
  ```bash
364
369
  npm install oracledb
package/docs/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Changelog
2
+ __4.4.2__
3
+ Support for schema in connection string. Postgrs only. [#116](https://github.com/alfateam/orange-orm/issues/118)
2
4
  __4.4.1__
3
5
  Support for date-only ISO strings. [#116](https://github.com/alfateam/orange-orm/issues/116)
4
6
  __4.4.0__
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "main": "./src/index.js",
5
5
  "browser": "./src/client/index.mjs",
6
6
  "bin": {
@@ -1,14 +1,18 @@
1
1
  /* eslint-disable no-prototype-builtins */
2
2
  //slightly modified code from github.com/brianc/node-postgres
3
+ var log = require('../../table/log');
3
4
  var EventEmitter = require('events').EventEmitter;
4
5
 
5
6
  var defaults = require('./defaults');
6
7
  var genericPool = require('../../generic-pool');
7
8
  var _pg = require('pg');
9
+ var parseSearchPathParam = require('./parseSearchPathParam');
8
10
 
9
11
  function newPgPool(connectionString, poolOptions) {
10
12
  poolOptions = poolOptions || {};
11
13
  let pg = poolOptions.native ? _pg.native : _pg;
14
+
15
+ // @ts-ignore
12
16
  var pool = genericPool.Pool({
13
17
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
14
18
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
@@ -41,7 +45,8 @@ function newPgPool(connectionString, poolOptions) {
41
45
  }
42
46
  });
43
47
  client.poolCount = 0;
44
- return cb(null, client);
48
+ negotiateSearchPath(client, connectionString, (err) => cb(err, client));
49
+
45
50
  });
46
51
  },
47
52
  destroy: function(client) {
@@ -65,7 +70,8 @@ function newPgPool(connectionString, poolOptions) {
65
70
  cb = domain.bind(cb);
66
71
  }
67
72
  if (err) return cb(err, null, function() {
68
- /*NOOP*/ });
73
+ /*NOOP*/
74
+ });
69
75
  client.poolCount++;
70
76
  cb(null, client, function(err) {
71
77
  if (err) {
@@ -79,4 +85,17 @@ function newPgPool(connectionString, poolOptions) {
79
85
  return pool;
80
86
  }
81
87
 
88
+ function negotiateSearchPath(client, connectionString, cb) {
89
+ const searchPath = parseSearchPathParam(connectionString);
90
+ if (searchPath) {
91
+ const sql = `set search_path to ${searchPath}`;
92
+ log.emitQuery({sql, parameters: []});
93
+ return client.query(sql, cb);
94
+ }
95
+ else
96
+ cb();
97
+
98
+
99
+ }
100
+
82
101
  module.exports = newPgPool;
@@ -0,0 +1,10 @@
1
+ function parseSearchPathParam(connectionString = '') {
2
+ const [, queryString] = connectionString.split('?');
3
+ if (!queryString)
4
+ return;
5
+ const params = new URLSearchParams(queryString);
6
+ const searchPath = params.get('search_path');
7
+ return searchPath;
8
+ }
9
+
10
+ module.exports = parseSearchPathParam;