Skip to content

Commit

Permalink
Handle sqlite3 as a scheme on Conf::GlobalSettings::Database#from_url
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmartinspt committed Nov 4, 2024
1 parent 7d2aae4 commit c6a4e70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions spec/marten/conf/global_settings/database_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,13 @@ describe Marten::Conf::GlobalSettings::Database do
db_config_1.name.should eq "marten.db"
end

it "parses sqlite url that starts with sqlite3" do
db_config_1 = Marten::Conf::GlobalSettings::Database.new("default")
db_config_1.from_url "sqlite3://marten.db"
db_config_1.backend.should eq "sqlite"
db_config_1.name.should eq "marten.db"
end

it "parses a postgres url" do
db_config_1 = Marten::Conf::GlobalSettings::Database.new("default")
db_config_1.from_url "postgres://username:password@martenframework.com:25/db"
Expand Down
6 changes: 3 additions & 3 deletions src/marten/conf/global_settings/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ module Marten
def from_url(url : String)
# URI.parse cant parse 'sqlite://:memory:'
if url.starts_with? "sqlite://:memory:"
self.backend = "sqlite"
self.backend = DB::Connection::SQLITE_ID
self.name = ":memory:"
return
end

uri = URI.parse url

self.backend = uri.scheme
self.backend = uri.scheme == "sqlite3" ? DB::Connection::SQLITE_ID : uri.scheme
self.host = uri.host
self.port = uri.port
self.user = uri.user
self.password = uri.password
self.name = uri.scheme == "sqlite" ? uri.host : uri.path[1..]?
self.name = @backend == DB::Connection::SQLITE_ID ? uri.host : uri.path[1..]?

params_map = uri.query_params.to_h

Expand Down

0 comments on commit c6a4e70

Please sign in to comment.