#sqlx

2025-05-20

I've been playing with #RustLang again.
Using #Axum #Handlebars #Htmx #Sqlx and #Sqlite
It's a really joyful environment to work with. I'm finding it far easier than last time, a combination of much improved compiler errors, clippy guidance, #VSCode also seems to have improved understanding of the code (I'm not using #AI just Rust-Analyser and Even Better TOML
Plus I'm building depth rather than width, fits much better for exploration and learning.
The amount of syntax feels much reduced :-)

2025-05-17

Kalorik: Telegram-бот на Rust для анализа питания

В данной статье мы рассмотрим архитектуру и реализацию Telegram-бота Kalorik , написанного на языке программирования Rust. Этот бот предоставляет пользователям возможность анализировать свой рацион питания, получая автоматический расчёт калорий, макроэлементов и индекса массы тела. Особенностью проекта является использование современного стека на основе tokio , sqlx , teloxide , а также продуманная архитектура с учётом масштабируемости.

habr.com/ru/articles/910298/

#Rust #Telegram #Боты #SQLx #PostgreSQL #AI #Машинное_обучение #OpenAI #Tokio #Асинхронное_программирование

2025-05-10

Dear #axum + #sqlx users, has anyone managed to put a `Pool<DB>` (generic!) into your app state (`.with_state` on the router)?
#rust

2025-05-06

`cargo audit` reports a vulnerability in a transient dependency that isn't in the output of `cargo tree`. What's going on here?
#RustLang #CargoAudit #sqlx #Rust

$ cargo audit
    Fetching advisory database from `https://github.com/RustSec/advisory-db.git`
      Loaded 776 security advisories (from /home/tbrackett/.cargo/advisory-db)
    Updating crates.io index
    Scanning Cargo.lock for vulnerabilities (319 crate dependencies)
Crate:     rsa
Version:   0.9.8
Title:     Marvin Attack: potential key recovery through timing sidechannels
Date:      2023-11-22
ID:        RUSTSEC-2023-0071
URL:       https://rustsec.org/advisories/RUSTSEC-2023-0071
Severity:  5.9 (medium)
Solution:  No fixed upgrade is available!
Dependency tree:
rsa 0.9.8
└── sqlx-mysql 0.8.5
    ├── sqlx-macros-core 0.8.5
    │   └── sqlx-macros 0.8.5
    │       └── sqlx 0.8.5
    │           └── irdl 0.1.0
    └── sqlx 0.8.5

error: 1 vulnerability found!
$ cargo tree | grep rsa
$ cargo tree | grep sqlx-mysql
$ cargo tree | grep sqlx-macros-core
$ cargo tree | grep sqlx-macros
$
2025-04-22

The #sqlx crate's compile-time checking of #SQL is really nice. Errors in my SQL even show up in my IDE! #Rust is definitely my favorite language for #database #programming because of that. I'm not aware of any other programming language with such a feature.

2025-03-28

Удобное сканирование в структуры в связке Go/PgX. Решение проблемы сканирования в PgX. Golang

Go. PgxWrappy как решение всех проблем PgX. Если вы сталкивались с неудобным сканом в структуры посредством PgX на Go, то гляньте эту либу. Она решает все проблемы сканинга.

habr.com/ru/articles/895298/

#Golang #go #pgx #го #орм_в_го #golang_orm #orm #driver #sql #sqlx

2025-02-27

Playing around with #leptos + #axum + #tailwindcss + #sqlx I'm still very very uncomfortable with front end development, but for some reason Leptos seems to click better in my head compared to anything else.

Also honestly just wanted to try a "front + backend" project in a workspace. #rustlang

H@R0👨🏻‍💻quetalocatl
2025-02-19

Interesting, doesn't have timezone data in its datetime data type, and only supports native datetime. For example, the UTC datetime won't pass the compile-time validation. However, if we don't use compile-time validation, we can store datetime values as TEXT and cast them into UTC datetime during runtime. That's not guaranteed, though.

mmcmmmcm
2025-02-18

If anyone has a working example of , , and the DateTime (or NaiveDateTime) types working together, I'd be really glag... 🙄

H@R0👨🏻‍💻quetalocatl
2025-02-17

Tips for using the CLI: If you create the first migration without the `-r` flag, all subsequent migrations will be single files, even if you use the `-r` argument later. Therefore, remember to run `sqlx migrate add -r init` when creating the first migration if you want the ability to revert migrations.

Jons Mostovojsjonn@social.doma.dev
2025-01-24

If you want to hang out with me and a bunch of cool humans, come join my #Zulip server!

zulip.memorici.de/join/jcl42ys

Invite active for 10 days.

Here are some topics in #general stream:

general

#sqlx
Axiom of Choice
#Nix General
Music
Memes
Algorithms and data structures
Books
Links we found
AI Wins
TIL
MIT Puzzle 2025
90 minutes of music
Links from Small Internet
Playwright
AI Fails
Flood
Arts and crafs
new streams
Logjam as a metaphor
Comic books
React
GDPR
Nix Rust
OSINT
Are software developers joking or are they serious?
Tool: Synergy (Share Mouse and Keyboard)
Git stuff
UX Fails
CPU Performance in Cloud
Fresh papers
TypeScript: Newtype pattern
Type bridges
Mac OS WSL Nix
Nix Configs
UX
VSCode
Strategy

2025-01-07

Why do portions of my result object from a sqlx::query_as INNER JOIN where all the fields/columns are NOT NULL force me to have Option-wrapping the subquery bits? Is that a bug?
I'm not actually good at SQL, so I could be wrong, but an INNER JOIN means that we're guaranteed to have all the columns, right?
#Rust #RustLang #sqlx #sqlite #sql

H@R0👨🏻‍💻quetalocatl
2024-11-12

又是一個改變世界的開發工具,各個其他程式語言都相繼在仿造。 Go 的話走得比較前,sqlc 已經是可用的程式,但個人認為sqlx是最舒服最好用。無容置疑是gamechanger。就算它不支持Oracle,都值得為它放弃Oracle改用Postgresql

2024-09-01

So, #sqlx for #rust #RustLang is pretty great actually. Compile-time checked queries are a huge win for reliability! I love being able to check my queries at compile time while I'm developing. :blobcatheart: Huge benefit there!

The trouble I've found so far with this approach is there's not a good way to turn it off when you don't need it!

Downstream consumers of my library crates must compile from source (because ... Rust), but they really don't need to double-check my queries, because I already did it before I committed the code. It's just completely unnecessary for every library consumer to re-check the queries again for the same code.

Tragically, sqlx still forces downstream consumers to check the queries anyway, and requires them to have all the query metadata necessary to do that. So as a library author, I need to do a bunch of extra work to enable that step, even tho it's reaaaaally not needed. :blobcatverysad:

Yes, sqlx has an offline mode that is supposed to make this easier. And maybe it does for the postgres types. But it's actually pretty complicated to get that working since it requires a special cli and extra build steps. But for us sqlite types, there's a much simpler way.

Luckily, in my case, the sqlite schema database is a tiny file and can easily be distributed along with the library crate sources. But then you actually have to configure sqlx to find the damn thing, which, due to their reliance on .env files, is not as easy as you'd like it to be, especially in multi-package workspace environments. But thankfully cargo lets us have per-crate environmental config by just adding some instructions to build.rs.

And presto! There you have it. Compile-time metadata that library consumers shouldn't even have to worry about, but need to anyway. Maybe this is something sqlx can improve in the future.

Mo Bitar :ferris:mo8it@fosstodon.org
2024-08-24

Released a new version of #OxiTraffic to use the new version of #SQLx that fixes the following database security vulnerability:

⚠️ RUSTSEC-2024-0363
rustsec.org/advisories/RUSTSEC

Also replaced Askama with #Rinja for the templates. The migration was trivial 😃

Robert :ferris: :emacs: 🚀robert@toot.kra.hn
2024-05-20

I used #sqlx for my #rust #database needs for the longest time but recently tried #diesel again which establishes and maintains a mapping between Rust types and tables for compile time checks.

One nit I had to pick was that struct attributes couldn't easily represented as json/jsonb without manually implementing traits (sqlx has an attribute macro for that). diesel-json-derive (crates.io/crates/diesel-json-d) now allows for a similar experience with diesel.

atamakahereatamakahere
2024-05-14

SQLx is such a nice crate!

Recently I was stuck with some dynamic query building, which I didn’t knew about how to do it best in I didn’t even knew what it’s called before I asked in Rust Lang Discord server.

I got this in reply and I felt very dumb. I didn’t knew it was called “Dynamic Query Building”, I have to share code and scenario for it, but anyways

stackoverflow.com/questions/74

This post saved me for the day!

Alex Zakhlestinthisalex@hachyderm.io
2024-05-05

I didn't touch #rustlang for couple of years. Decided to write an experimental web-API server using #Axum and #SQLX and it just works. That's so strange!

chfkch :nixos: :rust:chfkch@ruhr.social
2024-04-09

Today i am stuggling with #SQLX migrations in #RustLang.
I have an app, which starts with a sync main fn, which then continues in an async init fn.
I have placed the migrate! macro there, but i am not able to migrate on `cargo build`. Anybody got a clue here?
The documentation just says to run the macro when the application starts.
Taggin @mo8it for being and sqlx-evangelist 😁️

2024-03-26

If someone has solved the problem of "composing queries" with #sqlx in #rustlang , I'll take it. This is my last attempt and it's a failure.
(it works with the non-macro sqlx::query_as(), but I'd really like to keep the static checks provided by the macro version...)

macro_rules! sql_picture_view {
    ($query:literal) => {
        concat!(
	    "SELECT pictures.*, GROUP_CONCAT(tags.tag) tags \
	     FROM pictures LEFT JOIN tags ON tags.picture = pictures.id ",
	    $query,
	    " GROUP BY pictures.id")
    }
}

pub async fn get_picture(
    State(db): State<db::Db>,
    Path(query): Path<PicQuery>
) -> AppResult<impl IntoResponse> {

    let pic : PictureV = sqlx::query_as!(
	PictureS,
	sql_picture_view!("WHERE pictures.id=$1"),
	query.id)
        .fetch_one(&db.db)
        .await?
	.into();

    Ok(Edit { pic })
}

$ cargo run
   Compiling obscura v0.1.0 (/home/case/rust/obscura)
error: expected string literal
  --> src/edit.rs:47:26
   |
47 |       let pic : PictureV = sqlx::query_as!(
   |  __________________________^
48 | |     PictureS,
49 | |     sql_picture_view!("WHERE pictures.id=$1"),
50 | |     query.id)
   | |_____________^
   |
   = note: this error originates in the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unused macro definition: `sql_picture_view`
  --> src/edit.rs:32:14
   |
32 | macro_rules! sql_picture_view {
   |              ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst