~glorifiedgluer/gluer.org

6a4a875491af8e8a57a7ae320e03775aef9e1d06 — Victor Freire 2 months ago f07ceda main
article: getting-a-list-of-sqlite-tables-and-columns
1 files changed, 27 insertions(+), 0 deletions(-)

M content-org/content.org
M content-org/content.org => content-org/content.org +27 -0
@@ 6944,6 6944,33 @@ open System.Security.Cryptography
Random.range 1 6 // happy secure random number!
#+end_src

** Getting a list of SQLite tables and columns                    :database:
:PROPERTIES:
:EXPORT_DATE: 2024-06-25
:EXPORT_FILE_NAME: getting-a-list-of-sqlite-tables-and-columns
:EXPORT_HUGO_SLUG: getting-a-list-of-sqlite-tables-and-columns
:END:

#+begin_description
I don't know why you would want this, but...
#+end_description

I was thinking of writing an F# SQLite [[https://learn.microsoft.com/en-us/dotnet/fsharp/tutorials/type-providers/][Type Provider]] and the start
point would be to get the needed metadata to generate the types.
Here's how you can get a list of tables, columns and its types:

#+begin_src sql
SELECT m.name AS tableName
      ,c.name AS columnName
      ,c.type AS columnType
FROM sqlite_master m
LEFT OUTER JOIN pragma_table_info((m.name)) c
     ON m.name <> p.name
ORDER BY tableName, columnName, columnType;
#+end_src

Source: [[https://stackoverflow.com/a/50548508]]

* Footnotes

[fn:60] Which is the best kind of software, by the way.