database 个人 github 页面上的数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31655085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Database on a personal github page
提问by Paran0a
Is it possible to have some data stored somewhere on your personal github page?
是否可以在您的个人 github 页面上的某处存储一些数据?
For example a button that triggers a counter. When you click on the button , counter increments by 1. When other user visits that page and clicks the button , counter gets incremented by 1 once again.
例如触发计数器的按钮。当您点击按钮时,计数器增加 1。当其他用户访问该页面并点击按钮时,计数器再次增加 1。
So it would be a sum of all click across all visitors that would be displayed on the page.
因此,它将是页面上显示的所有访问者的所有点击的总和。
回答by dardo
Github pages only allow for static content, so you'd have to use something like firebasein order to get a database.
Github 页面只允许静态内容,因此您必须使用firebase 之类的东西才能获取数据库。
回答by Matt L.
The accepted answer about Firebase is a good, quick reply, but I want to write a longer and more comprehensive response for anyone who is investigating this topic, as Firebase is one of several ways to achieve this kind of functionality.
关于 Firebase 的公认答案是一个很好的、快速的回复,但我想为正在研究这个主题的任何人写一篇更长、更全面的回复,因为 Firebase 是实现这种功能的几种方法之一。
By way of background, databases/datastores like mysql, postgres, redis, mongodb, etc. are the most common way to store visitor data in the way that the next visitor and see or access it. Content management systems such as Django, Wordpress, and Drupal are built to read and write to a database. These services tend to be server-side technology, which is to say that a server admin sets them up, and blocks of code that the website's users cannot see communicate with the database. That server side code base also builds the rendered html that a user will see. So in general, Github Pages are not used with these kinds of technology because they support only static html, css, and javascript--that is, they allow client side code only.
作为背景,像 mysql、postgres、redis、mongodb 等数据库/数据存储区是最常见的以下一个访问者查看或访问访问者数据的方式存储访问者数据的方式。Django、Wordpress 和 Drupal 等内容管理系统是为读取和写入数据库而构建的。这些服务往往是服务器端技术,也就是说由服务器管理员设置它们,网站用户看不到的代码块与数据库进行通信。该服务器端代码库还构建了用户将看到的呈现的 html。所以总的来说,Github Pages 不用于这些技术,因为它们只支持静态 html、css 和 javascript——也就是说,它们只允许客户端代码。
For more on this topic, see How to connect html pages to mysql database?
有关此主题的更多信息,请参阅如何将 html 页面连接到 mysql 数据库?
If you want to set up a read only datastore, you have a lot of options on Github pages. You could put a json file in your repo, query a drive document, upload an sqlite.db file to your repo and query it, etc. In this imagined example, you would have to be ok with a website user seeing any data in your datastore, as the setup would not provide a way to make some data invisible to the user.
如果您想设置只读数据存储,Github 页面上有很多选项。您可以在您的存储库中放置一个 json 文件,查询驱动器文档,将 sqlite.db 文件上传到您的存储库并进行查询等。在这个想象的示例中,您必须对网站用户看到您的任何数据感到满意数据存储,因为设置不会提供使某些数据对用户不可见的方法。
As soon as you're thinking about writing to your database, however, security is a concern. If you set up some kind of offsite database and put DB access credentials into your client-side code, any user could see those credentials and compromise your database (inject data, take it over, delete it, etc.) For this reason alone, you need a setup that passes data from the front end to the back end and vice versa without letting website traffic see under the hood. As I understand it, this is a level of functionality that Github Pages can't give you.
但是,一旦您考虑写入数据库,安全性就会成为问题。如果您设置某种异地数据库并将数据库访问凭证放入您的客户端代码中,则任何用户都可以看到这些凭证并破坏您的数据库(注入数据、接管、删除它等)仅出于这个原因,您需要一个设置,将数据从前端传递到后端,反之亦然,而不会让网站流量在幕后看到。据我了解,这是 Github Pages 无法提供的功能级别。
For more on client-side database security, see this thread: https://softwareengineering.stackexchange.com/questions/180012/is-there-any-reason-not-to-go-directly-from-client-side-javascript-to-a-database
有关客户端数据库安全性的更多信息,请参阅此线程:https: //softwareengineering.stackexchange.com/questions/180012/is-there-any-reason-not-to-go-directly-from-client-side-javascript到一个数据库
One potential workaround is to use your static side to link to a third party service. You can, for example, embed a Google form in an html page. That form can link to a Google sheet. That sheet can be published to the web and be set to update automatically. Your Github pages site can reference the public version of that page and update (on a delay) when changes are submitted. This type of setup is clunky (I assume Google sheets get slow if they get too big) and should be used with caution, as a poorly designed form of this kind could be a spam magnet. Not to mention that anyone who looks at your client side code will be able to find an view the public version of your Google sheet, which will include submission time and user data if you collect it. However, if used carefully, it could work for the use case mentioned above.
一种可能的解决方法是使用您的静态端链接到第三方服务。例如,您可以在 html 页面中嵌入 Google 表单。该表单可以链接到 Google 表格。该工作表可以发布到网络并设置为自动更新。您的 Github 页面站点可以引用该页面的公共版本并在提交更改时更新(延迟)。这种类型的设置很笨拙(我认为 Google 表格如果太大会变慢)并且应该谨慎使用,因为这种设计不当的形式可能会成为垃圾邮件磁铁。更不用说任何查看您的客户端代码的人都可以查看您的 Google 表格的公开版本,如果您收集它,其中将包括提交时间和用户数据。但是,如果谨慎使用,它可以适用于上述用例。
回答by Thirdy
Using Github's HTTP REST API: https://developer.github.com/v3/One can commit/update a json file or an sqllite file into a github pages repo via browser js.
使用 Github 的 HTTP REST API:https: //developer.github.com/v3/可以通过浏览器 js 提交/更新 json 文件或 sqllite 文件到 github pages repo。
回答by Tomer Ben David
Depending on your needs, you can try GithubDB
根据你的需要,你可以试试GithubDB
From their docs:
从他们的文档:
Ever wanted to use Github as your private database, now you can.
Why would I want to use Github as my database?
Good question. Developers have many choices of different databases, GithubDB however leverages all the features you have come to love from Github.
Logging (With Github, you can quicky look at your commits and see the write and updates for your request).
Visualization (Github offers amazing tools to visualize the incoming number of read/writes).
Persistance (With Github you can rollback to early stages of your data and see how it has evolved).
Security (Using Github, your database inherits the same standards from Github).
Availability (Github has known to be down, but let's be honest, it is good enough unless you are Facebook).
曾经想使用 Github 作为您的私人数据库,现在您可以了。
为什么我要使用 Github 作为我的数据库?
好问题。开发人员可以选择不同的数据库,但 GithubDB 充分利用了您喜欢的 Github 的所有功能。
日志记录(使用 Github,您可以快速查看您的提交并查看您的请求的写入和更新)。
可视化(Github 提供了惊人的工具来可视化传入的读/写次数)。
持久性(使用 Github,您可以回滚到数据的早期阶段并查看它是如何演变的)。
安全性(使用 Github,您的数据库继承了 Github 的相同标准)。
可用性(Github 已经知道会宕机,但老实说,除非你是 Facebook,否则它已经足够好了)。