From e96145b4db6d5cdb8bc1bd58186c798dea4029cc Mon Sep 17 00:00:00 2001 From: James Pace Date: Wed, 14 Feb 2024 00:36:52 +0000 Subject: [PATCH] Start sqlx tutorial. --- _drafts/bible-cross-reference.md | 5 ----- _drafts/sqlx-without-macros.qmd | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) delete mode 100644 _drafts/bible-cross-reference.md create mode 100644 _drafts/sqlx-without-macros.qmd diff --git a/_drafts/bible-cross-reference.md b/_drafts/bible-cross-reference.md deleted file mode 100644 index d2eced6..0000000 --- a/_drafts/bible-cross-reference.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: "Draft" -author: "James Pace" -date: "2024/01/01" ---- diff --git a/_drafts/sqlx-without-macros.qmd b/_drafts/sqlx-without-macros.qmd new file mode 100644 index 0000000..c00a56a --- /dev/null +++ b/_drafts/sqlx-without-macros.qmd @@ -0,0 +1,38 @@ +--- +title: "Rust: sqlx without macros" +author: "James Pace" +date: "2024/01/01" +--- + +[`sqlx`](https://github.com/launchbadge/sqlx) is a Rust crate that allows +for interacting with a SQL database. +One of the more popular features of `sqlx` is that it does compile time checking +of database queries (giving you some ORM-ish properties) while still allowing +you to write straight SQL queries without the abstraction of an ORM though use +of their [`query!`](https://docs.rs/sqlx/0.5.5/sqlx/macro.query.html). + +To make this work, `sqlx` requires: + +1. access to a database at compile time, OR +2. config files to be generated from a running database everytime + the database queries are modified. + +I don't particularly like either of those options, though I admittedly +have not tried either of them long term. +Requring a running database at compile time would seem to make compilation +a lot slower. +It also adds a unexpected step (run a container hosting a development database) +before you can compile, which just feels wrong. +The configuation files are better in the sense they don't require a running +database at compile time, but it's an extra thing that has to be kept in sync +with the code. + +Luckily, `sqlx` provides functions that can be used to do queries that aren't +checked at compile time for people with the same concerns as I have. +Because this isn't the recommended path though, the number of examples of +using the functions online is a little lacking, which I'll make an effort +to improve in this post. + +# Background + +# Example