tina4ruby 3.11.11 → 3.11.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tina4/database/sqlite3_adapter.rb +27 -1
- data/lib/tina4/drivers/sqlite_driver.rb +37 -4
- data/lib/tina4/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ffc1ea931cf8203378e774e1efb4b3dbec399dd4309757200f8cd7967732b8b
|
|
4
|
+
data.tar.gz: 5141bdc93061f5eafa53e40098732d5342f645a69cd6978f3380bd7e2c3f1606
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10b0c0e20c2389c088b494a6db800b3ea95aae3317d826491ebc4f610d6dd11e6ce13d3cc79eba23e4bde0adba2ff9fe76a4d9bbe91b10bdb47ead3ac333933a
|
|
7
|
+
data.tar.gz: a748a5ce83aa37858b99a7a1ed204385ce09f2c43886fe6742dffe2332fb5ffba56849f0f3c81e046b31d6bed17f7d1a4d5f1ba7c61365398c0863dce0c6cf7f
|
|
@@ -14,7 +14,7 @@ module Tina4
|
|
|
14
14
|
|
|
15
15
|
def connect(connection_string)
|
|
16
16
|
require "sqlite3"
|
|
17
|
-
@db_path =
|
|
17
|
+
@db_path = self.class.resolve_path(connection_string)
|
|
18
18
|
@connection = SQLite3::Database.new(@db_path)
|
|
19
19
|
@connection.results_as_hash = true
|
|
20
20
|
@connection.execute("PRAGMA journal_mode=WAL")
|
|
@@ -22,6 +22,32 @@ module Tina4
|
|
|
22
22
|
self
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# Resolve a SQLite URL / path against the project root (cwd).
|
|
26
|
+
# Convention matches Tina4::Drivers::SqliteDriver.resolve_path —
|
|
27
|
+
# three slashes = relative, four = absolute, drive letter = Windows abs.
|
|
28
|
+
def self.resolve_path(connection_string)
|
|
29
|
+
return ":memory:" if connection_string == "sqlite::memory:" || connection_string == "sqlite:///:memory:"
|
|
30
|
+
|
|
31
|
+
raw = connection_string.to_s
|
|
32
|
+
.sub(/^sqlite3?:\/\/\//, "")
|
|
33
|
+
.sub(/^sqlite3?:\/\//, "")
|
|
34
|
+
.sub(/^sqlite3?:/, "")
|
|
35
|
+
return ":memory:" if raw == ":memory:"
|
|
36
|
+
|
|
37
|
+
is_windows_abs = raw.match?(/^[A-Za-z]:[\/\\]/)
|
|
38
|
+
is_unix_abs = raw.start_with?("/")
|
|
39
|
+
|
|
40
|
+
if is_windows_abs || is_unix_abs
|
|
41
|
+
raw
|
|
42
|
+
else
|
|
43
|
+
resolved = File.join(Dir.pwd, raw)
|
|
44
|
+
parent = File.dirname(resolved)
|
|
45
|
+
require "fileutils"
|
|
46
|
+
FileUtils.mkdir_p(parent) unless File.directory?(parent)
|
|
47
|
+
resolved
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
25
51
|
def close
|
|
26
52
|
@connection.close if @connection
|
|
27
53
|
@connection = nil
|
|
@@ -7,10 +7,7 @@ module Tina4
|
|
|
7
7
|
|
|
8
8
|
def connect(connection_string, username: nil, password: nil)
|
|
9
9
|
require "sqlite3"
|
|
10
|
-
db_path =
|
|
11
|
-
# Windows: sqlite:///C:/Users/app.db → /C:/Users/app.db after stripping scheme.
|
|
12
|
-
# The leading / before the drive letter must be removed.
|
|
13
|
-
db_path = db_path[1..] if db_path.match?(/^\/[A-Za-z]:/)
|
|
10
|
+
db_path = self.class.resolve_path(connection_string)
|
|
14
11
|
|
|
15
12
|
@connection = SQLite3::Database.new(db_path)
|
|
16
13
|
@connection.results_as_hash = true
|
|
@@ -18,6 +15,42 @@ module Tina4
|
|
|
18
15
|
@connection.execute("PRAGMA foreign_keys=ON")
|
|
19
16
|
end
|
|
20
17
|
|
|
18
|
+
# Resolve a SQLite URL / path against the project root (cwd).
|
|
19
|
+
#
|
|
20
|
+
# Convention (matches tina4-python, tina4-php, tina4-nodejs):
|
|
21
|
+
# sqlite::memory: → :memory:
|
|
22
|
+
# sqlite:///:memory: → :memory:
|
|
23
|
+
# sqlite:///app.db → {cwd}/app.db (relative)
|
|
24
|
+
# sqlite:///data/app.db → {cwd}/data/app.db (relative; auto-mkdir under cwd)
|
|
25
|
+
# sqlite:////var/data/app.db → /var/data/app.db (absolute; no auto-mkdir)
|
|
26
|
+
# sqlite:///C:/Users/app.db → C:/Users/app.db (Windows absolute)
|
|
27
|
+
#
|
|
28
|
+
# Never mkdir outside cwd — that was the root cause of the
|
|
29
|
+
# "Read-only file system: '/data'" crash on macOS.
|
|
30
|
+
def self.resolve_path(connection_string)
|
|
31
|
+
return ":memory:" if connection_string == "sqlite::memory:" || connection_string == "sqlite:///:memory:"
|
|
32
|
+
|
|
33
|
+
# Strip the scheme + up to three slashes, preserving a potential fourth
|
|
34
|
+
# slash (absolute) or drive letter.
|
|
35
|
+
raw = connection_string.sub(/^sqlite:\/\/\//, "").sub(/^sqlite:\/\//, "").sub(/^sqlite:/, "")
|
|
36
|
+
return ":memory:" if raw == ":memory:"
|
|
37
|
+
|
|
38
|
+
is_windows_abs = raw.match?(/^[A-Za-z]:[\/\\]/)
|
|
39
|
+
is_unix_abs = raw.start_with?("/")
|
|
40
|
+
|
|
41
|
+
if is_windows_abs || is_unix_abs
|
|
42
|
+
# Absolute — trust the user; don't auto-mkdir outside cwd.
|
|
43
|
+
raw
|
|
44
|
+
else
|
|
45
|
+
# Relative — resolve under cwd; auto-mkdir parent dir.
|
|
46
|
+
resolved = File.join(Dir.pwd, raw)
|
|
47
|
+
parent = File.dirname(resolved)
|
|
48
|
+
require "fileutils"
|
|
49
|
+
FileUtils.mkdir_p(parent) unless File.directory?(parent)
|
|
50
|
+
resolved
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
21
54
|
def close
|
|
22
55
|
@connection&.close
|
|
23
56
|
end
|
data/lib/tina4/version.rb
CHANGED