Login
You're viewing the ruby.social public feed.
  • 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

Replies

  • 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