Skip to content

Commit

Permalink
Merge pull request #48 from B4NGDAI/main
Browse files Browse the repository at this point in the history
fix database
  • Loading branch information
KadDarem authored Jan 27, 2025
2 parents 9c9528e + 7a0843c commit 9497739
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions jo_libs/modules/database/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ jo.file.load("@oxmysql.lib.MySQL")
---@param tableName string the name of the table
---@param definition string the definition of the table
function jo.database.addTable(tableName, definition)
local isExist = MySQL.single.await("SHOW TABLES LIKE @tableName", { tableName = tableName })
local isExist = MySQL.single.await("SHOW TABLES LIKE ?", { tableName })
if isExist then
return false
end

MySQL.update.await("CREATE TABLE IF NOT EXISTS " .. tableName .. " (" .. definition .. ")")
gprint("Database table created : " .. tableName)
gprint("Database table created: " .. tableName)
return true
end

Expand All @@ -22,19 +23,26 @@ function jo.database.addTrigger(triggerName, definition)
return false
end
MySQL.query.await("CREATE TRIGGER `" .. triggerName .. "` " .. definition)
gprint("Database trigger created : " .. triggerName)
gprint("Database trigger created: " .. triggerName)
return true
end

---@param tableName string the name of the table
---@param name string the name of the column
---@param definition string the definition of the column
function jo.database.addColumn(tableName, name, definition)
local tableExists = MySQL.single.await("SHOW TABLES LIKE ?", { tableName })
if not tableExists then
error("Table " .. tableName .. " does not exist")
return false
end

local isExist = MySQL.single.await("SHOW COLUMNS FROM " .. tableName .. " LIKE ?", { name })
if isExist then
return false
end

gprint("Database column " .. name .. " added to " .. tableName)
MySQL.update.await("ALTER TABLE `" .. tableName .. "` ADD `" .. name .. "` " .. definition)
return true
end
end

0 comments on commit 9497739

Please sign in to comment.