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.38.0 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.

Last Post!

quda

quda

This is it!
Thanks @kwando

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement