diff --git a/spec/marten/conf/global_settings/database_spec.cr b/spec/marten/conf/global_settings/database_spec.cr index 3d600126..28d03008 100644 --- a/spec/marten/conf/global_settings/database_spec.cr +++ b/spec/marten/conf/global_settings/database_spec.cr @@ -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" diff --git a/src/marten/conf/global_settings/database.cr b/src/marten/conf/global_settings/database.cr index 4550e98c..97e77fff 100644 --- a/src/marten/conf/global_settings/database.cr +++ b/src/marten/conf/global_settings/database.cr @@ -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