从phonegap应用程序连接到postgres数据库? [英] Connecting to postgres database from a phonegap app?

查看:141
本文介绍了从phonegap应用程序连接到postgres数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学生;我已经在我学校的计算机科学系获得了付费研究职位。

I am a student; I have been granted a paid research position with my school's computer science department.

研究实际上只是软件开发 - 我正在为ios建立一个phonegap应用程序和android。它已经进行得很好,但现在我打的主要障碍和应用程序的最重要的部分,我需要一些帮助。

The "research" is really just software development-- I'm building a phonegap app for ios and android. It's been going well so far but now I hit the major obstacle and the most important part of the app, and I need some help.

我需要连接到远程Postgres数据库。这是远远超出我以前做过的任何事情,在网络连接方面。

I need to connect to a remote Postgres database. This is something far beyond anything I've done before, in terms of making a network connection.

有没有任何经验/提示,或知道任何资源包含相关信息?

Does anyone have any experience/tips for this, or know of any resources which contain relevant information?

推荐答案

从客户端javascript,你不能。除非phonegap已经做了一些奇怪的权限或提供了一个PostgreSQL接口(这大概是你知道如果他们有)。

From client-side javascript, you can't. Unless phonegap has done something very odd with permissions or provided a PostgreSQL interface (which presumably you'd know about if they had).

你会想做什么提供一个小的服务器端包装器到PostgreSQL,它将接收请求,将它们转换为查询并返回(大概)json格式的结果。哦 - 你需要考虑安全性 - 谁可以连接,他们能做什么,是否需要加密?

What you'll want to do is provide a small server-side wrapper to PostgreSQL that will take requests, convert them to queries and return (presumably) json-formatted results. Oh - and you'll need to think about security too - who can connect, what can they do, does it all need to be encrypted?

如果你的要求很简单,这可以很容易做到在Perl / Python / Ruby等甚至javascript如果你有node.js手。使用Perl你可以在一个Dancer应用程序中打包DBIx :: Class,类似的模块存在于所有上述脚本语言中。

If your requirements are simple, this can be easy enough to do in Perl/Python/Ruby etc. or even javascript if you have node.js to hand. With Perl you'd wrap DBIx::Class in a Dancer app - similar modules exist for all the above scripting languages.

请考虑是否要运行整个事情

Do consider whether you want to run the whole thing over https (let apache handle this for you) - it will avoid issues with passwords/private data being sniffed over wireless connections.

例如,你的应用程序会发出一个ajax请求: http:// myserver / projects / 123 / messages?limit = 20& sort = date

For example, your app would issue an ajax request to: http://myserver/projects/123/messages?limit=20&sort=date

这将被转换成一个查询到项目消息表中,按日期排序的最后20条消息,并将结果作为一个JSON对象数组(可能)。

That would be translated into a query into the project-messages table for the last 20 messages sorted by date and wrap the results up as an array of JSON objects (presumably).

这篇关于从phonegap应用程序连接到postgres数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆