React Native-连接到PostgreSQL数据库 [英] React Native - connect to PostgreSQL database

查看:336
本文介绍了React Native-连接到PostgreSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将React Native与外部数据库连接,例如PostgreSQL,MySQL或其他。这可能吗?

I would like to connect with React Native to an external database, like PostgreSQL, MySQL or what ever. Is this possible?

但是首先让我告诉您我的计划:
我将为多个安装(多个设备-一个设备上一个安装)开发应用程序。所有设备都与Windows安装(服务器)提供的局域网连接。在服务器上运行数据库(PostgreSQL),我想使用我的设备所有连接到该数据库。
服务器(或实际上是其数据库)应存储任务,并且每个设备都应在本地访问这些任务(读和写)。

But first let me tell you something about my plan: I will develop my application for multiple installations (multiple devices - one installation on one device). All devices are connected with a local network which is provided by a Windows installation (server). On the server runs a database (PostgreSQL) and I would like to connect to this database with all my devices. The server (or in fact its database) should store tasks and each device should access to these tasks (read and write) locally.

我还有其他一些想法,例如简单的SMB-XML文件存储(但存在冲突问题)和SMB共享文件上的SQLite数据库-但是SQLite网站告诉我们,这将避免多路访问问题。因此,我需要另一个 local 解决方案。这使我提供了可从本地网络访问的数据库。

I had also some other ideas like simple SMB-XML file storage (but the problem with collisions) and an SQLite database on an SMB shared file - but the website of SQLite tells that this will not avoid problems with multiple accesses. Therefore I need another local solution. This brought me to provide a database which is accessible from the local network.

如果有人注意到如何解决此问题,我将不胜感激。

I would be very grateful if someone has a note how to solve this problem.

谢谢!

推荐答案

为了直接访问数据库从react native开始,您将需要一个纯JavaScript数据库驱动程序。快速的Google搜索产生了PostgreSQL的JavaScript驱动程序( https://github.com/brianc/node-postgres ),但是它是为Node.js编写的,我怀疑它是否可以在JavaScript Core或Chrome中运行。 CouchDB通过REST API工作,实际上是供多个客户端直接访问的。可以使用多个JavaScript客户端。

In order to access a database directly from react native you would need a pure JavaScript database driver. A quick google search produced a JavaScript drivers for PostgreSQL (https://github.com/brianc/node-postgres) but it is written for Node.js and I doubt it will work in JavaScript Core or Chrome. CouchDB works via a REST API and it's actually intended for direct access by multiple clients. There are multiple JavaScript clients available for that.

但是为什么要让客户端直接连接到数据库?您所描述的似乎是一个非常标准的应用程序模型。您只需要在与数据库进行对话并提供API的服务器上运行一个后端即可。良好的旧网站开发。如果您想在后端编写JavaScript,建议您使用Node.js

BUT why do you want your clients to connect to the DB directly? What you describe seems like a pretty standard application model. You'll just need a backend running on your server talking to the DB and providing an API. Good old web development. If you want to write JavaScript on the backend I suggest using Node.js

如果您真的不能或不想编写后端,则可以使用多种服务提供用于数据存储甚至某些数据处理的API。但是他们当然不是本地人。例如,看看parse.com或firebase.com。

If you really can't or don't want to write a backend, there are several services that provide API for data storage and even some data processing. But of course they aren't local. Have a look at parse.com or firebase.com for example.

这篇关于React Native-连接到PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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