Skip to main content
lathac41153227
Participating Frequently
Mar 23, 2018 9:37 AM UTC
Question

How to connect the postgresql database server using in extendscript?

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

Inspiring
Mar 23, 2018 10:25 AM UTC

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

Translate
4everJang
Legend
Mar 23, 2018 10:46 AM UTC

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

Translate
Inspiring
Mar 23, 2018 11:56 AM UTC

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

Translate
4everJang
Legend
Mar 23, 2018 9:59 AM UTC

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

Translate