SQL on Mudlet

I wrote the following script, attempting to wrap my head around database usage in Mudlet.
function createDB()
db:create("my database", {
friends = {
name = "",
city = "",
_index = { "city" },
_unique = { "name" }
}
});
end
createDB()
local mydb = db:get_database("my database")
function purgeDB()
db:delete(mydb.friends, true)
cecho("<red>\nDatabase purged.")
end
function mergeDB()
db:merge_unique(mydb.friends, true)
cecho("<red>\nDuplicate merged.")
end
function countFriends()
echo(db:aggregate(mydb.friends.name, "count"))
end
function addFriend(playerName, playerCity)
db:add(mydb.friends, {name=playerName, city=playerCity})
cecho("<LimeGreen>\nFriend added: "..playerName)
end
function ashtanFriends()
local ashtanitefriends = db:fetch(mydb.friends, db:eq(mydb.friends.city, "Ashtan"))
display(ashtanitefriends)
end
function eleusisFriends()
local eleusianfriends = db:fetch(mydb.friends, db:eq(mydb.friends.city, "Eleusis"))
display(eleusianfriends)
end
function shallamFriends()
local shallamesefriends = db:fetch(mydb.friends, db:eq(mydb.friends.city, "Shallam"))
display(shallamesefriends)
end
I then made an alias with the pattern of ^friend (.+) (.+)$
which executed the following:
if matches[2] == "list" then
if matches[3] == "eleusis" then
eleusisFriends()
elseif matches[3] == "ashtan" then
ashtanFriends()
elseif matches[3] == "shallam" then
shallamFriends()
end
elseif matches[2] == "purge" and matches[3] == "all" then
purgeDB()
elseif matches[2] == "merge" and matches[3] == "all" then
mergeDB()
else
addFriend(matches[2], matches[3])
end
Usage would be something like:
friend Tanris ashtan
friend Darroth shallam
friend Zeon eleusis
friend list eleusis
friend purge all
I was attempting to make a 'merge' usage as you can see.. which I assumed just cleared duplicates in the database, then I realised I'm just creating a temporary array with this setup, it hasn't been committed to any real consistent database when mudlet closed all of this was lost. Can anyone elaborate on how I could finish this setup? Hopefully this also helped others trying to learn, 'coz I couldn't find any useful snippets out there that were this simple.

Comments
-
i don't know anything about sql, but i did tin across this example that may help answer your question. http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf158.html0
Hail, Stranger!
Categories
- 6K All Categories
- 3K Everything Achaea
- 1.5K North of Thera
- 21 Archives of the Terraformer
- 246 The Matsuhama Arena
- 873 The Golden Dais of Creation
- 283 The Scarlattan Theatre
- 145 The Blank Canvas
- 1.9K Getting Help
- 392 General Questions
- 251 Quick Class Questions
- 1.3K Tech Support
- 300 Client Help
- 459 Curing Systems and Scripts
- 829 Off-Topic
- 250 The Wander Inn
- 579 The Universal Membrane
- 287 Class Discussions
- 287 Individual Class Sections
- 20 Alchemist
- 9 Apostate
- 29 Blademaster
- 9 Depthswalker
- 12 Druid
- 4 Infernal
- 20 Jester
- 19 Magi
- 31 Monk
- 10 Occultist
- 7 Paladin
- 7 Priest
- 28 Runewarden
- 18 Sentinel
- 26 Serpent
- 19 Shaman
- 9 Sylvan