linkam-db 1.0.5 → 1.1.1

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -1
  3. package/index.js +55 -1
  4. package/package.json +27 -27
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Link-AM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,81 @@
1
- # linkam-db
1
+ # linkam-db
2
+
3
+ A database wrapper for `knex` that simplifies database connection and querying. It includes built-in Oracle Instant Client, automatic camelCase conversion of query results, and credential management via `db.ini` configuration. Currently supports Oracle and PostgreSQL databases.
4
+
5
+ ## Features
6
+
7
+ - Pre-bundled Oracle Instant Client 12.1
8
+ - Automatic credential management via `db.ini`
9
+ - Query result camelCase conversion
10
+ - **PKG executable support** - Works in bundled Node.js executables
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install linkam-db
16
+ ```
17
+
18
+ ## PKG Compatibility (v1.0.6+)
19
+
20
+ When your application is bundled into a standalone executable using [`pkg`](https://github.com/yao-pkg/pkg), linkam-db automatically handles Oracle Client DLL extraction.
21
+
22
+ ### How It Works
23
+
24
+ 1. **Detection**: Checks for `process.pkg` environment
25
+ 2. **Extraction**: On first run, extracts Oracle Client DLLs from pkg's virtual filesystem to Windows temp directory
26
+ 3. **Caching**: DLLs remain in temp for subsequent runs (no extraction delay)
27
+ 4. **Loading**: Initializes `oracledb` with the real filesystem path (Windows requirement)
28
+
29
+ ### Why This Is Needed
30
+
31
+ Windows `LoadLibrary()` API cannot load native DLLs from memory or virtual filesystems. PKG bundles assets into a virtual filesystem that JavaScript can read, but native DLLs must exist as physical files on disk.
32
+
33
+ ### Configuration
34
+
35
+ No configuration needed! Just include linkam-db's assets in your pkg config:
36
+
37
+ ```json
38
+ {
39
+ "pkg": {
40
+ "assets": [
41
+ "node_modules/linkam-db/instantclient_12_1/**/*",
42
+ "node_modules/oracledb/build/Release/*.node",
43
+ "node_modules/linkam-db/db.ini"
44
+ ]
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### Temp Directory Location
50
+
51
+ DLLs are extracted to: `%TEMP%\linkam-db-oracle-client\instantclient_12_1`
52
+
53
+ Example: `C:\Users\username\AppData\Local\Temp\linkam-db-oracle-client\instantclient_12_1`
54
+
55
+ ## Usage
56
+
57
+ ```javascript
58
+ const db = require('linkam-db');
59
+
60
+ async function example() {
61
+ const knex = await db.init('myDatabase');
62
+
63
+ // Run raw SQL query
64
+ const results = await knex.raw('SELECT * FROM my_table WHERE id = ?', [123]);
65
+
66
+ // Results are automatically converted to camelCase
67
+ console.log(results);
68
+ }
69
+ ```
70
+
71
+ ## Database Configuration
72
+
73
+ Create a `db.ini` file in your project root (copy from `node_modules/linkam-db/db.ini` as template):
74
+
75
+ ```ini
76
+ [myDatabase]
77
+ client = oracledb
78
+ username = your_username
79
+ password = your_password
80
+ connectString = hostname:port/servicename
81
+ ```
package/index.js CHANGED
@@ -5,7 +5,61 @@ const camelcase = require(`./camelcase`)
5
5
  const authorize = require(`./authorize`)
6
6
  const log = require(`linkam-logs`)
7
7
 
8
- const libDir = path.resolve(__dirname, `instantclient_12_1`)
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
63
  oracledb.initOracleClient({ libDir: libDir })
10
64
 
11
65
 
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "linkam-db",
3
- "version": "1.0.5",
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
- "camelcase": "^6.2.0",
22
- "knex": "^2.2.0",
23
- "linkam-logs": "^1.0.1",
24
- "oracledb": "^5.4.0",
25
- "properties-reader": "^2.2.0"
26
- }
27
- }
1
+ {
2
+ "name": "linkam-db",
3
+ "version": "1.1.1",
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
+ "camelcase": "^6.2.0",
22
+ "knex": "^2.2.0",
23
+ "linkam-logs": "^1.0.1",
24
+ "oracledb": "^5.4.0",
25
+ "properties-reader": "^2.2.0"
26
+ }
27
+ }