I do a lot of sql, and I do a lot of org-mode. Lets put them together.

Native SQLite

In org-babel-load-languages turn on sqlite. (You can use customize for this if you don't have another method in use.)

Then you have a source block that looks like

1
2
3
4
5
  _#+begin_src sqlite :db test.db :colnames yes
  create table if not exists  greeting(one varchar(10), two varchar(10));
  insert into greeting values( 'Hello', 'world!');
  select * from greeting;
  _#+end_src

(Remove the _ if you are copy and pasting.)

And that will print out

  create table if not exists  greeting(one varchar(10), two varchar(10));
  insert into greeting values( 'Hello', 'world!');
  select * from greeting;
onetwo
Helloworld!

You can also set the :db property globally in your org file with:

1
#+PROPERTY: header-args :db test-sqlite.db

And then reload the file.

org-sql-mode

Install ob-sql-mode using the normal methods. This will use sql-mode to run queries, which lets you use other databases than sqlite3.

1
2
  (use-package ob-sql-mode
    :ensure t)

In org-babel-load-languages turn on sql.

And then you can run queries like so:

1
2
3
  _#+begin_src sql-mode :product postgres
    select * from commits;
  _#+end_src

There's more to it but that gives you the rough idea!

Previously

Bootstrapping React with Tailwind as so I remember

2021-04-15

Next

benbjohnson/litestream

2021-05-11

howto

Previously

SQLite in the browser pushing everything to the client

2021-04-15

Next

Controlling docker in golang So meta

2021-05-15