在本地存储 url 的最佳方式

发布于 2024-07-06 09:28:49 字数 200 浏览 11 评论 0原文

我正在创建一个 RSS 阅读器作为一个业余爱好项目,并且用户可以添加自己的 URL。

我在想两件事。

  • 一个纯文本文件,其中每个 url 都是单行
  • SQLite,其中我可以在 URL 之后有唯一的 ID 和描述

SQLite 的想法是否需要很大的开销,或者是否有更好的方法来做这样的事情?

I am creating an RSS reader as a hobby project, and at the point where the user is adding his own URL's.

I was thinking of two things.

  • A plaintext file where each url is a single line
  • SQLite where i can have unique ID's and descriptions following the URL

Is the SQLite idea to much of an overhead or is there a better way to do things like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

热风软妹 2024-07-13 09:28:49

作为 OPML 文件怎么样? 它是 XML,因此如果您需要存储比 OPML 规范提供的更多数据,您可以随时添加自己的命名空间。

此外,从其他 RSS 阅读器的导入和导出都是通过 OPML 完成的。 通常有图书馆支持它。 如果您有兴趣让用户切换,那么您必须支持 OPML。 感谢詹姆斯提出这一点。

What about as an OPML file? It's XML, so if you needed to store more data then the OPML specification supplies, you can always add your own namespace.

Additionally, importing and exporting from other RSS readers is all done via OPML. Often there is library support for it. If you're interested in having users switch then you have to support OPML. Thansk to jamesh for bringing that point up.

萌辣 2024-07-13 09:28:49

为什么不使用 XML?

如果您正在处理 RSS,那么您也可以:)

Why not XML?

If you're dealing with RSS anyway you mayaswell :)

那伤。 2024-07-13 09:28:49

您打算只存储 URL 吗? 或者您计划添加诸如 last_fetch_time 之类的数据?

如果它只是一个简单的 URL 列表,您的程序将逐行读取并下载数据,请将其存储在文件中,甚至更好地存储在写入文件的某些序列化对象中。

如果您打算扩展它,添加注释/上次获取的时间等,我会选择 SQLite,这并没有那么多开销。

Do you plan just to store URLs? Or you plan to add data like last_fetch_time or so?

If it's just a simple URL list that your program will read line-by-line and download data, store it in a file or even better in some serialized object written to a file.

If you plan to extend it, add comments/time of last fetch, etc, I'd go for SQLite, it's not that much overhead.

っ左 2024-07-13 09:28:49

如果它是只有一个实例的单用户应用程序,那么 SQLite 可能就有点大材小用了。

在我看来,你有几个选择:

  1. SQLite / 数据库层。 增加代码运行所需的依赖项。 但允许并发访问
  2. Roll 您自己的文本解析器。 当您想要保存更多数据并且重新发明轮子时,复杂性就会增加。 依赖性较小,最初,虽然您的数据很简单,但对于应用程序的新手用户来说编辑起来很简单。
  3. 使用 XML。 它结构良好且结构合理。 已定义且文本可编辑。 不过,仅存储 URL 可能有点过分了。
  4. 使用类似 pickle 来序列化你的对象并保存将它们写入磁盘。 数据结构的更改意味着“升级”pickle 文件。 对于新手用户来说编辑不是很直观,但非常容易实现。

If it's a single user application that only has one instance, SQLite might be overkill.

You've got a few options as I see it:

  1. SQLite / Database layer. Increases the dependencies your code needs to run. But allows concurrent access
  2. Roll your own text parser. Complexity increases as you want to save more data and you're re-inventing the wheel. Less dependency and initially, while your data is simple, it's trivial for a novice user of your application to edit.
  3. Use XML. It's well formed & defined and text editable. Could be overkill for storing just a URL though.
  4. Use something like pickle to serialize your objects and save them to disk. Changes to your data structure means "upgrading" the pickle files. Not very intuitive to edit for a novice user, but extremely easy to implement.
遥远的绿洲 2024-07-13 09:28:49

我会选择 XML 文本文件选项。 您可以使用 Visual Studio 中内置的 XSD 工具从 XML 数据创建 DataTable,并在需要时轻松序列回文件。

另一个需要注意的是,我确信您会希望最终用户能够对他们的 RSS 提要进行分类,并能够对它们进行潜在的搜索/排序,并且拥有这种数据表样式将对此有所帮助。

您将获得轻松的文件存储和访问,这是“数据库”结构的好处,但不完全是 SQLite 的开销。

I'd go with the XML text file option. You can use the XSD tool built into Visual Studio to create a DataTable out of the XML data, and it easily serializes back into the file when needed.

The other caveat is that I'm sure you're going to want the end user to be able to categorize their RSS feeds and be able to potentially search/sort them, and having that kind of datatable style will help with this.

You'll get easy file storage and access, the benefit of a "database" structure, but not quite the overhead of SQLite.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文