2

I am writing a small standalone Lua tool which uses several key/value pairs in trees as data storage. My prototype is using Lua tables, they fit perfectly for my task. However the table entries change and grow continuously. For me, that seems a good reason for storing all the data in a database.

A lot of smaller tools rely on SQLite databases but I think there must be a better (key-value) solution if one wants to store small to medium sized Lua tables. I read about storing trees with SQL but that looks complicated at first glance.

Is there a KISS solution for storing and retrieving Lua tables in databases, maybe together with a query language?

The database will still be small, should be persistent and do not need to handle parallel queries. Performance is also no issue, the tool is single-user only. I would prefer a disk/file-based DB. Ideally, the updates (queries/scripts) to the DB shall be under version control.

First I was thinking of (G)dbm as possible candidate (see here), but I do not know about a simple and "scriptable" way to modify and create new entries (as one could do with SQL statements).

I want avoid full blown/server based solutions like MongoDB or with Graph DBs like Neo4j, they would be overkill for my task at hand.

smartmic
  • 661
  • 5
  • 15
  • For "small to medium sized Lua tables" where performance isn't an issue, why not serialize to a standard format like JSON? A database would probably be overkill. – Colonel Thirty Two Apr 03 '16 at 16:30
  • @ColonelThirtyTwo Okay, but in that case I would leave the data in a lua file containing only the Lua table. Is a JSON not 1:1 comparable to a Lua table when only storing data? – smartmic Apr 03 '16 at 18:36
  • Even though you seem to avoid it, I would go with the SQLite3 approach. It's very simple, fast, scalable, uses powerful SQL (including recursive queries -- good for tree structures), provides ACID database, and offloads your main memory from keeping large data sets. – tonypdmtr Apr 03 '16 at 19:33
  • @tonypdmtr What do you recommend in SQL, I found solution with adjacency lists, nested sets, closure tables, … something else? – smartmic Apr 03 '16 at 20:03

1 Answers1

1

My lgdbm binding contains a table proxy for gdbm databases. In other words, you can interact with a gdbm database simply by reading and writing entries in Lua tables.

To keep it simple, lgdbm only works with string keys and values but it can be modified to handle other types if necessary.

lhf
  • 70,581
  • 9
  • 108
  • 149