72 lines
2.5 KiB
Lua
72 lines
2.5 KiB
Lua
-- ============================================================
|
||
-- db/creator.lua – Garage CRUD queries
|
||
-- ============================================================
|
||
|
||
function db.createGarage(sourcePlayer, garageData)
|
||
assert(garageData, "db.createGarage data must be provided")
|
||
|
||
local identifier = GetPlayerIdentifier(sourcePlayer)
|
||
assert(identifier, "db.createGarage identifier is nil")
|
||
|
||
local insertId = MySQL.insert.await(
|
||
"INSERT INTO player_garages (creator, name, price, coords, zone, shell, type, available, isImpound, jobs, gangs, interior_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||
{
|
||
identifier,
|
||
garageData.name,
|
||
garageData.price,
|
||
json.encode(garageData.coords),
|
||
json.encode(garageData.zone),
|
||
json.encode(garageData.shell),
|
||
garageData.type,
|
||
garageData.available,
|
||
garageData.isImpound,
|
||
json.encode(garageData.jobs),
|
||
json.encode(garageData.gangs),
|
||
garageData.interior_type,
|
||
}
|
||
)
|
||
|
||
Debug("db.createGarage", "Inserted", insertId, "Identifier", identifier)
|
||
return insertId, identifier
|
||
end
|
||
|
||
function db.updateGarage(sourcePlayer, garageData)
|
||
assert(garageData, "db.updateGarage data must be provided")
|
||
|
||
local identifier = GetPlayerIdentifier(sourcePlayer)
|
||
assert(identifier, "db.updateGarage identifier is nil")
|
||
|
||
local affected = MySQL.update.await(
|
||
"UPDATE player_garages SET name = ?, price = ?, coords = ?, zone = ?, shell = ?, type = ?, available = ?, isImpound = ?, jobs = ?, gangs = ?, interior_type = ? WHERE id = ?",
|
||
{
|
||
garageData.name,
|
||
garageData.price,
|
||
json.encode(garageData.coords),
|
||
json.encode(garageData.zone),
|
||
json.encode(garageData.shell),
|
||
garageData.type,
|
||
garageData.available,
|
||
garageData.isImpound,
|
||
json.encode(garageData.jobs),
|
||
json.encode(garageData.gangs),
|
||
garageData.interior_type,
|
||
garageData.id,
|
||
}
|
||
)
|
||
|
||
Debug("db.updateGarage", "Updated", affected, "Identifier", identifier)
|
||
return affected
|
||
end
|
||
|
||
function db.removeGarage(garageId)
|
||
assert(garageId, "db.removeGarage garage is nil")
|
||
|
||
local affected = MySQL.update.await(
|
||
"DELETE FROM player_garages WHERE name = ?",
|
||
{ garageId }
|
||
)
|
||
|
||
Debug("db.removeGarage", "Deleted", affected, "Garage", garageId)
|
||
return affected
|
||
end
|