source: node_modules/pg/lib/index.js@ 6c7cfa6

main
Last change on this file since 6c7cfa6 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[62b2964]1'use strict'
2
3const Client = require('./client')
4const defaults = require('./defaults')
5const Connection = require('./connection')
6const Result = require('./result')
7const utils = require('./utils')
8const Pool = require('pg-pool')
9const TypeOverrides = require('./type-overrides')
10const { DatabaseError } = require('pg-protocol')
11const { escapeIdentifier, escapeLiteral } = require('./utils')
12
13const poolFactory = (Client) => {
14 return class BoundPool extends Pool {
15 constructor(options) {
16 super(options, Client)
17 }
18 }
19}
20
21const PG = function (clientConstructor) {
22 this.defaults = defaults
23 this.Client = clientConstructor
24 this.Query = this.Client.Query
25 this.Pool = poolFactory(this.Client)
26 this._pools = []
27 this.Connection = Connection
28 this.types = require('pg-types')
29 this.DatabaseError = DatabaseError
30 this.TypeOverrides = TypeOverrides
31 this.escapeIdentifier = escapeIdentifier
32 this.escapeLiteral = escapeLiteral
33 this.Result = Result
34 this.utils = utils
35}
36
37let clientConstructor = Client
38
39let forceNative = false
40try {
41 forceNative = !!process.env.NODE_PG_FORCE_NATIVE
42} catch {
43 // ignore, e.g., Deno without --allow-env
44}
45
46if (forceNative) {
47 clientConstructor = require('./native')
48}
49
50module.exports = new PG(clientConstructor)
51
52// lazy require native module...the native module may not have installed
53Object.defineProperty(module.exports, 'native', {
54 configurable: true,
55 enumerable: false,
56 get() {
57 let native = null
58 try {
59 native = new PG(require('./native'))
60 } catch (err) {
61 if (err.code !== 'MODULE_NOT_FOUND') {
62 throw err
63 }
64 }
65
66 // overwrite module.exports.native so that getter is never called again
67 Object.defineProperty(module.exports, 'native', {
68 value: native,
69 })
70
71 return native
72 },
73})
Note: See TracBrowser for help on using the repository browser.