elixir-sqlite / exqlite

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

is there way to run some sqlite command, such as .import #295

Closed lei0zhou closed 1 month ago

lei0zhou commented 2 months ago

for example importing a csv file, could you suggest a way to do that? thanks!

image
warmwaffles commented 2 months ago

So the sqlite cli is compiled with that support. Bog standard embedded sqlite does not have this ability. https://sqlite.org/cli.html

Your best bet is to parse the CSV and stream it into the database

"priv/english.csv"
|> File.stream!()
|> CSV.decode()
|> Enum.each(fn row ->
  Repo.insert(....)
end)

Or use the CLI to import it manually.

EDIT:

Sqlean has an ability to read a CSV as a virtual table as well https://github.com/nalgeon/sqlean but you'll need to compile the extension and load it.