<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.zcubes.com/index.php?action=history&amp;feed=atom&amp;title=ZAP_connection_with_DB</id>
	<title>ZAP connection with DB - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.zcubes.com/index.php?action=history&amp;feed=atom&amp;title=ZAP_connection_with_DB"/>
	<link rel="alternate" type="text/html" href="http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;action=history"/>
	<updated>2026-04-28T11:50:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217774&amp;oldid=prev</id>
		<title>Virajp at 20:31, 12 June 2025</title>
		<link rel="alternate" type="text/html" href="http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217774&amp;oldid=prev"/>
		<updated>2025-06-12T20:31:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:31, 12 June 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l424&quot; &gt;Line 424:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 424:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         calci.display();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         calci.display();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;        console.log('=== CALCI Operations using Global SUM ===');&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Virajp</name></author>
	</entry>
	<entry>
		<id>http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217773&amp;oldid=prev</id>
		<title>Virajp at 20:29, 12 June 2025</title>
		<link rel="alternate" type="text/html" href="http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217773&amp;oldid=prev"/>
		<updated>2025-06-12T20:29:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;//wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;amp;diff=217773&amp;amp;oldid=217772&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Virajp</name></author>
	</entry>
	<entry>
		<id>http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217772&amp;oldid=prev</id>
		<title>Virajp at 19:19, 12 June 2025</title>
		<link rel="alternate" type="text/html" href="http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217772&amp;oldid=prev"/>
		<updated>2025-06-12T19:19:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:19, 12 June 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l575&quot; &gt;Line 575:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 575:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ZCubes&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Z3&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[ZAP &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;(ZCubes Advanced Platform)&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[ZAP]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[[PostgreSQL]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;https://www.postgresql.org/&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;* [ZCubes Documentation]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ZCubes]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ZCubes]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Virajp</name></author>
	</entry>
	<entry>
		<id>http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217759&amp;oldid=prev</id>
		<title>Virajp: Created page with &quot;= ZAP Integration with Database =  '''ZAP (ZCubes Advanced Platform)''' is a desktop application within the ZCubes ecosystem, providing a powerful suite for computation, progr...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.zcubes.com/index.php?title=ZAP_connection_with_DB&amp;diff=217759&amp;oldid=prev"/>
		<updated>2025-06-12T00:26:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= ZAP Integration with Database =  &amp;#039;&amp;#039;&amp;#039;ZAP (ZCubes Advanced Platform)&amp;#039;&amp;#039;&amp;#039; is a desktop application within the ZCubes ecosystem, providing a powerful suite for computation, progr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= ZAP Integration with Database =&lt;br /&gt;
&lt;br /&gt;
'''ZAP (ZCubes Advanced Platform)''' is a desktop application within the ZCubes ecosystem, providing a powerful suite for computation, programming, content creation, and more. Integrating database connectivity with ZAP allows users to manage, analyze, and visualize data directly from the ZAP desktop environment, leveraging ZCubes' omni-functional capabilities.&lt;br /&gt;
&lt;br /&gt;
This guide provides a step-by-step approach to connecting ZAP Desktop with a database (such as PostgreSQL) on ZCubes, inspired by the integration style of other advanced computational tools.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
ZAP Desktop, as part of ZCubes, supports extensibility through scripting (JavaScript, z^3, and more) and integration with external systems. By enabling database connections, users can automate data workflows, perform analytics, and connect ZAP’s content creation tools with live data sources.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* '''ZAP Desktop''' installed from the ZCubes platform.&lt;br /&gt;
* '''Database server''' (e.g., PostgreSQL, MySQL) installed and running.&lt;br /&gt;
* '''Node.js''' installed for scripting and integration.&lt;br /&gt;
* '''Database client libraries''' (e.g., &amp;lt;code&amp;gt;pg&amp;lt;/code&amp;gt; for PostgreSQL).&lt;br /&gt;
&lt;br /&gt;
== Installation Steps ==&lt;br /&gt;
&lt;br /&gt;
=== 1. Install ZAP Desktop ===&lt;br /&gt;
* Download ZAP Desktop from the [https://downloads.zcubes.com/ ZCubes platform].&lt;br /&gt;
* Follow the installation instructions for your operating system.&lt;br /&gt;
* Launch ZAP Desktop and ensure it is running.&lt;br /&gt;
&lt;br /&gt;
=== 2. Set Up Your Database ===&lt;br /&gt;
* Install your preferred database (e.g., PostgreSQL).&lt;br /&gt;
* Create a database (e.g., &amp;lt;code&amp;gt;ZAPTesting&amp;lt;/code&amp;gt;) and user credentials.&lt;br /&gt;
* Note the host, port, username, and password for use in your scripts.&lt;br /&gt;
&lt;br /&gt;
=== 3. Install Node.js and Database Client in a Specific Directory ===&lt;br /&gt;
* Download and install Node.js from [https://nodejs.org nodejs.org].&lt;br /&gt;
* Choose or create a directory for your ZAP project, for example: &amp;lt;code&amp;gt;D:/ZAP_Testing&amp;lt;/code&amp;gt;&lt;br /&gt;
* Open a terminal or command prompt and run:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
npm install pg --prefix D:/ZAP_Testing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* This will install the &amp;lt;code&amp;gt;pg&amp;lt;/code&amp;gt; library and its dependencies into &amp;lt;code&amp;gt;D:/ZAP_Testing/node_modules&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* (Optional) If you want to manage dependencies with a &amp;lt;code&amp;gt;package.json&amp;lt;/code&amp;gt;, run:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd D:/ZAP_Testing&lt;br /&gt;
npm init&lt;br /&gt;
npm install pg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In your ZAP Desktop code block (before requiring the npm package), add:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;z^3&amp;quot;&amp;gt;&lt;br /&gt;
AddToModuleSearchPath(&amp;quot;D:/ZAP_Testing/node_modules&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:29.png|thumb]]&lt;br /&gt;
* This tells ZAP where to look for your installed npm modules.  &lt;br /&gt;
*Example screenshot of usage:*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 4. Configure Database Connection Script ===&lt;br /&gt;
Below is a sample JavaScript (Node.js) script for connecting ZAP Desktop to a PostgreSQL database. This script can be run inside ZAP’s scripting interface or as an external process, with output routed to ZCubes windows using &amp;lt;code&amp;gt;ZAppend&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
const windowId = &amp;quot;7Space&amp;quot;; &lt;br /&gt;
&lt;br /&gt;
const originalConsoleLog = console.log;&lt;br /&gt;
console.log = function(...args) {&lt;br /&gt;
    const message = args.map(arg =&amp;gt; &lt;br /&gt;
        typeof arg === 'object' ? JSON.stringify(arg) : String(arg)&lt;br /&gt;
    ).join(' ');&lt;br /&gt;
    originalConsoleLog.apply(console, args);&lt;br /&gt;
    &lt;br /&gt;
    if (typeof ZAppend === 'function') {&lt;br /&gt;
        ZAppend(windowId, message);&lt;br /&gt;
    } else {&lt;br /&gt;
        originalConsoleLog('ZAppend not available in current context');&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
const fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
const pg = require(&amp;quot;pg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const config = {&lt;br /&gt;
    user: &amp;quot;postgres&amp;quot;,&lt;br /&gt;
    password: &amp;quot;root&amp;quot;, &lt;br /&gt;
    host: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
    port: &amp;quot;5432&amp;quot;,&lt;br /&gt;
    database: &amp;quot;ZAPTesting&amp;quot;,&lt;br /&gt;
    ssl: false,&lt;br /&gt;
    connectionTimeoutMillis: 5000,&lt;br /&gt;
    query_timeout: 10000&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
const testConnection = async () =&amp;gt; {&lt;br /&gt;
    const client = new pg.Client(config);&lt;br /&gt;
    &lt;br /&gt;
    try {&lt;br /&gt;
        console.log(&amp;quot;Testing PostgreSQL connection...&amp;quot;);&lt;br /&gt;
        await client.connect();&lt;br /&gt;
        console.log('Connection successful to ZAPTesting database');&lt;br /&gt;
        &lt;br /&gt;
        // Additional test query for verification&lt;br /&gt;
        const res = await client.query('SELECT $1::text as message', ['ZAP-ZCubes connection working']);&lt;br /&gt;
        console.log('Test query result:', res.rows[0].message);&lt;br /&gt;
        &lt;br /&gt;
    } catch (err) {&lt;br /&gt;
        console.error('Connection failed:', err.message);&lt;br /&gt;
        &lt;br /&gt;
    } finally {&lt;br /&gt;
        await client.end();&lt;br /&gt;
        console.log('Connection closed');&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
if (typeof ZAppend === 'function') {&lt;br /&gt;
    ZAppend(windowId, &amp;quot;Starting PostgreSQL connection test...&amp;quot;);&lt;br /&gt;
    testConnection();&lt;br /&gt;
} else {&lt;br /&gt;
    console.log(&amp;quot;Running in non-ZCube environment&amp;quot;);&lt;br /&gt;
    testConnection();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Testing PostgreSQL connection...&lt;br /&gt;
&lt;br /&gt;
Connection successful to ZAPTesting database&lt;br /&gt;
&lt;br /&gt;
Connection closed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5. Using Database Features in ZAP Desktop ===&lt;br /&gt;
* Open a new script or code cell in ZAP.&lt;br /&gt;
* Select the appropriate language (JavaScript, z^3, etc.).&lt;br /&gt;
* Use your database connection to run queries, insert or retrieve data, and visualize results directly in ZAP windows using &amp;lt;code&amp;gt;ZAppend&amp;lt;/code&amp;gt; or similar functions.&lt;br /&gt;
&lt;br /&gt;
===Example for creating the database:===&lt;br /&gt;
[[File:24.png|thumb]]&lt;br /&gt;
[[File:25.png|thumb]]&lt;br /&gt;
[[File:26.png|thumb]]&lt;br /&gt;
[[File:27.png|thumb]]&lt;br /&gt;
[[File:28.png|thumb]]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// --- ZAppend Console Log Redirect ---&lt;br /&gt;
const windowId = &amp;quot;10Space&amp;quot;; // Current ZCube window ID from debug log&lt;br /&gt;
&lt;br /&gt;
// Save original console.log and override to use ZAppend&lt;br /&gt;
const originalConsoleLog = console.log;&lt;br /&gt;
console.log = function(...args) {&lt;br /&gt;
    const message = args.map(arg =&amp;gt; &lt;br /&gt;
        typeof arg === 'object' ? JSON.stringify(arg) : String(arg)&lt;br /&gt;
    ).join(' ');&lt;br /&gt;
    originalConsoleLog.apply(console, args);&lt;br /&gt;
    &lt;br /&gt;
    if (typeof ZAppend === 'function') {&lt;br /&gt;
        ZAppend(windowId, message);&lt;br /&gt;
    } else {&lt;br /&gt;
        originalConsoleLog('ZAppend not available in current context');&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// --- Random Data Generation Code ---&lt;br /&gt;
const fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
const pg = require(&amp;quot;pg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const config = {&lt;br /&gt;
    user: &amp;quot;postgres&amp;quot;,&lt;br /&gt;
    password: &amp;quot;root&amp;quot;, &lt;br /&gt;
    host: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
    port: &amp;quot;5432&amp;quot;,&lt;br /&gt;
    database: &amp;quot;ZAPTesting&amp;quot;,&lt;br /&gt;
    ssl: false,&lt;br /&gt;
    connectionTimeoutMillis: 5000,&lt;br /&gt;
    query_timeout: 10000&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
async function generateRandomData() {&lt;br /&gt;
    const client = new pg.Client(config);&lt;br /&gt;
    &lt;br /&gt;
    try {&lt;br /&gt;
        await client.connect();&lt;br /&gt;
        console.log('Connected to ZAPTesting database');&lt;br /&gt;
        &lt;br /&gt;
        // Create random numbers table&lt;br /&gt;
        const createTableQuery = `&lt;br /&gt;
            CREATE TABLE IF NOT EXISTS random_numbers_data (&lt;br /&gt;
                id SERIAL PRIMARY KEY,&lt;br /&gt;
                value_a NUMERIC(10,2),&lt;br /&gt;
                value_b NUMERIC(10,2),&lt;br /&gt;
                value_c NUMERIC(10,2),&lt;br /&gt;
                value_d NUMERIC(10,2),&lt;br /&gt;
                value_e NUMERIC(10,2),&lt;br /&gt;
                is_positive BOOLEAN,&lt;br /&gt;
                category VARCHAR(20),&lt;br /&gt;
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br /&gt;
            )&lt;br /&gt;
        `;&lt;br /&gt;
        &lt;br /&gt;
        await client.query(createTableQuery);&lt;br /&gt;
        console.log('Random numbers table created successfully');&lt;br /&gt;
        &lt;br /&gt;
        // Clear existing data&lt;br /&gt;
        await client.query('DELETE FROM random_numbers_data');&lt;br /&gt;
        &lt;br /&gt;
        // Generate random data using PostgreSQL functions&lt;br /&gt;
        const insertRandomDataQuery = `&lt;br /&gt;
            INSERT INTO random_numbers_data (value_a, value_b, value_c, value_d, value_e, is_positive, category)&lt;br /&gt;
            SELECT &lt;br /&gt;
                ROUND((random() * 1000)::numeric, 2) as value_a,&lt;br /&gt;
                ROUND((random() * 500 - 250)::numeric, 2) as value_b,&lt;br /&gt;
                ROUND((random() * 100)::numeric, 2) as value_c,&lt;br /&gt;
                ROUND((random() * 50)::numeric, 2) as value_d,&lt;br /&gt;
                ROUND((random() * 200)::numeric, 2) as value_e,&lt;br /&gt;
                (random() &amp;gt; 0.5) as is_positive,&lt;br /&gt;
                CASE &lt;br /&gt;
                    WHEN random() &amp;lt; 0.33 THEN 'Category A'&lt;br /&gt;
                    WHEN random() &amp;lt; 0.66 THEN 'Category B'&lt;br /&gt;
                    ELSE 'Category C'&lt;br /&gt;
                END as category&lt;br /&gt;
            FROM generate_series(1, 20)&lt;br /&gt;
        `;&lt;br /&gt;
        &lt;br /&gt;
        await client.query(insertRandomDataQuery);&lt;br /&gt;
        console.log('Random data inserted successfully');&lt;br /&gt;
        &lt;br /&gt;
        // Display the generated data&lt;br /&gt;
        const selectQuery = 'SELECT * FROM random_numbers_data ORDER BY id';&lt;br /&gt;
        const result = await client.query(selectQuery);&lt;br /&gt;
        &lt;br /&gt;
        console.log('\n=== Generated Random Data ===');&lt;br /&gt;
        result.rows.forEach(row =&amp;gt; {&lt;br /&gt;
            console.log(`ID: ${row.id}, A: ${row.value_a}, B: ${row.value_b}, C: ${row.value_c}, D: ${row.value_d}, E: ${row.value_e}, Positive: ${row.is_positive}, Category: ${row.category}`);&lt;br /&gt;
        });&lt;br /&gt;
        &lt;br /&gt;
        console.log(`\nTotal records generated: ${result.rows.length}`);&lt;br /&gt;
        &lt;br /&gt;
    } catch (err) {&lt;br /&gt;
        console.error('Database operation failed:', err.message);&lt;br /&gt;
        &lt;br /&gt;
    } finally {&lt;br /&gt;
        await client.end();&lt;br /&gt;
        console.log('Database connection closed');&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Execute with ZCube environment check&lt;br /&gt;
if (typeof ZAppend === 'function') {&lt;br /&gt;
    ZAppend(windowId, &amp;quot;Starting random data generation...&amp;quot;);&lt;br /&gt;
    generateRandomData();&lt;br /&gt;
} else {&lt;br /&gt;
    console.log(&amp;quot;Running in non-ZCube environment&amp;quot;);&lt;br /&gt;
    generateRandomData();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example for performing operations on the table data===&lt;br /&gt;
[[File:21.png|thumb]]&lt;br /&gt;
[[File:22.png|thumb]]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// --- ZAppend Console Log Redirect ---&lt;br /&gt;
const windowId = &amp;quot;8Space&amp;quot;; // &amp;lt;-- Set your ZCube window ID here&lt;br /&gt;
&lt;br /&gt;
// Save the original console.log&lt;br /&gt;
const originalConsoleLog = console.log;&lt;br /&gt;
&lt;br /&gt;
// Override console.log to also append to the ZCube window&lt;br /&gt;
console.log = function(...args) {&lt;br /&gt;
    const message = args.map(arg =&amp;gt;&lt;br /&gt;
        typeof arg === 'object' ? JSON.stringify(arg) : String(arg)&lt;br /&gt;
    ).join(' ');&lt;br /&gt;
    originalConsoleLog.apply(console, args);&lt;br /&gt;
    if (typeof ZAppend === &amp;quot;function&amp;quot;) {&lt;br /&gt;
        ZAppend(windowId, message);&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// --- Your CALCI SUM code starts here ---&lt;br /&gt;
const fs = require(&amp;quot;fs&amp;quot;);&lt;br /&gt;
const pg = require(&amp;quot;pg&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
const config = {&lt;br /&gt;
    user: &amp;quot;postgres&amp;quot;,&lt;br /&gt;
    password: &amp;quot;root&amp;quot;, &lt;br /&gt;
    host: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
    port: &amp;quot;5432&amp;quot;,&lt;br /&gt;
    database: &amp;quot;ZAPTesting&amp;quot;,&lt;br /&gt;
    ssl: false,&lt;br /&gt;
    connectionTimeoutMillis: 5000,&lt;br /&gt;
    query_timeout: 10000&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// Enhanced Array prototype with CALCI SUM functionality&lt;br /&gt;
Array.prototype.calci = function() {&lt;br /&gt;
    const data = this;&lt;br /&gt;
    &lt;br /&gt;
    return {&lt;br /&gt;
        table: data,&lt;br /&gt;
        &lt;br /&gt;
        // CALCI SUM function implementation&lt;br /&gt;
        SUM: function(...args) {&lt;br /&gt;
            let total = 0;&lt;br /&gt;
            &lt;br /&gt;
            for (let arg of args) {&lt;br /&gt;
                if (typeof arg === 'string' &amp;amp;&amp;amp; arg.includes(':')) {&lt;br /&gt;
                    // Handle range like A1:A3&lt;br /&gt;
                    const rangeValues = this.parseRange(arg);&lt;br /&gt;
                    total += this.sumArray(rangeValues);&lt;br /&gt;
                } else if (typeof arg === 'string') {&lt;br /&gt;
                    // Handle single cell like A1&lt;br /&gt;
                    const cellValue = this.parseRange(arg);&lt;br /&gt;
                    total += this.convertToNumber(cellValue);&lt;br /&gt;
                } else if (Array.isArray(arg)) {&lt;br /&gt;
                    // Handle array input&lt;br /&gt;
                    total += this.sumArray(arg);&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Handle direct number&lt;br /&gt;
                    total += this.convertToNumber(arg);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            return total;&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Helper function to sum array values&lt;br /&gt;
        sumArray: function(arr) {&lt;br /&gt;
            let sum = 0;&lt;br /&gt;
            if (Array.isArray(arr[0])) {&lt;br /&gt;
                // 2D array (range result)&lt;br /&gt;
                for (let row of arr) {&lt;br /&gt;
                    for (let cell of row) {&lt;br /&gt;
                        sum += this.convertToNumber(cell);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            } else {&lt;br /&gt;
                // 1D array&lt;br /&gt;
                for (let cell of arr) {&lt;br /&gt;
                    sum += this.convertToNumber(cell);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            return sum;&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Convert value to number following CALCI rules&lt;br /&gt;
        convertToNumber: function(value) {&lt;br /&gt;
            if (value === null || value === undefined || value === '') {&lt;br /&gt;
                return 0; // Empty cells ignored&lt;br /&gt;
            }&lt;br /&gt;
            if (value === true) return 1; // TRUE counts as 1&lt;br /&gt;
            if (value === false) return 0; // FALSE counts as 0&lt;br /&gt;
            if (typeof value === 'string') {&lt;br /&gt;
                const num = parseFloat(value);&lt;br /&gt;
                return isNaN(num) ? 0 : num; // Text ignored (returns 0)&lt;br /&gt;
            }&lt;br /&gt;
            return typeof value === 'number' ? value : 0;&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Parse range notation (A1:B3) and return data&lt;br /&gt;
        parseRange: function(range) {&lt;br /&gt;
            if (range.includes(':')) {&lt;br /&gt;
                const [start, end] = range.split(':');&lt;br /&gt;
                const startCoords = this.cellToCoords(start);&lt;br /&gt;
                const endCoords = this.cellToCoords(end);&lt;br /&gt;
                &lt;br /&gt;
                const result = [];&lt;br /&gt;
                for (let row = startCoords.row; row &amp;lt;= endCoords.row; row++) {&lt;br /&gt;
                    const rowData = [];&lt;br /&gt;
                    for (let col = startCoords.col; col &amp;lt;= endCoords.col; col++) {&lt;br /&gt;
                        if (data[row] &amp;amp;&amp;amp; data[row][col] !== undefined) {&lt;br /&gt;
                            rowData.push(data[row][col]);&lt;br /&gt;
                        } else {&lt;br /&gt;
                            rowData.push(null);&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
                    result.push(rowData);&lt;br /&gt;
                }&lt;br /&gt;
                return result;&lt;br /&gt;
            } else {&lt;br /&gt;
                const coords = this.cellToCoords(range);&lt;br /&gt;
                return data[coords.row] ? data[coords.row][coords.col] : null;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Convert cell notation (A1) to coordinates&lt;br /&gt;
        cellToCoords: function(cell) {&lt;br /&gt;
            const match = cell.match(/([A-Z]+)(\d+)/);&lt;br /&gt;
            if (!match) {&lt;br /&gt;
                throw new Error('Invalid cell reference: ' + cell);&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            const col = this.columnToNumber(match[1]) - 1;&lt;br /&gt;
            const row = parseInt(match[2]) - 1;&lt;br /&gt;
            &lt;br /&gt;
            return { row, col };&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Convert column letters to numbers (A=1, B=2, etc.)&lt;br /&gt;
        columnToNumber: function(column) {&lt;br /&gt;
            let result = 0;&lt;br /&gt;
            for (let i = 0; i &amp;lt; column.length; i++) {&lt;br /&gt;
                result = result * 26 + (column.charCodeAt(i) - 'A'.charCodeAt(0) + 1);&lt;br /&gt;
            }&lt;br /&gt;
            return result;&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        // Display table&lt;br /&gt;
        display: function() {&lt;br /&gt;
            console.log('\n--- CALCI Spreadsheet ---');&lt;br /&gt;
            data.forEach((row, index) =&amp;gt; {&lt;br /&gt;
                console.log(`Row ${index + 1}:`, row);&lt;br /&gt;
            });&lt;br /&gt;
            console.log('-------------------------\n');&lt;br /&gt;
        }&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// Main function to create CALCI operations table&lt;br /&gt;
const createCalciOperationsTable = async () =&amp;gt; {&lt;br /&gt;
    const client = new pg.Client(config);&lt;br /&gt;
    &lt;br /&gt;
    try {&lt;br /&gt;
        await client.connect();&lt;br /&gt;
        console.log('Connected to ZAPTesting database');&lt;br /&gt;
        &lt;br /&gt;
        // Create CALCI operations table&lt;br /&gt;
        const createTableQuery = `&lt;br /&gt;
            CREATE TABLE IF NOT EXISTS calci_operations (&lt;br /&gt;
                id SERIAL PRIMARY KEY,&lt;br /&gt;
                operation_name VARCHAR(50) NOT NULL,&lt;br /&gt;
                formula TEXT NOT NULL,&lt;br /&gt;
                input_data JSONB,&lt;br /&gt;
                result NUMERIC,&lt;br /&gt;
                cell_range VARCHAR(50),&lt;br /&gt;
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br /&gt;
            )&lt;br /&gt;
        `;&lt;br /&gt;
        &lt;br /&gt;
        await client.query(createTableQuery);&lt;br /&gt;
        console.log('CALCI operations table created successfully');&lt;br /&gt;
        &lt;br /&gt;
        // Insert sample CALCI data for SUM operations&lt;br /&gt;
        const sampleData = [&lt;br /&gt;
            {&lt;br /&gt;
                operation: 'SUM_NUMBERS',&lt;br /&gt;
                formula: 'SUM(1,2,3)',&lt;br /&gt;
                data: [1, 2, 3],&lt;br /&gt;
                range: 'A1:A3'&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                operation: 'SUM_MIXED',&lt;br /&gt;
                formula: 'SUM(5,-9,45)',&lt;br /&gt;
                data: [5, -9, 45],&lt;br /&gt;
                range: 'B1:B3'&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                operation: 'SUM_WITH_BOOLEAN',&lt;br /&gt;
                formula: 'SUM(10,TRUE,FALSE,20)',&lt;br /&gt;
                data: [10, true, false, 20],&lt;br /&gt;
                range: 'C1:C4'&lt;br /&gt;
            },&lt;br /&gt;
            {&lt;br /&gt;
                operation: 'SUM_WITH_TEXT',&lt;br /&gt;
                formula: 'SUM(15,&amp;quot;text&amp;quot;,25,30)',&lt;br /&gt;
                data: [15, &amp;quot;text&amp;quot;, 25, 30],&lt;br /&gt;
                range: 'D1:D4'&lt;br /&gt;
            }&lt;br /&gt;
        ];&lt;br /&gt;
        &lt;br /&gt;
        // Create spreadsheet data and perform CALCI operations&lt;br /&gt;
        const spreadsheetData = [&lt;br /&gt;
            ['Value1', 'Value2', 'Value3', 'Value4'],&lt;br /&gt;
            [1, 5, 10, 15],&lt;br /&gt;
            [2, -9, true, &amp;quot;text&amp;quot;],&lt;br /&gt;
            [3, 45, false, 25],&lt;br /&gt;
            [null, null, 20, 30]&lt;br /&gt;
        ];&lt;br /&gt;
        &lt;br /&gt;
        const calci = spreadsheetData.calci();&lt;br /&gt;
        calci.display();&lt;br /&gt;
        &lt;br /&gt;
        console.log('=== CALCI SUM Operations ===');&lt;br /&gt;
        &lt;br /&gt;
        for (let sample of sampleData) {&lt;br /&gt;
            // Perform CALCI SUM operation&lt;br /&gt;
            let result;&lt;br /&gt;
            if (sample.operation === 'SUM_NUMBERS') {&lt;br /&gt;
                result = calci.SUM(1, 2, 3);&lt;br /&gt;
            } else if (sample.operation === 'SUM_MIXED') {&lt;br /&gt;
                result = calci.SUM(5, -9, 45);&lt;br /&gt;
            } else if (sample.operation === 'SUM_WITH_BOOLEAN') {&lt;br /&gt;
                result = calci.SUM(10, true, false, 20);&lt;br /&gt;
            } else if (sample.operation === 'SUM_WITH_TEXT') {&lt;br /&gt;
                result = calci.SUM(15, &amp;quot;text&amp;quot;, 25, 30);&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            console.log(`${sample.formula} = ${result}`);&lt;br /&gt;
            &lt;br /&gt;
            // Insert operation result into database&lt;br /&gt;
            const insertQuery = `&lt;br /&gt;
                INSERT INTO calci_operations (operation_name, formula, input_data, result, cell_range)&lt;br /&gt;
                VALUES ($1, $2, $3, $4, $5)&lt;br /&gt;
            `;&lt;br /&gt;
            &lt;br /&gt;
            await client.query(insertQuery, [&lt;br /&gt;
                sample.operation,&lt;br /&gt;
                sample.formula,&lt;br /&gt;
                JSON.stringify(sample.data),&lt;br /&gt;
                result,&lt;br /&gt;
                sample.range&lt;br /&gt;
            ]);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Demonstrate range-based SUM operations&lt;br /&gt;
        console.log('\n=== Range-based SUM Operations ===');&lt;br /&gt;
        &lt;br /&gt;
        // SUM(A2:A4) - Sum first column numbers&lt;br /&gt;
        const sumA2A4 = calci.SUM('A2:A4');&lt;br /&gt;
        console.log('SUM(A2:A4) =', sumA2A4);&lt;br /&gt;
        &lt;br /&gt;
        // SUM(B2:B4) - Sum second column (including negative)&lt;br /&gt;
        const sumB2B4 = calci.SUM('B2:B4');&lt;br /&gt;
        console.log('SUM(B2:B4) =', sumB2B4);&lt;br /&gt;
        &lt;br /&gt;
        // SUM(C2:C4) - Sum with boolean values&lt;br /&gt;
        const sumC2C4 = calci.SUM('C2:C4');&lt;br /&gt;
        console.log('SUM(C2:C4) =', sumC2C4);&lt;br /&gt;
        &lt;br /&gt;
        // Insert range operations&lt;br /&gt;
        const rangeOperations = [&lt;br /&gt;
            { name: 'SUM_RANGE_A2A4', formula: 'SUM(A2:A4)', result: sumA2A4, range: 'A2:A4' },&lt;br /&gt;
            { name: 'SUM_RANGE_B2B4', formula: 'SUM(B2:B4)', result: sumB2B4, range: 'B2:B4' },&lt;br /&gt;
            { name: 'SUM_RANGE_C2C4', formula: 'SUM(C2:C4)', result: sumC2C4, range: 'C2:C4' }&lt;br /&gt;
        ];&lt;br /&gt;
        &lt;br /&gt;
        for (let op of rangeOperations) {&lt;br /&gt;
            await client.query(&lt;br /&gt;
                'INSERT INTO calci_operations (operation_name, formula, result, cell_range) VALUES ($1, $2, $3, $4)',&lt;br /&gt;
                [op.name, op.formula, op.result, op.range]&lt;br /&gt;
            );&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Query and display all operations&lt;br /&gt;
        const allOperations = await client.query('SELECT * FROM calci_operations ORDER BY id');&lt;br /&gt;
        &lt;br /&gt;
        console.log('\n=== Stored CALCI Operations ===');&lt;br /&gt;
        allOperations.rows.forEach(row =&amp;gt; {&lt;br /&gt;
            console.log(`ID: ${row.id}, Operation: ${row.operation_name}, Formula: ${row.formula}, Result: ${row.result}`);&lt;br /&gt;
        });&lt;br /&gt;
        &lt;br /&gt;
        console.log('\nCALCI SUM operations completed successfully!');&lt;br /&gt;
        &lt;br /&gt;
    } catch (err) {&lt;br /&gt;
        console.error('Database operation failed:', err.message);&lt;br /&gt;
        throw err;&lt;br /&gt;
        &lt;br /&gt;
    } finally {&lt;br /&gt;
        await client.end();&lt;br /&gt;
        console.log('Database connection closed');&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// Execute the CALCI operations&lt;br /&gt;
createCalciOperationsTable()&lt;br /&gt;
    .then(() =&amp;gt; {&lt;br /&gt;
        console.log('CALCI SUM implementation completed');&lt;br /&gt;
    })&lt;br /&gt;
    .catch(err =&amp;gt; {&lt;br /&gt;
        console.error('Error:', err.message);&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Output Saved in the Table==&lt;br /&gt;
[[File:30.png|center|600px|Output Saved in the Table]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* '''Connection errors:''' Double-check your credentials and network settings.&lt;br /&gt;
* '''Missing client libraries:''' Ensure &amp;lt;code&amp;gt;pg&amp;lt;/code&amp;gt; or your chosen client is installed in the correct directory.&lt;br /&gt;
* '''Output not visible:''' Verify your ZCubes window ID and that &amp;lt;code&amp;gt;ZAppend&amp;lt;/code&amp;gt; is available in your environment.&lt;br /&gt;
* '''Permissions:''' Ensure your database user has the necessary privileges.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[ZCubes]]&lt;br /&gt;
* [[ZAP (ZCubes Advanced Platform)]]&lt;br /&gt;
* [[PostgreSQL]]&lt;br /&gt;
* [ZCubes Documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:ZCubes]]&lt;br /&gt;
[[Category:ZAP]]&lt;br /&gt;
[[Category:Database Integration]]&lt;br /&gt;
[[Category:System integration]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''Note: ZAP in ZCubes is a desktop application and not a database itself. This guide is for integrating ZAP Desktop with external databases for enhanced data-driven workflows.''&lt;/div&gt;</summary>
		<author><name>Virajp</name></author>
	</entry>
</feed>