elixir-sqlite / exqlite

An SQLite3 driver for Elixir
https://hexdocs.pm/exqlite
MIT License
217 stars 48 forks source link

Issue with ":memory:" value #237

Closed ndrean closed 1 year ago

ndrean commented 1 year ago

This key doesn't seem to work when I pass the value ":memory:". The code below works if I use any other name.

defmodule SqilteConn do
  def start do
    Exqlite.Sqlite3.open(":memory:")
  end
  def create_table(conn) do
    Exqlite.Sqlite3.execute(
      conn,
      "CREATE TABLE IF NOT EXISTS csv (
        id integer primary key, ....)
     ')
  end
end
{:ok, conn} = SqilteConn.start()
SqilteConn.create_table(conn,)

defmodule Repo do
  use Ecto.Repo, adapter: Ecto.Adapters.SQLite3, otp_app: :noop
end

defmodule Airport do
  use Ecto.schema
  ...
end

{:ok, pid} = Repo.start_link(database: ":memory:", default_chunk_size: 100)
Repo.all(Airport)

returns:

** (Exqlite.Error) no such table: csv

instead of [].

warmwaffles commented 1 year ago

Running Repo.start_link(database: ":memory:", default_chunk_size: 100) will use the default pool size where each database connection in the pool will open its own in memory database.

If you want to use an in memory database, you'll need to crank the pool size down to 1. I don't recommend doing that right now for application code because you'll have to migrate / load a structure everytime the connection is opened.

When you use any other value for the database name, it's just using that value as the path to the database from the application directory.

ndrean commented 1 year ago

OK., thanks! The in-memory use case was for comparison with Surrealdb, not for a production case.