简体   繁体   English

连接到/从没有node.js的javascript查询rethinkdb

[英]Connect to / query rethinkdb from javascript without node.js

I'm trying to create a simple in-browser web app to display the contents on a given rethink table with some nice formatting. 我正在尝试创建一个简单的浏览器内Web应用程序,以使用一些不错的格式在给定的重新思考表上显示内容。 I'm having trouble finding a way to actually connect to rethink without having to use node.js. 我无法找到一种无需使用node.js即可真正进行重新思考的方法。 All I want to do is get the data out and then run it through some styling/layout stuff. 我要做的就是取出数据,然后通过一些样式/布局来运行它。 Node + dependencies are overkill for a tiny browser-only app. 对于只有浏览器的微型应用程序,Node +依赖关系是过大的。

Unfortunately, you're going to need a server. 不幸的是,您将需要一台服务器。 It might be node.js or it might be another language, but you'll need a server. 可能是node.js,也可能是另一种语言,但是您需要一台服务器。

RethinkDB is not Firebase. RethinkDB不是Firebase。 It can't be queried from your browser. 无法从浏览器中查询。 If you absolutely need browser side querying and can't have a server, you should use Firbase. 如果您绝对需要浏览器端查询并且没有服务器,则应使用Firbase。

If you want to use RethinkDB, you can just have a very thin server that just redirects your queries to RethinkDB. 如果您想使用RethinkDB,您可以拥有一个非常瘦的服务器,该服务器仅将您的查询重定向到RethinkDB。 This can be done over HTTP or over WebSockets. 这可以通过HTTP或WebSockets完成。

Why 为什么

Ultimately, the reason why you don't want to query your database from the browser is security. 最终,您不想从浏览器查询数据库的原因是安全性。 RethinkDB has no users or read only accounts. RethinkDB没有用户或只读帐户。 That means that if your database is accessible from your browsers, anyone can come and delete all your databases (including your system tables) with a simple query. 这意味着,如果可以通过浏览器访问数据库,那么任何人都可以通过简单的查询来删除所有数据库(包括系统表)。

For example: 例如:

r.db('rethinkdb').tableList().forEach(function (tableName) {
  return r.db('rethinkdb').tableDrop(tableName);
});

And now, all your database is gone :). 现在,您所有的数据库都不见了:)。

Keep in mind that this is something the RethinkDB team is aware of and working on. 请记住,这 RethinkDB团队意识到并正在努力的事情。

https://github.com/rethinkdb/rethinkdb/issues/218 https://github.com/rethinkdb/rethinkdb/issues/218

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM