reddit / emacs

Examples for org-sql?

pragmat1c1 · 2022-06-16 09:32
I am trying to use an sqlite backend for my org files to quickly query the headings and the content. There are several solutions out there that save org files in sqlite databases. One is this: https://github.com/ndwarshuis/org-sql Seems pretty mature, but I don't see any example for how to use it. I haven't gotten further than these steps: (require 'org-sql) (require 'f) (defun ugt-setup-org-sql nil (interactive) (setq org-sql-files ;;(f-directories org-directory nil :recursive) (list (concat org-directory "/org-roam"))) (org-sql-user-reset) (org-sql-user-init) (org-sql-user-push)) (ugt-setup-org-sql) nil (org-sql-list-tables) ("clocks" "headlines" "properties" "file_metadata" "links" "state_changes" "file_tags" "logbook_entries" "timestamp_repeaters" "headline_closures" "outlines" "timestamp_warnings" "headline_properties" "planning_changes" "timestamps" "headline_tags" "planning_entries") And I dont' even know - Where my sqlite database has been generated. - How I can query that database.
bbenne10 · 2022-06-16 14:40
It looks like there is not an interactive function to do what you want, but `org-sql-send-sql` exists and may do what you want? I haven't dived much deeper than that to see what that stack of functions ultimately returns though
akirakom · 2022-06-16 14:41
I think you should use `ob-sql`. Here is an example for PostgreSQL: https://fluca1978.github.io/2021/01/18/PostgreSQLLiterateProgramming.html You probably can set the database file in `header-args` property.
bbenne10 · 2022-06-16 14:44
But I will note that this library does not seem to be explicitly for what you want to do. This seems like it is pushing org data into a database which is then intended to be queried outside of emacs for data analysis and/or external integration
gravygrowinggreen · 2022-06-16 14:46
Does it have to be SQL? If you are unaware, there is a fantastic package called [org-ql](https://github.com/alphapapa/org-ql), which provides significant search capabilities.
pragmat1c1 · 2022-06-16 14:59
I know that package, it‘s awesome. But when you have hundreds of org files, it is unusably slow. The developer recommends using few org files, that’s not an option.
pragmat1c1 · 2022-06-16 15:00
Sending queries is not the problem (I‘d query it with Python anyway). Getting the data into it is the challenge.
bbenne10 · 2022-06-16 16:03
It looks like theres a function for this. Check the bottom of `org-sql.el` for their public functions. I'm away from a computer, but it was called `org-sql-push` or something iirc
organic-bookworm · 2022-06-16 17:28
> (list (concat org-directory "/org-roam"))) You do know, that `org-roam` already maintains `sqlite` DB, right? The DB is located at `org-roam-db-location`. The scheme used is defined in `org-roam-db--table-schemata`. See [Accessing the Database](https://www.orgroam.com/manual.html#Accessing-the-Database). You can query the DB using `org-roam-db-query` function. You could also use [`ob-sqlite`](https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-sqlite.html) src block in Org.
pragmat1c1 · 2022-06-16 18:08
But it indexes only headings that are nodes (that is, headings for which I have generated Ord IDs), but I do not want to convert every heading into a node.
github-alphapapa · 2022-06-17 23:34
Or you can preload your Org files into Emacs with `desktop-mode`, and then org-ql can search them quickly.