Connecting to postgres database from a phonegap app?

前端 未结 3 1709
遥遥无期
遥遥无期 2021-01-19 09:11

I\'m trying to build a phonegap app for ios and android. It\'s been going well so far but now I hit a major obstacle and I need some help.

I need to connect to a rem

相关标签:
3条回答
  • 2021-01-19 09:24

    You would need to create an API for your data. Then access that API using promises from your js app.

    0 讨论(0)
  • 2021-01-19 09:35

    To let the security issues where they belong to (in existing experienced and tested parts of server / client software) and to have a minimum effort of development, I suggest to use some existing lightweight middle ware:

    • http://restsql.org/doc/Overview.html

    It comes with a docker, where any service you require is packed in, thus making it easy to try it out quickly.

    0 讨论(0)
  • 2021-01-19 09:37

    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).

    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?

    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.

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

    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).

    0 讨论(0)
提交回复
热议问题