TinyDB

I mentioned that I am using TinyDB in my Flask website. TinyDB is a NoSQL database similar to MongoDB and CouchDB. I’ve been a big fan of MongoDB from day one, but because it no longer runs on the latest RaspberryPi OS, I looked for alternatives. I’m using CouchDB for other projects, but I prefer TinyDB because it doesn’t require a server and produces stand-alone databases in JSON.

That means, I can use TinyDB across platforms, and where the database needs to be portable, such as on iOS. Unfortunately, there is no implementation of a TinyDB library, so I’m writing my own. I’m going to keep the library call syntax close to the Python implementation of TinyDB’s simplifying porting code to iOS.

What of SwiftData, which was announced at WWDC this year, I hear you ask? Well, I haven’t gone down that rabbit hole yet. I’ve seen the high-level presentations, and it looks interesting, but from what I can tell, SwiftData is another relational model layer, better suited to CoreData and SQL databases. Now, I have nothing against SQL. In fact, I spent “many-a-year” in it and I’m expert in it both from a design and access standpoint. But document-based storage makes more sense for what I’m trying to build. SwiftData may link to a NoSQL engine, but I haven’t looked into that. That’s the reason for TinyDB.

Today, I started an XCode project, with the latest beta. I’m working on being able to read a TinyDB database since I have some reference examples I’ve created on other platforms. Although TinyDB is JSON, it has some interesting concepts. It has the concept of tables. A TinyDB database can store related documents in these tables—all in a single file. It’s like SQLite, but with JSON documents. TinyDB allows you to create custom middleware and storage engines. The example they provide is using YAML instead of JSON. I won’t be writing my own middleware or storage solutions, since I don’t need that capability for what I’m doing. I just want to read an existing database first. Then I’ll worry about manipulating it.

Depending on how things go, and how clean the code is, I may release it into the wild. We’ll see. If you want to learn more about TinyDB, check out their documentation site. https://tinydb.readthedocs.io/

blog comments powered by Disqus

This site does not track your information.