Skip to main content
lathac41153227
Participating Frequently
March 23, 2018
Question

How to connect the postgresql database server using in extendscript?

  • March 23, 2018
  • 2 replies
  • 1032 views

Hi,

I need to connect the postgresql database server via extendscript javascript. So I tried with the following code. But error thrown like 'require is not a function'. So please suggests if any ideas.

var pg= require('pg');

var connection = pg.createConnection({ 

  host: '', port: '', user: 'test', 

  password : 'test', database : 'test' 

}); 

connection.connect();

var queryString = "SELECT * FROM 'ExtendScriptTest'"; 

connection.end();

Thanks,

Latha

I need to connect the postgresql database server via extendscript javascript. So I tried with the following code. But error thrown like 'require is not a function'. So please suggests if any ideas.

This topic has been closed for replies.

2 replies

Inspiring
March 23, 2018

Hi,

as Jang mentioned it's not possible by ExtendScript.

For such use cases I develop an FDK plugin, perhaps with DotNet Integration, to make data access more easy than with c++.

Bye

Markus

4everJang
Legend
March 23, 2018

Hi Markus,

I did not mention that it is impossible with ExtendScript, but it is not possible with the pg object. I made it work using a socket.

Kind regards

Inspiring
March 23, 2018

Hi Jang,

> to connect FrameMaker to an SQL database via a PHP script running on a local server.

This is not a direct connect, right?

So it's not possible query a database directly. If you want to connect with a database driver you have to go other ways.

Markus

4everJang
Legend
March 23, 2018

Hello Latha,

This is not going to work, as you are using javascript that normally runs in a browser, and ExtendScript is running in the FrameMaker environment, which is definitely not a browser. You need to connect to a server that can retrieve dara and pass it to your script. The socket object is supported in ExtendScript and allows low-level communication to a server. I have used this in the past to connect FrameMaker to an SQL database via a PHP script running on a local server.

I cannot share my code here as it took quite some time to make it work and I do need to make a living out of the programming that I do. If you cannot figure it out with the info above, you can of course contact me direct (jang at jang dot nl) to give you a quote.

Kind regards from Amsterdam

4everJang