[英]How can I write to my lowdb-Database from the frontend, using next.js?
I am a hobby programmer with some experience in React, primarily using Firebase for my backend.我是一名有一定 React 经验的业余程序员,主要使用 Firebase 作为我的后端。 Recently, I have started using Next.js and am wondering if I can use it as a small JSON-based database for local applications on my Raspberry Pi.
最近,我开始使用 Next.js,想知道是否可以将它用作我的 Raspberry Pi 上本地应用程序的基于 JSON 的小型数据库。 I have set up LowDB and can access it from server-side rendered components, but I am unsure of the best way to make them accessible from interactive frontend components, such as allowing user input and saving it to the database.
我已经设置了 LowDB 并且可以从服务器端呈现的组件访问它,但我不确定让它们从交互式前端组件访问的最佳方法,例如允许用户输入并将其保存到数据库。 I have considered using Next.js's own API endpoint, but I am unsure if this is the most efficient and desired method.
我考虑过使用 Next.js 自己的 API 端点,但我不确定这是否是最有效和最理想的方法。 It feels strange to use a DB query in server-side components but an API for data changes.
在服务器端组件中使用 DB 查询感觉很奇怪,但是 API 用于数据更改。
NextJs as great framework derived from React, its more for UI frontend, for interacting with DB normally you would use an NodeJS API framework like NestJs or simply Express with some kickstart templates. NextJs 作为源自 React 的优秀框架,它更多地用于 UI 前端,为了与数据库交互,通常你会使用像 NestJs 这样的 NodeJS API 框架,或者简单地使用一些 kickstart 模板的 Express。 You will not like use SSC since its just not the way/goal it was designed.
您不会喜欢使用 SSC,因为它不是设计的方式/目标。 like dentist doctor doing eye check haha
就像牙医做眼科检查哈哈
Happy coding!编码愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.