🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

node-jdbc-driver

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-jdbc-driver - npm Package Compare versions

Comparing version

to
1.3.1

dist/database.d.ts

28

dist/index.d.ts

@@ -1,24 +0,16 @@

import IConnectionType from "./IConnectionType";
import IConnectionConfig from "./IConnectionConfig";
import IConnectionConfig from "./IConfig";
import IDrivers from "./IDrivers";
import HiveDriver from "./hive/HiveDriver";
import PostgreSQL from "./postgresql/PostgreSQL";
import Sqlite from "./sqlite/Sqlite";
import CustomDriver from "./custom/driver";
import Drivers from './drivers';
export declare enum ConnectionType {
hive = "H",
postgreSql = "P",
sqlite = "S",
custom = "C"
hive = "hive",
postgreSql = "postgreSql",
sqlite = "sqlite",
tibero = "tibero",
custom = "custom"
}
export default class JdbcDriver<T extends ConnectionType> implements IDrivers {
protected jarPath: string;
export default class JdbcDriver<T extends ConnectionType> extends Drivers<T> implements IDrivers {
protected static connection: any;
protected driverInstance: IConnectionType;
protected type: T;
constructor(type: T, connectionConfig: IConnectionConfig<T>);
protected createDriverInstance(type: T, config: IConnectionConfig<T>): HiveDriver | PostgreSQL | Sqlite | CustomDriver;
constructor(type: T, config: IConnectionConfig<T>);
get_version: () => string;
get_columns: (tableName: string) => Promise<unknown>;
get_table_properties: (tableName: string) => Promise<unknown>;
findAll: (tableName: string) => Promise<unknown>;

@@ -29,2 +21,4 @@ count: (tableName: any) => Promise<unknown>;

connection_details: () => any;
get_columns: (tableName: string) => Promise<unknown>;
get_table_properties: (tableName: string) => Promise<unknown>;
sql: (sql: string) => Promise<unknown>;

@@ -31,0 +25,0 @@ ddl: (sql: string) => Promise<unknown>;

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -44,8 +59,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

// Import interface
var IConnectionType_1 = require("./IConnectionType");
var IDatabase_1 = require("./IDatabase");
// Import all drivers
var HiveDriver_1 = __importDefault(require("./hive/HiveDriver"));
var PostgreSQL_1 = __importDefault(require("./postgresql/PostgreSQL"));
var Sqlite_1 = __importDefault(require("./sqlite/Sqlite"));
var driver_1 = __importDefault(require("./custom/driver"));
var drivers_1 = __importDefault(require("./drivers"));
// Import dependecies

@@ -58,32 +70,15 @@ var jdbc = require('jdbc');

(function (ConnectionType) {
ConnectionType["hive"] = "H";
ConnectionType["postgreSql"] = "P";
ConnectionType["sqlite"] = "S";
ConnectionType["custom"] = "C";
ConnectionType["hive"] = "hive";
ConnectionType["postgreSql"] = "postgreSql";
ConnectionType["sqlite"] = "sqlite";
ConnectionType["tibero"] = "tibero";
ConnectionType["custom"] = "custom";
})(ConnectionType || (exports.ConnectionType = ConnectionType = {}));
var CType = {
H: HiveDriver_1.default,
P: PostgreSQL_1.default,
S: Sqlite_1.default,
C: driver_1.default
};
var JdbcDriver = /** @class */ (function () {
function JdbcDriver(type, connectionConfig) {
var _this = this;
this.jarPath = '../drivers/';
this.get_version = function () { return _this.driverInstance.get_version(); };
this.get_columns = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
var JdbcDriver = /** @class */ (function (_super) {
__extends(JdbcDriver, _super);
function JdbcDriver(type, config) {
var _this = _super.call(this, type, config) || this;
_this.get_version = function () { return _this.driver.version; };
_this.findAll = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.sql(this.driverInstance.get_query(tableName, IConnectionType_1.QueryType.columns))];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); };
this.get_table_properties = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.sql(this.driverInstance.get_query(tableName, IConnectionType_1.QueryType.describe))];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); };
this.findAll = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.sql("SELECT * FROM ".concat(tableName))];

@@ -93,3 +88,3 @@ case 1: return [2 /*return*/, _a.sent()];

}); }); };
this.count = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
_this.count = function (tableName) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {

@@ -100,3 +95,3 @@ case 0: return [4 /*yield*/, this.sql("SELECT COUNT(*) as total from ".concat(tableName))];

}); }); };
this.find = function (tableName, where) {
_this.find = function (tableName, where) {
if (where === void 0) { where = 1; }

@@ -110,5 +105,27 @@ return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {

};
this.connection_count = function () { return JdbcDriver.connection.size; };
this.connection_details = function () { return JdbcDriver.connection.entries(); };
this.sql = function (sql) { return __awaiter(_this, void 0, void 0, function () {
_this.connection_count = function () { return JdbcDriver.connection.size; };
_this.connection_details = function () { return JdbcDriver.connection.entries(); };
_this.get_columns = function (tableName) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this.type === 'custom')) return [3 /*break*/, 1];
return [2 /*return*/, 'This method is not supported for the custom drivers'];
case 1: return [4 /*yield*/, this.sql(this.get_query(tableName, IDatabase_1.QueryType.columns))];
case 2: return [2 /*return*/, _a.sent()];
}
});
}); };
_this.get_table_properties = function (tableName) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this.type === 'custom')) return [3 /*break*/, 1];
return [2 /*return*/, 'This method is not supported for the custom drivers'];
case 1: return [4 /*yield*/, this.sql(this.get_query(tableName, IDatabase_1.QueryType.describe))];
case 2: return [2 /*return*/, _a.sent()];
}
});
}); };
_this.sql = function (sql) { return __awaiter(_this, void 0, void 0, function () {
var res;

@@ -126,3 +143,3 @@ return __generator(this, function (_a) {

}); };
this.ddl = function (sql) { return __awaiter(_this, void 0, void 0, function () {
_this.ddl = function (sql) { return __awaiter(_this, void 0, void 0, function () {
var res;

@@ -140,3 +157,3 @@ return __generator(this, function (_a) {

}); };
this.close = function (connObj) { return __awaiter(_this, void 0, void 0, function () {
_this.close = function (connObj) { return __awaiter(_this, void 0, void 0, function () {
var coon;

@@ -159,3 +176,3 @@ return __generator(this, function (_a) {

}); };
this.executeQuery = function (sql) { return __awaiter(_this, void 0, void 0, function () {
_this.executeQuery = function (sql) { return __awaiter(_this, void 0, void 0, function () {
var _this = this;

@@ -206,3 +223,3 @@ return __generator(this, function (_a) {

}); };
this.executeUpdate = function (sql) { return __awaiter(_this, void 0, void 0, function () {
_this.executeUpdate = function (sql) { return __awaiter(_this, void 0, void 0, function () {
var _this = this;

@@ -242,3 +259,3 @@ return __generator(this, function (_a) {

}); };
this.createStatement = function () { return __awaiter(_this, void 0, void 0, function () {
_this.createStatement = function () { return __awaiter(_this, void 0, void 0, function () {
var _this = this;

@@ -272,3 +289,3 @@ return __generator(this, function (_a) {

}); };
this.open = function () { return __awaiter(_this, void 0, void 0, function () {
_this.open = function () { return __awaiter(_this, void 0, void 0, function () {
var _this = this;

@@ -307,6 +324,6 @@ return __generator(this, function (_a) {

}); };
this.is_init = function (conn) {
_this.is_init = function (conn) {
return conn._reserved.length;
};
this.init = function (connection) { return __awaiter(_this, void 0, void 0, function () {
_this.init = function (connection) { return __awaiter(_this, void 0, void 0, function () {
var _this = this;

@@ -330,21 +347,14 @@ return __generator(this, function (_a) {

}); };
this.type = type;
this.driverInstance = this.createDriverInstance(type, connectionConfig);
_this.type = type;
if (!jinst.isJvmCreated()) {
jinst.addOption('-Xrs');
jinst.setupClasspath([path.join(__dirname, "".concat(type === 'C' ? '' : this.jarPath).concat(this.driverInstance.driver))]);
jinst.setupClasspath([path.join(__dirname, _this.driverPath)]);
}
var connection = new jdbc(this.driverInstance.get_config());
JdbcDriver.connection.set(this.type, connection);
var connection = new jdbc(_this.get_config());
JdbcDriver.connection.set(_this.type, connection);
return _this;
}
JdbcDriver.prototype.createDriverInstance = function (type, config) {
var DriverClass = CType[type];
if (!DriverClass) {
throw new Error("Invalid type ".concat(type));
}
return new DriverClass(config);
};
JdbcDriver.connection = new Map();
return JdbcDriver;
}());
}(drivers_1.default));
exports.default = JdbcDriver;
{
"name": "node-jdbc-driver",
"version": "1.2.1",
"version": "1.3.1",
"description": "This package is help to use jdbc connection",

@@ -18,3 +18,6 @@ "main": "dist/index.js",

"hive-jdbc",
"postgre"
"postgresql",
"tibero",
"hive",
"sqlite"
],

@@ -21,0 +24,0 @@ "devDependencies": {

@@ -5,7 +5,37 @@ <div align="center">

<p>node-jdbc-driver is a JDBC API wrapper for Node.js, providing methods to manage database connections, execute queries and update statements, and retrieve database information such as table and column structures in a database-independent manner.</p>
<!-- <a href="https://packagephobia.now.sh/result?p=node-jdbc-driver"><img src="https://badgen.net/packagephobia/install/node-jdbc-driver" alt="Bundle size"></a> -->
<a href="https://img.shields.io/badge/dependencies-up--to--date-brightgreen.svg"><img src="https://img.shields.io/badge/dependencies-up--to--date-brightgreen.svg" alt="Dependencies upto date"></a>
<a href="https://img.shields.io/badge/status-stable-brightgreen.svg"><img src="https://img.shields.io/badge/status-stable-brightgreen.svg" alt="Status"></a>
<a href="https://www.npmjs.com/package/node-jdbc-driver"><img src="https://img.shields.io/npm/dw/node-jdbc-driver" alt="Downloads"></a>
<a href="https://www.npmjs.com/package/node-jdbc-driver"><img src="https://img.shields.io/npm/v/node-jdbc-driver" alt="Npm version"></a>
<a href="https://www.npmjs.com/package/node-jdbc-driver"><img src="https://img.shields.io/npm/v/node-jdbc-driver" alt="Npm version"></a><br />
<a href="mail-pcode027@gmail.com"><img src="https://img.shields.io/badge/author-pcode027@gmail.com-blue.svg" alt="Author"></a>
</div>
---
<!-- DOC -->
- [Features](#features)
- [Installation](#installation)
- [Loading and configuring the module](#loading-and-configuring-the-module)
- [Common Usage](#common-usage)
<!-- /DOC -->
## Features
- **Simplified JDBC Usage**: Provides an intuitive API to manage JDBC database connections, execute queries, and handle update statements, abstracting away low-level complexities.
- **Multiple Database Support**: Seamlessly connect to different types of databases, including Hive, PostgreSQL, Tibero, and SQLite, with a unified interface.
- **Flexible Configuration**: Easily configure database connections using either host, port, database name, username, and password or via custom JDBC connection with driver jars and connection URLs.
- **Connection Pooling**: Benefit from built-in connection pooling support to efficiently manage and reuse database connections, enhancing application performance.
- **Query Execution**: Execute custom SQL queries and retrieve results in a straightforward manner, enabling you to interact with your database effortlessly.
- **Database Structure Information**: Retrieve comprehensive information about table and column structures using simple methods, enabling you to work with your database schema efficiently.
- **Data Manipulation**: Perform essential data manipulation tasks such as counting rows, finding rows based on criteria, retrieving all rows from a table, and more.
- **Data Definition Language (DDL) Support**: Execute DDL queries to manage the structure of your database, including creating and altering tables, views, and indexes.
## Installation

@@ -17,6 +47,3 @@ To install the package, use the following command:

## Usage
Below are some minimal usage examples demonstrating how to use the `node-jdbc-driver` package.
### Initialization
### Loading and configuring the module
You can initialize the JDBC driver using either CommonJS or ES6 syntax:

@@ -30,2 +57,7 @@ ```javascript

```
## Common Usage
Below are some minimal usage examples demonstrating how to use the `node-jdbc-driver` package.
### Connection Setup

@@ -39,2 +71,3 @@ For different types of databases, you need to provide specific connection details.

ConnectionType.sqlite // for sqlite connection
ConnectionType.tibero // for tibero connection
ConnectionType.custom // Establish a JDBC connection using a custom driver

@@ -69,2 +102,5 @@ ```

const jdbc = new JdbcDriver(ConnectionType.postgreSql, { jdbcUrl, username, password });
// For tibero connection
const jdbc = new JdbcDriver(ConnectionType.tibero, { host, port, database, username, password });
```

@@ -71,0 +107,0 @@ #### SQLite Connection