Login
You're viewing the ruby.social public feed.
  • May 15, 2026, 2:09 AM

    so ... I recently was/am working on database related stuff ... and blobs can be anything, right?

    so ...
    what if I just stored a database inside another database as a blob?

    💬 1🔄 0⭐ 1

Replies

  • 💬 0🔄 0⭐ 0
  • May 15, 2026, 3:46 AM

    @loganer SQL databases sorta kinda do this already since they tend to be built on standard B-tree key-value store databases, with the other SQL columns then looked up in the value of that database

    💬 1🔄 0⭐ 0
  • May 15, 2026, 3:56 AM

    @nytpu ok cool, so in theory at least recursive databases should work...

    not a problem I have to deal with right now of course but something I was curious of as it could reduce the total number of actual database files I'll need to create.
    (assuming I can figure out how to write into a file housed entirely in ram, as I will still need a buffer for extracting/inserting.)

    💬 1🔄 0⭐ 0
  • May 15, 2026, 4:02 AM

    @loganer I mean… why though? There's a very high chance you can do whatever you're trying to do with multiple tables and then a view wrapping some complex join

    💬 1🔄 0⭐ 0
  • May 15, 2026, 5:14 AM

    @nytpu because I would already be using tables for something else.

    basically I have an object that represents a database ...
    the tables of that databese are acting like 'categories' while the rows are elements of that category.
    and each one of these groupings needs to be it's own thing.

    character{profile{...},memory{...},inventor{...}};
    characters[character];

    but everything is still kind of WIP on even the single layer db so it's a problem for later.

    💬 1🔄 0⭐ 0
  • May 15, 2026, 5:24 AM

    @nytpu right now I'm just going to be saving each of the ... ?larger groups of things? as a seperate database file.
    in the case of a character it would be database.character_name.db or similar.

    the reason for this seperation is so I can have a clean compartmentalization of what each of the characters are and know.
    (I would rather not go insane figuring out the syntax to fuzzy search each of the characters apart from each other.)

    💬 0🔄 0⭐ 0
  • May 15, 2026, 5:29 AM

    @loganer
    Yeah, as with most questions/thoughts about doing bizarre things like that, just a misunderstanding of how to structure relational databases. In particular making a table or especially a full DB for every character is, frankly, just nonsense and not really at all how SQL should (or really even can) be used (unless you have a permanently-unchanging, small, known-ahead-of-time set of characters)

    For most cases you could have a table for each subsection of character with all the associated data, and one or more rows per character, each with a foreign key back to the table that has one row for each character (which could be as simple as solely an ID, although any data present for nearly all characters and is one-to-one should be in there). With that you can have one-to-many relationships between a character and data fields, many-to-one relationships between characters and a data field, etc., and with only slight modifications needed for many-to-many

    💬 1🔄 0⭐ 0
  • May 15, 2026, 5:36 AM

    @nytpu that's ... it would work if all the characters had all the attribute and I was only using the object strictly for characters.

    if I for instance have a character with an inventory and then a character without an inventory, the one without will still need an empty "inventory" because the rows need to have the same number of columns.

    💬 1🔄 0⭐ 0
  • May 15, 2026, 5:45 AM

    @loganer
    So… make a table that has inventory items, with each item having a foreign key linking back to the owner? And if you really need to distinguish between "no inventory" and "empty inventory" (i.e. no result rows" then just have a flag in the character table.

    Something like (just writing this SQL from memory without testing):

    CREATE TABLE characters (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL UNIQUE
    );

    CREATE TABLE inventory (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    owner INTEGER NOT NULL
    REFERENCES characters (id)
    );

    -- Get a given character's inventory list:
    SELECT id, name
    FROM inventory_items
    WHERE owner IN
    (SELECT id
    FROM characters
    WHERE name = 'loganer');

    Or I'd probably go even with like (creating a many-to-many)

    CREATE TABLE characters (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL UNIQUE
    );

    CREATE TABLE items (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL
    );

    CREATE TABLE inventory_items (
    character INTEGER NOT NULL
    REFERENCES characters (id),
    item INTEGER NOT NULL
    REFERENCES items (id)
    );

    (probably with a lot more stuff ON DELETE CASCADE and indices and triggers and such, depending on the DBMS you're using)

    💬 1🔄 0⭐ 1
  • May 15, 2026, 5:51 AM

    @loganer Sorry, I don't mean to be excessively critical, just that doing "cursed" stuff with SQL in particular just makes it a nightmare to get anything done so I try and steer people onto a more right path lol

    💬 1🔄 0⭐ 0
  • May 15, 2026, 5:53 AM

    @loganer And a big thing with SQL is with foreign keys, it's acceptable to mix a whole bunch of subsets of data conceptually "owned" by different things together in one big table as long as it has the same "shape", since it's easy enough to separate them out with a query (and without even much performance hit if you make an index on the foreign key)

    💬 2🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • May 15, 2026, 5:58 AM

    @loganer Although, if you don't expect you'll need super complex queries on the data anyways, maybe this is a case where a NoSQL database actually makes sense for you to use? Just a key-value store (or a JSON-like nested KV-store + arrays) might be enough since no individual-level project really needs Maximum Performance

    💬 0🔄 0⭐ 0