quda

quda

Exqlite - make it work with existing Sqlite db

Hi,

I need to do the following tasks for me project using Sqlite3 existing dbs (files):

  • connect to each of the Sqlite db/files in the repository
  • list all the tables in the db.
  • select (filter) some tables of interest
  • for selected tables execute one query to extract some data (a very simple query such as SELECT items FROM table WHERE condition)
  • return a map with all the collected results

So far, I managed (with difficulties) to install and configure Exqlite into the project.
I tried to follow the documentation Readme — Exqlite v0.7.9 and did:

{:ok, conn} = Exqlite.Sqlite3.open("path_to_one_db")
:ok = Exqlite.Sqlite3.execute(conn, "SELECT name FROM sqlite_master WHERE "type"='table'");

…and I got stuck. I don’t know how to use this library further on. The documentation is not very clear. There are no examples/tutorial online.
Next step is to get the list with the tables in the db.

Thanks for your help,
T.

PS: As you might have noted, I am quite new to Elixir. :flushed:

Marked As Solved

kwando

kwando

Yep, I noticed that too. But I dont think it will be very hard to guess how it works :slight_smile:

{:ok, db} = Exqlite.Basic.open(":memory:")

db
|> Exqlite.Basic.exec("create table books (title, author)")

db
|> Exqlite.Basic.exec("insert into books (title, author) values (?, ?)", ["test", "bob"])

db
|> Exqlite.Basic.exec("select * from books")
|> Exqlite.Basic.rows()

Results in this

{:ok, [["test", "bob"]], ["title", "author"]}

Also Liked

LostKobrakai

LostKobrakai

It might be worth looking at using exqlite through ecto, which is quite well documented.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement