Empty Database File

Post Reply
jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

Empty Database File

Post by jbrumble »

Hello Folks,

I've been working on putting together an item data base and I've been having a difficult time structuring it. Some basic tests databases I have made work fine. But when I try to tie everything together I end up with a database file that has nothing in it, not even the structure. I also don't end up with any errors. Attempts to display the database result in 'nil'. Could someone point out where I am going wrong?

Code: Select all

db:create("items",{item={
                          names = {"inventoryName", "equippedName", "floorDescription", "Keyword"},
                          values = {
                            rentCost = 0, 
                            purchaseCost = 0, 
                            sellValue = 0
                            },
                          location = {
                            droppedBy ="", 
                            zoneID = 0
                            },
                          requirements = {
                            minimumLevel = 0, 
                            weight = 0, 
                            alignment ="", 
                            size =""
                            },
                          purpose = {"itemType", "equipPosition"},
                          effectTable = {"type", "value"},
                          notes = ""
                          }
                          })

Thank you!

User avatar
Vadi
Posts: 4941
Joined: Sat Mar 14, 2009 3:13 pm

Re: Empty Database File

Post by Vadi »

It's a relational database, so I think the error here is putting things into nested tables. You'd have to create separate sheets. Compare your example to the one in the manual:
Code: [show] | [select all] lua
db:create(
  "items",
  {
    item =
      {
        names = {"inventoryName", "equippedName", "floorDescription", "Keyword"},
        values = {rentCost = 0, purchaseCost = 0, sellValue = 0},
        location = {droppedBy = "", zoneID = 0},
        requirements = {minimumLevel = 0, weight = 0, alignment = "", size = ""},
        purpose = {"itemType", "equipPosition"},
        effectTable = {"type", "value"},
        notes = "",
      },
  }
)
local mydb =
  db:create(
    "combat_log",
    {
      kills =
        {
          name = "",
          area = "",
          killed = db:Timestamp("CURRENT_TIMESTAMP"),
          _index = {{"name", "area"}},
        },
      enemies =
        {
          name = "",
          city = "",
          reason = "",
          enemied = db:Timestamp("CURRENT_TIMESTAMP"),
          _index = {"city"},
          _unique = {"name"},
          _violations = "IGNORE",
        },
    }
  )

jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

Re: Empty Database File

Post by jbrumble »

Thank you Vadi! I've got the database mostly working now. I'm still not sure how I'm going to get the effect table field to work. The idea is to add 1-10 effects with a type and a value field. Do you have any advice on the matter?

User avatar
Vadi
Posts: 4941
Joined: Sat Mar 14, 2009 3:13 pm

Re: Empty Database File

Post by Vadi »

Remember again this is a relational database, so you'd need a column for every effect you want to record if you want to store multiple effects and data associated with them.

jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

Re: Empty Database File

Post by jbrumble »

Thank you again Vadi, it looks like I'm a bit slow on the uptake on this one, sorry! I need to do some more reading about relational databases to fully understand what can and cannot be done. Thank you for taking the time to set me straight.

jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

Re: Empty Database File

Post by jbrumble »

Here's another question in the same line of thought: If I need a column for every effect an item can have, I will end up with an item database with about 40 columns. I'd like to echo item IDs on the screen whenever an item is visible. Is this going to cause performance issues? I am not considering creating one database of item names and IDs and then another database of item stats for when I want to see a detailed breakdown.

What do you folks think / do?

User avatar
Vadi
Posts: 4941
Joined: Sat Mar 14, 2009 3:13 pm

Re: Empty Database File

Post by Vadi »

You don't have to do two databases but you could do two sheets (see kills and enemies example above). That said 40 columns should be OK as well, just when fetching the data make sure to only fetch the data you need and not everything all the time then.

Post Reply