Eve-of-Darkness / db-public

Vanilla database for Dawn of Light
19 stars 19 forks source link

Add table definitions in code #288

Closed NetDwarf closed 1 year ago

NetDwarf commented 1 year ago

Remove corresponding sql files Replace usage of sql files with built-in tables

NetDwarf commented 1 year ago

This is supposed to be a refactoring with no behavior changes, however of course I had to make some concessions; namely:

Regarding the SQLite types, these are still inside the broad types that SQLite actually exposes to the user (NULL, INTEGER, REAL, TEXT, BLOB)¹. So it should also not change anything in practice.

The diff is still rather small from this to the previous exported sqls and it is easy to track by eye.

NetDwarf commented 1 year ago

The goal is to have an SQL agnostic table definition. JSON has the disadvantage of being very lengthy and harder to maintain/alter. i.e.

t := newTable("Ability")
t.Static = true
t.AddPrimary("AbilityID", "int(11)").NotNullable()

in JSON:

[
  "Ability": {
    "Static" : true
    "Primary" : "AbilityID"
    "Columns" : [
      "AbilityID" : {
        "Type" : "int(11)"
        "NotNull" : true
      }
    ]
  }
]

And that was just one column.

The code definition also has the advantage that it is augmented by the IDE.

That being said. JSON would have the advantage that it's easier to add/import arbitrary tables, but this is not (yet) a goal, but it's an option for sure. The code implementation can also be tweaked, but I thought I better PR the working state instead of trying to perfect it and then just not PRing it at all.

In a way I am happy with this PR and am going to tweak the output next.