tcoopman
I’m using ecto with sqlite3. I was wondering if it’s possible to configure the ecto sandbox in such a way that the database is not cleaned up after a failed test, so that I can inspect the database.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 18 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
adw632
It sounds like your use case is going beyond running your elixir tests and the specific need of being able to diagnose a specific test failure.
That said, if you must “copy it and do other things with it as well”, then simply force commit the transaction from IEx.pry by typing something like
Ecto.Adapters.SQL.query!(MyApp.Repo, "COMMIT")to preserve the transaction in the database and then exit iex and then you can copy the database and do all those other things you want.jarlah
Use testcomtainers for elixir, coupled with testcontainers desktop which lets you freeze container shutdown (and thus also the test)? EDIT: nvm, not applicable for this use case.
tcoopman
I know what I can do from IEx.
I was just looking for an easy way to use sqlite itself. I like to be able to type raw sql queries sometimes.
I know I can do that with ecto as well but it’s a tiny bit more work.
Furthermore having the database available outside of the tests allows me to copy it and do other things with it as well.
adw632
Well no, and that’s not what I proposed.
I am not sure you have fully grasped the concept of using Elixir iex and IEx.pry where you are in Elixir at a break point in the code in the context of the test process and sandbox transaction where something has failed or is about to fail, and where you have access to inspect all variables and the full repertoire of Ecto queries at your fingertips to also inspect the database contents from the perspective of that sandbox transaction.
You are not running sqlite command on a different database connection outside of the Elxir/Ecto sandbox transaction.
warmwaffles
Not entirely true. Transactions certainly do work in SQLite. With how ecto does sandbox rollbacks, things get a little weird. As long as your journal mode is set to WAL and the filesystem that the system is running on is not an NFS mount, it should work just fine.
tcoopman
Yes, you can do it from within elixir.
But I don’t think I can reuse the single database connection to use the command line tool
sqlite?adw632
Yes. Within a single database connection, a SELECT statement always sees all changes to the database that are completed prior to the start of the SELECT statement, whether committed or uncommitted.
Summary fom the docs:
Transactions in SQLite are SERIALIZABLE.
Changes made in one database connection are invisible to all other database connections prior to commit.
A query sees all changes that are completed on the same database connection prior to the start of the query, regardless of whether or not those changes have been committed.
If changes occur on the same database connection after a query starts running but before the query completes, then it is undefined whether or not the query will see those changes.
If changes occur on the same database connection after a query starts running but before the query completes, then the query might return a changed row more than once, or it might return a row that was previously deleted.
For the purposes of the previous four items, two database connections that use the same shared cache and which enable PRAGMA read_uncommitted are considered to be the same database connection, not separate database connections.
tcoopman
yeah, I’m thinking that I could probably set a tag and if that tag has been set, change the sandbox mode.
But doing it manually is good enough for now.
LostKobrakai
You could look into setting the sandbox mode to manual before running a failing test. That would skip the whole transaction wrapping. That might change how the test works across multiple processes though, so keep that in mind.
tcoopman
Can you query data that hasn’t been commited by a transaction?
That doesn’t work as far as I know.
Of course you can inspect it via the elixir tools, but not with the database tools.