Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions gamemode/config/sv_database.lua

This file was deleted.

5 changes: 5 additions & 0 deletions gamemode/core/libs/sh_date.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ if SERVER then
-- Checks the time difference between the old time values and current time, and updates month and day to advance in the time difference
-- creates a timer that updates the month and day values, in case the server runs continuously without restarts.
function nut.date.initialize()
-- Migrations
if (istable(nut.data.get("date", os.time(), true))) then
nut.data.set("date", os.time(), true, true)
end

local configTime = os.time({
year = tonumber(os.date("%Y")),
month = tonumber(nut.config.get("month")),
Expand Down
27 changes: 25 additions & 2 deletions gamemode/core/libs/sv_database.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
nut.db = nut.db or {}
nut.db.queryQueue = nut.db.queue or {}

nut.util.include("nutscript/gamemode/config/sv_database.lua")

local function ThrowQueryFault(query, fault)
MsgC(Color(255, 0, 0), "* "..query.."\n")
MsgC(Color(255, 0, 0), fault.."\n")
Expand Down Expand Up @@ -682,6 +680,31 @@ function nut.db.delete(dbTable, condition)
return d
end

local defaultConfig = {
module = "sqlite",
hostname = "127.0.0.1",
username = "",
password = "",
database = "",
port = 3306
}

function GM:SetupDatabase()
local config = file.Read("nutscript/nutscript.json", "LUA")

if (not config) then
MsgC(Color(255, 0, 0), "Database not configured.\n")

for k, v in pairs(defaultConfig) do
nut.db[k] = v
end
else
for k, v in pairs(util.JSONToTable(config)) do
nut.db[k] = v
end
end
end

function GM:OnMySQLOOConnected()
hook.Run("RegisterPreparedStatements")
MYSQLOO_PREPARED = true
Expand Down
8 changes: 8 additions & 0 deletions gamemode/nutscript.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"module": "sqlite",
"hostname": "127.0.0.1",
"username": "",
"password": "",
"database": "",
"port": 3306
}