UNPKG

teradatasql

Version:
81 lines 3.15 kB
"use strict"; // Copyright 2025 by Teradata Corporation. All rights reserved. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); // This sample program demonstrates how to use connectAsync and closeAsync // for non-blocking connection operations. // @ts-ignore const teradatasql = __importStar(require("teradatasql")); async function main() { const con = new teradatasql.TeradataConnection(); try { console.log("Connecting asynchronously to the database..."); await con.connectAsync({ host: "whomooz", user: "guest", password: "please" }); console.log("Connected successfully!"); const cur = con.cursor(); try { // Execute a simple query to verify the connection works cur.execute("select current_timestamp"); const row = cur.fetchone(); if (row) { console.log(`Current timestamp: ${row[0]}`); } // Demonstrate a query execution cur.execute("select 'Hello from Teradata!' as greeting"); const result = cur.fetchone(); if (result) { console.log(`Query result: ${result[0]}`); } } finally { cur.close(); } console.log("Closing connection asynchronously..."); await con.closeAsync(); console.log("Connection closed successfully!"); } catch (error) { console.error(`Error: ${error.message}`); // Ensure connection is closed even if an error occurs try { if (con) { await con.closeAsync(); } } catch (closeError) { console.error(`Error closing connection: ${closeError.message}`); } } } // end main // Run the async main function main() .then(() => { console.log("Sample completed successfully"); }) .catch((error) => { console.error(`Unexpected error: ${error.message}`); process.exit(1); }); //# sourceMappingURL=AsyncConnectClose.js.map