开发者

PostgreSQL sockets from JavaScript (HTML5)

I'm looking at options to connect directly--without a web server or middleware--to a PostgreSQL server using JavaScript from a web browser client. On github, I found three projects:

  1. node_postgres
  2. node-postgres
  3. postgres-js

They all appear to be in early but at least somewhat active development.

Do they all do roughly the same thing? I开发者_开发知识库s what they do even what I'm looking for? Does anyone have experience with any of them that could recommend one over the others?


node-postgres was inspired by postgres-js and does roughly the same thing.

However, they both seem to be their own sort of middleware, because they require node.js, which is a server-side JavaScript implementation of a web server. So they would cut out a layer, but still not be the same thing as connecting directly to the PostgreSQL server.

There might be a way to combine the code in them with some HTML5 socket examples, though, to make connections directly from a web browser client.


If you are interested in CLIENT side JavaScript, as the OP's question implied, but you don't insist on owning the server, there is a commercial service that can help you.

The Rdbhost service makes PostgreSQL servers accessible from client-side JavaScript. There is a security system to prevent unauthorized queries, using a server-side white-list and an automated white-list populating system.

It uses plain old AJAX style http requests, provides a jQuery extension to facilitate the querying.

See https://www.rdbhost.com .


There is no secure solution today. One of possible solutions would be htsql: http://htsql.org/

However there you use web addresses to query, even with https your queries will be plain text!

You should/could use a small webserver to handle requests. Alternativelly you can write an app, or use a local postgres server to handle the connection (in this case you still will need some kind of webserver).

The problem is very simple: your webbrowsers are limited in protocols to talk to the web, and postgres is not on this list. In fact you should not try to overcome this issue, using a server-client architecture is a very good solution. Format your request with JS to make it as small as possible, and let your web-server scripts interpret it into functional sql requests. The answer can be parsed into shorter response, then a sql data transfer, and you just need to interpret it on your side. Since you will create interperers on all sides, you will achieve a higher abstraction then in case of direct db connection, and thus independency towards the backend engines you use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜