Start sqlx tutorial.
This commit is contained in:
parent
9a84c31885
commit
e96145b4db
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
title: "Draft"
|
|
||||||
author: "James Pace"
|
|
||||||
date: "2024/01/01"
|
|
||||||
---
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue