What's clearing out the nodes table?

When I start emacs, for some reason my nodes table in the database is emptied. I have no idea what’s doing that yet. This is what happens when I query the nodes table before starting emacs and then after starting emacs:

$ sqlite3 org-roam.db
SQLite version 3.32.3 2020-06-18 14:16:19
Enter ".help" for usage hints.
sqlite> select count(*) from nodes;
1306
sqlite> select count(*) from nodes;
0
sqlite> 

Has anyone seen this type of problem? I need to run org-roam-db-sync in order to repopulate the database, every time I run Emacs. I have been working around this problem for a couple months but and ready to figure out the problem and fix it now.

A similar bit different issue on GitHub: org-roam-node-find or org-roam-node-insert not showing nodes · Issue #2165 · org-roam/org-roam · GitHub

I can’t reproduce it and could not help with solving it.

It is reported that the DB is empty after upgrade of Org-roam and if I understand it correctly, db-sync does not repopulate the DB — different from your issue.

Yeah this isn’t just when upgrading – this happens every time I close and reopen.

I see that back and forth you had with people on Github. I don’t know if that is related to what i’m seeing.

Does anyone know of a way to turn on logging of all commands sent to the database? I read through some library code and then put this in my config.el:

(emacsql-enable-debugging (org-roam-db--get-connection))

But that didn’t result in all the SQL that’s sent to the database being logged in the resulting buffer. I think if I could see all the commands, I could identify what is issuing a delete statement and trace it back from there.

OK, it took a while for me to get back to this, but I appear to have a partial solution to this problem for now.

I found that I needed to comment out +org-roam-try-init-db-a, which is in org/contrib/roam2.el.

Does anyone know why this function is misbehaving like this? Every time I start Emacs, it creates the tables from scratch, which results in the org-roam-db being wiped.

1 Like

Perhaps you use an alternative org-roam-database-connector? What does function emacsql-sqlite-ensure-binary do?