This project provides a Node.js module to connect to a Timbr instance (using its Hive interface) via JDBC. It wraps the node-jdbc-driver package to offer a simplified, Promise-based interface for connecting and executing queries.
Install the package using npm:
npm install timbr-node-jdbc- Node.js (v16 or higher recommended for async/await) installed on your machine.
- Java Development Kit (JDK) installed and
JAVA_HOMEenvironment variable set correctly (required bytimbr-node-jdbc).
timbr-node-jdbc
├── jars
│ └── hive-jdbc-4.0.1-standalone.jar # Default location for the JDBC driver JAR
├── index.js # The connector module logic
├── package.json # NPM configuration file
└── README.md # This documentation
└── test.js # Test file for Timbr connector, should be modified before running
-
Clone or Download: Get the code for this module.
# If it's a git repo: git clone <repository-url> cd timbr-node-jdbc
-
Install Dependencies: Run the following command in the
timbr-node-jdbcdirectory:npm install
This installs the
timbr-node-jdbcpackage and its dependencies. -
Verify Java Setup: Ensure your JDK is installed and the
JAVA_HOMEenvironment variable points to the JDK installation directory.timbr-node-jdbcneeds this to interact with the Java Bridge.
After installing, import the module and create a connector instance by providing connection options. Use async/await or Promise chains to handle the asynchronous operations.
const createTimbrConnector = require('timbr-node-jdbc');
// --- Required Options ---
const options = {
ontology: '<your_ontology_name>', // Replace with your Timbr ontology name
password: '<your_timbr_user_token>', // Replace with your Timbr token/password
host: '<your_timbr-server_host>', // Replace with your Timbr Plattform hostname
// --- Optional Options (with defaults) ---
// userName: 'token', // Default: 'token'
// isSSL: true, // Default: true
// port: 443, // Default: 443 if isSSL=true, 80 otherwise
// driverPath: require('path').resolve(__dirname, '../jars/hive-jdbc-4.0.1-standalone.jar'), // Default path (absolute)
// driverName: 'org.apache.hive.jdbc.HiveDriver' // Default driver class
};
// Create the connector instance
const timbrConnector = createTimbrConnector(options);
// --- Example using async/await ---
async function runQuery() {
try {
// --- Connect to the database ---
console.log('Attempting to connect...');
await timbrConnector.connect();
console.log('Successfully connected!');
// --- Execute a query ---
const sqlQuery = 'SHOW CONCEPTS'; // Example query
console.log(`Executing query: ${sqlQuery}`);
const results = await timbrConnector.executeQuery(sqlQuery);
console.log(`Query results for "${sqlQuery}":`);
console.log(results); // results is an array of objects
} catch (error) {
console.error('An error occurred during operation:', error);
} finally {
// --- Close the connection when done ---
console.log('Attempting to close connection...');
try {
await timbrConnector.close();
console.log('Connection closed successfully.');
} catch (closeErr) {
console.error('Failed to close connection:', closeErr);
}
}
}
// Run the example function
runQuery();createTimbrConnector(options): (Factory Function) Creates and returns a new connector instance.options(Object): Configuration object.ontology(String, required): The name of the Timbr ontology.password(String, required): The user's password or token.host(String, required): The hostname of the Timbr server.userName(String, optional): The username. Defaults to'token'.isSSL(Boolean, optional): Whether to use SSL. Defaults totrue.port(Number | String, optional): The port number. Defaults to443ifisSSLis true,80otherwise.driverPath(String, optional): The absolute file path to the JDBC driver JAR. Defaults to an absolute path pointing to'./jars/hive-jdbc-4.0.1-standalone.jar'relative toindex.js.driverName(String, optional): The Java class name of the JDBC driver. Defaults to'org.apache.hive.jdbc.HiveDriver'.
connector.connect(): Opens a connection to the database.- Returns:
Promise<void>- Resolves on success, rejects on error.
- Returns:
connector.executeQuery(query): Executes a SQL query against the connected database.query(String): The SQL query string.- Returns:
Promise<Array>- Resolves with an array of row objects on success, rejects on error.
connector.close(): Closes the database connection.- Returns:
Promise<void>- Resolves on success, rejects on error.
- Returns:
