Skip to content

Commit 547ed72

Browse files
Use Connection.connect instead of Sqlite3.open (#96)
1 parent 6fdb3e4 commit 547ed72

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

lib/ecto/adapters/sqlite3.ex

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,27 @@ defmodule Ecto.Adapters.SQLite3 do
209209

210210
@impl Ecto.Adapter.Storage
211211
def storage_up(options) do
212-
storage_up_with_path(
213-
Keyword.get(options, :database),
214-
Keyword.get(options, :journal_mode, :wal)
215-
)
212+
database = Keyword.get(options, :database)
213+
214+
cond do
215+
is_nil(database) ->
216+
raise ArgumentError,
217+
"""
218+
No SQLite database path specified. Please check the configuration for your Repo.
219+
Your config/*.exs file should have something like this in it:
220+
221+
config :my_app, MyApp.Repo,
222+
adapter: Ecto.Adapters.SQLite3,
223+
database: "/path/to/sqlite/database"
224+
"""
225+
226+
File.exists?(database) ->
227+
{:error, :already_up}
228+
229+
true ->
230+
{:ok, state} = Exqlite.Connection.connect(options)
231+
:ok = Exqlite.Connection.disconnect(:normal, state)
232+
end
216233
end
217234

218235
@impl Ecto.Adapter.Migration
@@ -446,29 +463,6 @@ defmodule Ecto.Adapters.SQLite3 do
446463
## HELPERS
447464
##
448465

449-
defp storage_up_with_path(nil, _) do
450-
raise ArgumentError,
451-
"""
452-
No SQLite database path specified. Please check the configuration for your Repo.
453-
Your config/*.exs file should have something like this in it:
454-
455-
config :my_app, MyApp.Repo,
456-
adapter: Ecto.Adapters.SQLite3,
457-
database: "/path/to/sqlite/database"
458-
"""
459-
end
460-
461-
defp storage_up_with_path(db_path, journal_mode) do
462-
if File.exists?(db_path) do
463-
{:error, :already_up}
464-
else
465-
db_path |> Path.dirname() |> File.mkdir_p!()
466-
{:ok, db} = Exqlite.Sqlite3.open(db_path)
467-
:ok = Exqlite.Sqlite3.execute(db, "PRAGMA JOURNAL_MODE = #{journal_mode}")
468-
:ok = Exqlite.Sqlite3.close(db)
469-
end
470-
end
471-
472466
defp dump_versions(config) do
473467
table = config[:migration_source] || "schema_migrations"
474468

0 commit comments

Comments
 (0)