linkam-db 1.0.0
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 +1 -0
- package/authorize.js +26 -0
- package/camelcase.js +33 -0
- package/db.ini +5 -0
- package/index.js +100 -0
- package/instantclient_12_1/BASIC_LITE_README +14 -0
- package/instantclient_12_1/adrci.exe +0 -0
- package/instantclient_12_1/adrci.sym +0 -0
- package/instantclient_12_1/genezi.exe +0 -0
- package/instantclient_12_1/genezi.sym +0 -0
- package/instantclient_12_1/oci.dll +0 -0
- package/instantclient_12_1/oci.sym +0 -0
- package/instantclient_12_1/ocijdbc12.dll +0 -0
- package/instantclient_12_1/ocijdbc12.sym +0 -0
- package/instantclient_12_1/ociw32.dll +0 -0
- package/instantclient_12_1/ociw32.sym +0 -0
- package/instantclient_12_1/ojdbc6.jar +0 -0
- package/instantclient_12_1/ojdbc7.jar +0 -0
- package/instantclient_12_1/orannzsbb12.dll +0 -0
- package/instantclient_12_1/orannzsbb12.sym +0 -0
- package/instantclient_12_1/oraocci12.dll +0 -0
- package/instantclient_12_1/oraocci12.sym +0 -0
- package/instantclient_12_1/oraocci12d.dll +0 -0
- package/instantclient_12_1/oraocci12d.sym +0 -0
- package/instantclient_12_1/oraociicus12.dll +0 -0
- package/instantclient_12_1/oraociicus12.sym +0 -0
- package/instantclient_12_1/oraons.dll +0 -0
- package/instantclient_12_1/orasql12.dll +0 -0
- package/instantclient_12_1/orasql12.sym +0 -0
- package/instantclient_12_1/uidrvci.exe +0 -0
- package/instantclient_12_1/uidrvci.sym +0 -0
- package/instantclient_12_1/vc10/oraocci12.dll +0 -0
- package/instantclient_12_1/vc10/oraocci12.sym +0 -0
- package/instantclient_12_1/vc10/oraocci12d.dll +0 -0
- package/instantclient_12_1/vc10/oraocci12d.sym +0 -0
- package/instantclient_12_1/vc11/oraocci12.dll +0 -0
- package/instantclient_12_1/vc11/oraocci12.sym +0 -0
- package/instantclient_12_1/vc11/oraocci12d.dll +0 -0
- package/instantclient_12_1/vc11/oraocci12d.sym +0 -0
- package/instantclient_12_1/vc12/oraocci12.dll +0 -0
- package/instantclient_12_1/vc12/oraocci12.sym +0 -0
- package/instantclient_12_1/vc12/oraocci12d.dll +0 -0
- package/instantclient_12_1/vc12/oraocci12d.sym +0 -0
- package/instantclient_12_1/xstreams.jar +0 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# linkam-db
|
package/authorize.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const log = require(`linkam-logs`)
|
|
2
|
+
const path = require(`path`)
|
|
3
|
+
const fs = require(`fs`)
|
|
4
|
+
const propReader = require('properties-reader')
|
|
5
|
+
const props = propReader(getPropFile()).getAllProperties()
|
|
6
|
+
|
|
7
|
+
function getCredentials(app) {
|
|
8
|
+
log.debug(`getCredentials called. app=${app}`)
|
|
9
|
+
let credentials = props
|
|
10
|
+
if (credentials) {
|
|
11
|
+
return credentials
|
|
12
|
+
} else {
|
|
13
|
+
log.warn(`nodeToolsCredentials missing for app ${app}`)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getPropFile() {
|
|
18
|
+
let criteria = path.join(__dirname, `..`, `db.ini`)
|
|
19
|
+
let personal = path.join(__dirname, `..`, `personal.db.ini`)
|
|
20
|
+
let propFile = fs.existsSync(personal) ? personal : criteria
|
|
21
|
+
return propFile
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports= {
|
|
25
|
+
getCredentials: getCredentials
|
|
26
|
+
}
|
package/camelcase.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const camelCase = require(`camelcase`)
|
|
2
|
+
|
|
3
|
+
function convert(o) {
|
|
4
|
+
let newO
|
|
5
|
+
let origKey
|
|
6
|
+
let newKey
|
|
7
|
+
let value
|
|
8
|
+
if (o instanceof Array) {
|
|
9
|
+
return o.map(function (value) {
|
|
10
|
+
if (typeof value === "object") {
|
|
11
|
+
value = convert(value)
|
|
12
|
+
}
|
|
13
|
+
return value
|
|
14
|
+
})
|
|
15
|
+
} else {
|
|
16
|
+
newO = {}
|
|
17
|
+
for (origKey in o) {
|
|
18
|
+
if (o.hasOwnProperty(origKey)) {
|
|
19
|
+
newKey = (camelCase(origKey).toString())
|
|
20
|
+
value = o[origKey]
|
|
21
|
+
if (value instanceof Array || (value !== null && value.constructor === Object)) {
|
|
22
|
+
value = convert(value)
|
|
23
|
+
}
|
|
24
|
+
newO[newKey] = value
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return newO
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
convert: convert
|
|
33
|
+
}
|
package/db.ini
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const oracledb = require(`oracledb`)
|
|
2
|
+
const path = require(`path`)
|
|
3
|
+
const fs = require(`fs`)
|
|
4
|
+
const camelcase = require(`./camelcase`)
|
|
5
|
+
const authorize = require(`./authorize`)
|
|
6
|
+
const log = require(`linkam-logs`)
|
|
7
|
+
|
|
8
|
+
const libDir = path.resolve(__dirname, `instantclient_12_1`)
|
|
9
|
+
oracledb.initOracleClient({ libDir: libDir })
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async function init(db) {
|
|
13
|
+
let credentials = authorize.getCredentials(db)
|
|
14
|
+
let connection = setConnection(credentials)
|
|
15
|
+
const knex = require(`knex`)({
|
|
16
|
+
//debug: true,
|
|
17
|
+
client: credentials.client,
|
|
18
|
+
connection: connection,
|
|
19
|
+
postProcessResponse: (result, queryContext) => {
|
|
20
|
+
let response = camelcase.convert(result)
|
|
21
|
+
//log.debug(queryContext)
|
|
22
|
+
return response
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
knex.run = async function (query) {
|
|
27
|
+
let sql = fs.readFileSync(`${path.resolve(__dirname, '..')}/${query.sql}.sql`, `utf8`)
|
|
28
|
+
log.debug(formatSqlForLogs(sql, query.params))
|
|
29
|
+
|
|
30
|
+
let results = await knex.raw(sql, query.params)
|
|
31
|
+
.then( (response) => {
|
|
32
|
+
if (this.client.config.client === `oracledb`) {
|
|
33
|
+
return response
|
|
34
|
+
} else if (this.client.config.client === `pg`) {
|
|
35
|
+
return response.rows
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.catch(function (err) {
|
|
39
|
+
log.error(err)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return results
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
knex.getRows = async function getRows(sqlFile, params) {
|
|
46
|
+
if (!params) params = {}
|
|
47
|
+
let query = {
|
|
48
|
+
sql: sqlFile,
|
|
49
|
+
params: params
|
|
50
|
+
}
|
|
51
|
+
let response = await knex.run(query)
|
|
52
|
+
if (response && response.length > 0) {
|
|
53
|
+
let arr = []
|
|
54
|
+
for (var i in response) {
|
|
55
|
+
arr.push(`${response[i][Object.keys(response[i])[0]]}`)
|
|
56
|
+
}
|
|
57
|
+
log.debug(`${response.length} rows returned. ${response[0][Object.keys(response[0])[0]]}: ${arr.toString()}`)
|
|
58
|
+
return response
|
|
59
|
+
} else {
|
|
60
|
+
log.warn(`No rows returned - file: ${query.sql}. params: ${query.params}`)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return knex
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function setConnection(credentials) {
|
|
68
|
+
let connection
|
|
69
|
+
if (credentials.client === `oracledb`) {
|
|
70
|
+
connection = {
|
|
71
|
+
user: credentials.user,
|
|
72
|
+
password: credentials.password,
|
|
73
|
+
connectString: credentials.connectString
|
|
74
|
+
}
|
|
75
|
+
} else if (credentials.client === `pg`) {
|
|
76
|
+
connection = {
|
|
77
|
+
user: credentials.user,
|
|
78
|
+
password: credentials.password,
|
|
79
|
+
host: credentials.host,
|
|
80
|
+
//port: credentials.port,
|
|
81
|
+
database: credentials.database
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return connection
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function formatSqlForLogs(sql, params) {
|
|
88
|
+
if (Object.keys(params).length > 0) {
|
|
89
|
+
for (let [key, value] of Object.entries(params)) {
|
|
90
|
+
sql = sql.replace(`:${key}`, value)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
sql = sql.replace(/(\r\n|\n|\r|\t)/gm, ` `)
|
|
94
|
+
sql = sql.replace(/\s+/g, ` `).trim()
|
|
95
|
+
return sql
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
init: init,
|
|
100
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Basic Lite Package Information
|
|
2
|
+
==============================
|
|
3
|
+
Thu Sep 11 02:53:55 CDT 2014
|
|
4
|
+
Client Shared Library 64-bit - 12.1.0.2.0
|
|
5
|
+
|
|
6
|
+
Windows NT Version V6.1 Service Pack 1
|
|
7
|
+
CPU : 2 - type 8664, 2 Physical Cores
|
|
8
|
+
Process Affinity : 0x0x0000000000000000
|
|
9
|
+
Memory (Avail/Total): Ph:10325M/11999M, Ph+PgF:22379M/23997M VM name : VMWare Version (6)
|
|
10
|
+
|
|
11
|
+
Operating in ORACLE_HOME environment.
|
|
12
|
+
Small timezone file = C:\ADE\aime_956679\oracle\oracore\zoneinfo\timezone_18.dat
|
|
13
|
+
Large timezone file = C:\ADE\aime_956679\oracle\oracore\zoneinfo\timezlrg_18.dat
|
|
14
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "linkam-db",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Link-AM/linkam-db.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Link-AM/linkam-db/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/Link-AM/linkam-db#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"knex": "^2.2.0",
|
|
22
|
+
"linkam-logs": "^1.0.1",
|
|
23
|
+
"oracledb": "^5.4.0",
|
|
24
|
+
"properties-reader": "^2.2.0"
|
|
25
|
+
}
|
|
26
|
+
}
|