简体   繁体   English

如何在不编写自己的 API 的情况下读取 javascript 中的 sqlite 信息?

[英]How to read in sqlite information in javascript without writing your own API?

Most of my experience with database manipulation has been through node.js, and writing simple APIs for class.我在数据库操作方面的大部分经验都是通过 node.js 以及为 class 编写简单的 API。 I'm now trying a private project, where I would write a database, and read in information from it to display on a website hosted through github.我现在正在尝试一个私人项目,我将在其中编写一个数据库,并从中读取信息以显示在通过 github 托管的网站上。 however, for what I'm doing, an API seems unnecessary, as I should be able to upload the database file onto github, and have the website read from that, rather than hosting a node.js server.但是,对于我正在做的事情,API 似乎没有必要,因为我应该能够将数据库文件上传到 github,并从中读取网站,而不是托管 Z28A3689BE95C88DD5E7A37DB516AB08 服务器。 So, what I'm asking is at a high level, how would I get information from a database into a form I can read onto a website, and would just creating a json locally, or storing the info some other way, be a better solution?所以,我要问的是高层次的,我如何从数据库中获取信息到我可以在网站上阅读的表格中,并且只是在本地创建一个 json,或者以其他方式存储信息,会更好解决方案?

If the database is very large, then this really should be done server side.如果数据库非常大,那么这确实应该在服务器端完成。

If the database is small, one option is to convert the sqlLite database to JSON, and then just use fetch to grab, and just parse using Javascript.如果数据库很小,一种选择是将sqlLite数据库转换为JSON,然后直接使用fetch抓取,使用Javascript解析即可。

But another option I think you might like, is use a sqLite client compiled for the browser.但我认为您可能喜欢的另一个选项是使用为浏览器编译的 sqLite 客户端。 If your browser is relatively new and supports webAssembly you might find this interesting.如果您的浏览器相对较新并且支持 webAssembly,您可能会觉得这很有趣。

https://github.com/sql-js/sql.js https://github.com/sql-js/sql.js

Basically sqLite compiled for the browser..基本上是为浏览器编译的 sqLite ..

One issue with any of these is security, anybody could of course download the JSON or Sqlite database in full and have full access.其中任何一个问题都是安全性,任何人当然都可以完整下载 JSON 或 Sqlite 数据库并拥有完全访问权限。 Server side you can implement user authentication etc.服务器端可以实现用户认证等。

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

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