Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

[Mudlet] Database won't initialise

KlendathuKlendathu Eye of the StormPosts: 2,967Member @@ - Legendary Achaean
I'm trying to create a database in Mudlet so I can store settings from one session to the next, but I'm getting the following error:

Lua syntax error:../mudlet-lua/lua/DB.lua:445: bad argument #1 to 'pairs' (table expected, got string)

The code has been adapted from the ndb.init code.

ak = ak or {}
ak.schema = {
oppclass = {
rank = 0,
aff = "",
probability = 100,
_unique = {"rank"},
_violations = "REPLACE",
},
_unique = {"oppclass"},
_violations = "REPLACE",
}


function ak.init()
ak.db = db:create("akat", ak.schema)
db.__conn["akat"]:execute("pragma synchronous = OFF")
end


ak.init() --create the database

The line that's erroring is:

ak.db = db:create("akat", ak.schema)

Any help would be appreciated as this is a whole new area for me.


Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."

Comments

  • NexesNexes Posts: 86Member ✭✭✭ - Distinguished
    edited January 2015
    Try removing the last two lines? Not sure what they could mean but if they are legal I guess it's saying the entire DB can hold one unique opclass. Also if you ask for unique, maybe you should define an index. Caveats: I've never used this. Edit: last two lines in the schema def, the outermost unique and violations lines.
  • KlendathuKlendathu Eye of the StormPosts: 2,967Member @@ - Legendary Achaean
    Those two lines are meant to ensure that there's only ever one entry with a particular oppclass, and if a new one is created with an existing oppclass, the existing oppclass is overwritten with the new one.

    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • NexesNexes Posts: 86Member ✭✭✭ - Distinguished
    edited January 2015
    Klendathu said:
    Those two lines are meant to ensure that there's only ever one entry with a particular oppclass, and if a new one is created with an existing oppclass, the existing oppclass is overwritten with the new one.
    Entries of what? They are at the outermost level so they apply to the schema proper right now, I think. The uniqueness constraint should be in the schema definition for the sheet you want to insure had unique opclass fields. Edit: each sub-dictionary is the schema definition for what mudlet seems to call a sheet (a table anywhere else), which describe the format for sets of things. Those are what can have entries of things. The entire schema itself is just a list of these table schemes. I am pretty sure if you delete those lines the code will at least run, even if it might not do what you want.
  • KlendathuKlendathu Eye of the StormPosts: 2,967Member @@ - Legendary Achaean
    Edited out the two lines as suggested, db initialised, thanks!

    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • VadimusesVadimuses Posts: 1,081Member @ - Epic Achaean
    edited January 2015
    Database stuff is massively improved in 3.0. A bunch of functions were broken that are now fixed starting from the first preview.
Sign In to Comment.