# Sqlite database column types

**URL:** https://org-roam.discourse.group/t/sqlite-database-column-types/3412
**Category:** Development
**Created:** [March 28, 2024, 9:52am UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412 "2024-03-28T09:52:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kalin](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kalin](https://org-roam.discourse.group/u/kalin)
#### Post date: [March 28, 2024, 9:52am UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412/1 "2024-03-28T09:52:48Z")

</div>

Hello fellow org-roamers,

I am trying to build a graph visualizer for myself in Rust. I use sqlx for interaction with the database, which allows you to load rows into a user-defined struct, very convenient. It does require however that all columns have a set datatype, which is not the case with the org-roam database. Can I just naively define types? What should I take into consideration? Thank you and have a great day!

---

<div class="post-metadata">

### Author: ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)
#### Post date: [March 28, 2024, 1:55pm UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412/2 "2024-03-28T13:55:19Z")

</div>

Org-roam relies on another library called `emacsql` for interfacing with the database (`sqlite`). Have a look at this [FAQ](https://github.com/magit/emacsql?tab=readme-ov-file#faq) from that project:

> #### Why are all values stored as strings?
> 
> EmacSQL is not intended to interact with arbitrary databases, but to be an ACID-compliant database for Emacs extensions. This means that EmacSQL cannot be used with a regular SQL database used by other non-Emacs clients.
> 
> All database values must be s-expressions. When EmacSQL stores a value — string, symbol, cons, etc. — it is printed and written to the database in its printed form. Strings are wrapped in quotes and escaped as necessary. That means “bare” symbols in the database generally look like strings. The only exception is `nil`, which is stored as `NULL`.
> 
> #### Will EmacSQL ever support arbitrary databases?
> 
> The author of EmacSQL [thinks](https://github.com/magit/emacsql/issues/35#issuecomment-346352439) that it was probably a design mistake to restrict it to Emacs by storing only printed values, and that it would be a lot more useful if it just handled primitive database types.
> 
> However, EmacSQL is in maintenance mode and there are no plans to make any fundamental changes, not least because they would break all existing packages and databases that rely on the current EmacSQL behavior.

---

<div class="post-metadata">

### Author: ![kalin](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kalin](https://org-roam.discourse.group/u/kalin)
#### Post date: [March 28, 2024, 2:18pm UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412/3 "2024-03-28T14:18:15Z")

</div>

Doesn’t that mean that I can just set all columns to `TEXT` to maintain compatibility with EmacSQL and get the values as `String` and if I need to cast any of them I can do it in rust?

---

<div class="post-metadata">

### Author: ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)
#### Post date: [March 28, 2024, 3:41pm UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412/4 "2024-03-28T15:41:58Z")

</div>

That’d be my guess. I suppose you can try and find out if this understanding holds.

---

<div class="post-metadata">

### Author: ![dmg](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dmg](https://org-roam.discourse.group/u/dmg)
#### Post date: [May 18, 2024, 6:46pm UTC](https://org-roam.discourse.group/t/sqlite-database-column-types/3412/5 "2024-05-18T18:46:44Z")

</div>

sqlite tables do not really have datatypes (they are hints). emacsql stores data as s-exps. See this:

[https://www.emacswiki.org/emacs/Sexp#sexp](https://www.emacswiki.org/emacs/Sexp#sexp)

Load the database into something like sqlitebrowser and you will quickly grasp the idea.
