Skip to content

Commit

Permalink
remove luv usage from sqlite library
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauumm committed Oct 23, 2024
1 parent 9382d50 commit 92efa30
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion extlibs/sqlite/defs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ M.connect = function(uri, opts)
open_mode = M.open_modes[open_mode or "rwc"]
end

local code = clib.sqlite3_open_v2(uri, conn, open_mode, nil)
local code = clib.sqlite3_open_v2(love.filesystem.getSaveDirectory() .. "/" .. uri, conn, open_mode, nil)

if code ~= M.flags.ok then
error(("sqlite.lua: couldn't connect to sql database, ERR: %s"):format(M.last_errmsg(conn[0])))
Expand Down
3 changes: 1 addition & 2 deletions extlibs/sqlite/helpers.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local M = {}
local luv = require("luv")
local a = require("extlibs.sqlite.assert")
local u = require("extlibs.sqlite.utils")
local fmt = string.format
Expand Down Expand Up @@ -73,7 +72,7 @@ M.run = function(func, o)
--- Run once pre-init
if o.tbl_exists == nil then
o.tbl_exists = o.db:exists(o.name)
o.mtime = o.db.uri and (luv.fs_stat(o.db.uri) or { mtime = {} }).mtime.sec or nil
o.mtime = o.db.uri and (love.filesystem.getInfo(o.db.uri) or {}).modtime or nil
rawset(
o,
"has_content",
Expand Down
5 changes: 2 additions & 3 deletions extlibs/sqlite/tbl/cache.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local u = require("sql.utils")
local luv = require("luv")

local Cache = {}

Expand Down Expand Up @@ -62,8 +61,8 @@ end
---@param query sqlite_query_select
---@return table
function Cache:get(query)
local stat = luv.fs_stat(self.db.uri)
local mtime = stat and stat.mtime.sec
local stat = love.filesystem.getInfo(self.db.uri)
local mtime = stat and stat.modtime

if self.db.modified or mtime ~= self.mtime then
self:clear(true)
Expand Down
6 changes: 0 additions & 6 deletions extlibs/sqlite/utils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local luv = require("luv")
local M = {}

M.if_nil = function(a, b)
Expand Down Expand Up @@ -102,11 +101,6 @@ M.expand = function(path)
local expanded
if string.find(path, "~") then
expanded = string.gsub(path, "^~", os.getenv("HOME"))
elseif string.find(path, "^%.") then
expanded = luv.fs_realpath(path)
if expanded == nil then
error("Path not valid")
end
elseif string.find(path, "%$") then
local rep = string.match(path, "([^%$][^/]*)")
local val = os.getenv(string.upper(rep))
Expand Down
3 changes: 1 addition & 2 deletions game_handler/profile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local strfun = require("extlibs.sqlite.strfun")
local profile = {}

local profile_path = "profiles/"
local db_path = love.filesystem.getSaveDirectory() .. "/" .. profile_path
if not love.filesystem.getInfo(profile_path) then
love.filesystem.createDirectory(profile_path)
end
Expand Down Expand Up @@ -34,7 +33,7 @@ end
---open or create a new profile
---@param name string
function profile.open_or_new(name)
local path = db_path .. name .. ".db"
local path = profile_path .. name .. ".db"
database = sqlite({
uri = path,
scores = {
Expand Down
2 changes: 1 addition & 1 deletion server/database_thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local msgpack = require("extlibs.msgpack.msgpack")
local api = {}

local server_path = "server/"
local db_path = love.filesystem.getSaveDirectory() .. "/" .. server_path .. "server.db"
local db_path = server_path .. "server.db"
local replay_path = server_path .. "replays/"
love.filesystem.createDirectory(server_path)
love.filesystem.createDirectory(replay_path)
Expand Down

0 comments on commit 92efa30

Please sign in to comment.