linkam-db 1.1.1 → 1.1.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
@@ -58,8 +58,12 @@ Example: `C:\Users\username\AppData\Local\Temp\linkam-db-oracle-client\instantcl
58
58
  const db = require('linkam-db');
59
59
 
60
60
  async function example() {
61
+ // Initialize with default db.ini location
61
62
  const knex = await db.init('myDatabase');
62
63
 
64
+ // Or specify custom credentials file path
65
+ const knex2 = await db.init('myDatabase', '/path/to/custom/credentials.ini');
66
+
63
67
  // Run raw SQL query
64
68
  const results = await knex.raw('SELECT * FROM my_table WHERE id = ?', [123]);
65
69
 
@@ -79,3 +83,5 @@ username = your_username
79
83
  password = your_password
80
84
  connectString = hostname:port/servicename
81
85
  ```
86
+
87
+ By default, linkam-db looks for `personal.db.ini` first, then falls back to `db.ini` in your project root. You can also specify a custom credentials file path as the second parameter to `db.init()`.
package/authorize.js CHANGED
@@ -2,10 +2,10 @@ const log = require(`linkam-logs`)
2
2
  const path = require(`path`)
3
3
  const fs = require(`fs`)
4
4
  const propReader = require('properties-reader')
5
- const props = propReader(getPropFile()).getAllProperties()
6
5
 
7
- function getCredentials(app) {
6
+ function getCredentials(app, credentialsFile) {
8
7
  log.debug(`getCredentials called. app=${app}`)
8
+ const props = propReader(getPropFile(credentialsFile)).getAllProperties()
9
9
  let credentials = props
10
10
  if (credentials) {
11
11
  return credentials
@@ -14,7 +14,18 @@ function getCredentials(app) {
14
14
  }
15
15
  }
16
16
 
17
- function getPropFile() {
17
+ function getPropFile(credentialsFile) {
18
+ if (credentialsFile) {
19
+ // Use provided credentials file path
20
+ if (fs.existsSync(credentialsFile)) {
21
+ return credentialsFile
22
+ } else {
23
+ log.error(`Provided credentials file does not exist: ${credentialsFile}`)
24
+ throw new Error(`Credentials file not found: ${credentialsFile}`)
25
+ }
26
+ }
27
+
28
+ // Default behavior: look for personal.db.ini, then db.ini
18
29
  let criteria = path.join(__dirname, `..`, `..`, `db.ini`)
19
30
  let personal = path.join(__dirname, `..`, `..`, `personal.db.ini`)
20
31
  let propFile = fs.existsSync(personal) ? personal : criteria
package/index.js CHANGED
@@ -4,67 +4,15 @@ const fs = require(`fs`)
4
4
  const camelcase = require(`./camelcase`)
5
5
  const authorize = require(`./authorize`)
6
6
  const log = require(`linkam-logs`)
7
+ const oracleClientSetup = require(`./oracleClientSetup`)
7
8
 
8
- // Handle pkg executable - extract Oracle Client to real filesystem
9
- let libDir
10
- if (process.pkg) {
11
- // When running in pkg, extract DLLs to temp directory
12
- // Windows DLL loader can't load from pkg's virtual filesystem
13
- const os = require('os')
14
- const tempDir = path.join(os.tmpdir(), 'linkam-db-oracle-client', 'instantclient_12_1')
15
-
16
- // Extract DLLs if not already present
17
- if (!fs.existsSync(tempDir)) {
18
- log.info('Extracting Oracle Client libraries to temp directory...')
19
- fs.mkdirSync(tempDir, { recursive: true })
20
-
21
- const sourceDir = path.resolve(__dirname, 'instantclient_12_1')
22
- const files = fs.readdirSync(sourceDir)
23
-
24
- files.forEach(file => {
25
- const sourcePath = path.join(sourceDir, file)
26
- const targetPath = path.join(tempDir, file)
27
-
28
- const stats = fs.statSync(sourcePath)
29
- if (stats.isDirectory()) {
30
- // Copy directory recursively
31
- copyDirSync(sourcePath, targetPath)
32
- } else {
33
- fs.copyFileSync(sourcePath, targetPath)
34
- }
35
- })
36
- log.info(`Oracle Client extracted to: ${tempDir}`)
37
- }
38
-
39
- libDir = tempDir
40
- } else {
41
- // Normal execution - use __dirname
42
- libDir = path.resolve(__dirname, `instantclient_12_1`)
43
- }
44
-
45
- // Helper function to copy directory recursively
46
- function copyDirSync(source, target) {
47
- if (!fs.existsSync(target)) {
48
- fs.mkdirSync(target, { recursive: true })
49
- }
50
- const files = fs.readdirSync(source)
51
- files.forEach(file => {
52
- const sourcePath = path.join(source, file)
53
- const targetPath = path.join(target, file)
54
- const stats = fs.statSync(sourcePath)
55
- if (stats.isDirectory()) {
56
- copyDirSync(sourcePath, targetPath)
57
- } else {
58
- fs.copyFileSync(sourcePath, targetPath)
59
- }
60
- })
61
- }
62
-
9
+ // Initialize Oracle Client with the appropriate library directory
10
+ const libDir = oracleClientSetup.getOracleClientPath()
63
11
  oracledb.initOracleClient({ libDir: libDir })
64
12
 
65
13
 
66
- async function init(db) {
67
- let creds = authorize.getCredentials(db)
14
+ async function init(db, credentialsFile) {
15
+ let creds = authorize.getCredentials(db, credentialsFile)
68
16
  let credentials = {
69
17
  client: creds[`${db}.client`],
70
18
  user: creds[`${db}.username`],
@@ -0,0 +1,70 @@
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const log = require('linkam-logs')
4
+
5
+ /**
6
+ * Helper function to copy directory recursively
7
+ */
8
+ function copyDirSync(source, target) {
9
+ if (!fs.existsSync(target)) {
10
+ fs.mkdirSync(target, { recursive: true })
11
+ }
12
+ const files = fs.readdirSync(source)
13
+ files.forEach(file => {
14
+ const sourcePath = path.join(source, file)
15
+ const targetPath = path.join(target, file)
16
+ const stats = fs.statSync(sourcePath)
17
+ if (stats.isDirectory()) {
18
+ copyDirSync(sourcePath, targetPath)
19
+ } else {
20
+ fs.copyFileSync(sourcePath, targetPath)
21
+ }
22
+ })
23
+ }
24
+
25
+ /**
26
+ * Determines the Oracle Client library directory path.
27
+ * When running in a PKG executable, extracts DLLs to the system temp directory
28
+ * because Windows DLL loader cannot load from PKG's virtual filesystem.
29
+ *
30
+ * @returns {string} The path to the Oracle Instant Client libraries
31
+ */
32
+ function getOracleClientPath() {
33
+ if (process.pkg) {
34
+ // When running in pkg, extract DLLs to temp directory
35
+ // Windows DLL loader can't load from pkg's virtual filesystem
36
+ const os = require('os')
37
+ const tempDir = path.join(os.tmpdir(), 'linkam-db-oracle-client', 'instantclient_12_1')
38
+
39
+ // Extract DLLs if not already present
40
+ if (!fs.existsSync(tempDir)) {
41
+ log.info('Extracting Oracle Client libraries to temp directory...')
42
+ fs.mkdirSync(tempDir, { recursive: true })
43
+
44
+ const sourceDir = path.resolve(__dirname, 'instantclient_12_1')
45
+ const files = fs.readdirSync(sourceDir)
46
+
47
+ files.forEach(file => {
48
+ const sourcePath = path.join(sourceDir, file)
49
+ const targetPath = path.join(tempDir, file)
50
+
51
+ const stats = fs.statSync(sourcePath)
52
+ if (stats.isDirectory()) {
53
+ copyDirSync(sourcePath, targetPath)
54
+ } else {
55
+ fs.copyFileSync(sourcePath, targetPath)
56
+ }
57
+ })
58
+ log.info(`Oracle Client extracted to: ${tempDir}`)
59
+ }
60
+
61
+ return tempDir
62
+ } else {
63
+ // Normal execution - use __dirname
64
+ return path.resolve(__dirname, 'instantclient_12_1')
65
+ }
66
+ }
67
+
68
+ module.exports = {
69
+ getOracleClientPath
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkam-db",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {