Skip to content

Commit c621a9b

Browse files
authored
Upgrade to Crystal 0.28.0 (#38)
1 parent a95182b commit c621a9b

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

spec/driver_spec.cr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ describe Driver do
1818

1919
assert_filename("sqlite3:/path/to/file.db", "/path/to/file.db")
2020
assert_filename("sqlite3:///path/to/file.db", "/path/to/file.db")
21+
22+
{% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %}
23+
# Before 0.28.0 the filename had the query string in this case
24+
# but it didn't bother when deleting the file in pool_spec.cr.
25+
# After 0.28.0 the behavior is changed, but can't be fixed prior that
26+
# due to the use of URI#opaque.
27+
assert_filename("sqlite3:./file.db?max_pool_size=5", "./file.db")
28+
{% end %}
29+
assert_filename("sqlite3:/path/to/file.db?max_pool_size=5", "/path/to/file.db")
30+
assert_filename("sqlite3://./file.db?max_pool_size=5", "./file.db")
31+
assert_filename("sqlite3:///path/to/file.db?max_pool_size=5", "/path/to/file.db")
2132
end
2233

2334
it "should use database option as file to open" do

spec/pool_spec.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ describe DB::Pool do
2121
fibers.times { channel.receive }
2222

2323
# all numbers were inserted
24-
s = fibers * max_n * (max_n + 1) / 2
24+
s : Int32
25+
{% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %}
26+
s = fibers * max_n * (max_n + 1) // 2
27+
{% else %}
28+
s = fibers * max_n * (max_n + 1) / 2
29+
{% end %}
2530
db.scalar("select sum(n) from numbers").should eq(s)
2631

2732
# numbers were not inserted one fiber at a time

spec/spec_helper.cr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ ensure
1919
File.delete(DB_FILENAME)
2020
end
2121

22-
def with_db(name, &block : DB::Database ->)
23-
File.delete(name) rescue nil
24-
DB.open "sqlite3:#{name}", &block
22+
def with_db(config, &block : DB::Database ->)
23+
uri = "sqlite3:#{config}"
24+
filename = SQLite3::Connection.filename(URI.parse(uri))
25+
File.delete(filename) rescue nil
26+
DB.open uri, &block
2527
ensure
26-
File.delete(name)
28+
File.delete(filename) if filename
2729
end
2830

2931
def with_mem_db(&block : DB::Database ->)

src/sqlite3/connection.cr

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ class SQLite3::Connection < DB::Connection
99
end
1010

1111
def self.filename(uri : URI)
12-
URI.unescape (if path = uri.path
13-
(uri.host || "") + path
14-
else
15-
uri.opaque.not_nil!
16-
end)
12+
{% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %}
13+
URI.unescape((uri.host || "") + uri.path)
14+
{% else %}
15+
URI.unescape (if path = uri.path
16+
(uri.host || "") + path
17+
else
18+
uri.opaque.not_nil!
19+
end)
20+
{% end %}
1721
end
1822

1923
def build_prepared_statement(query)

0 commit comments

Comments
 (0)