# sqlx-template `sqlx-template` is a Rust library designed to generate database query functions using macros, based on the `sqlx` framework. It aims to provide a flexible, simple way to interact with databases such as MySQL, Postgres, and SQLite.
## Features - Generate functions for select, insert, update, delete, and order by queries based on fields. - Various return types such as counting, paging, streaming, returning (Postgres only), fetch_one, fetch_all, and rows_affected. - All generated query functions include the corresponding code in the documentation. - Supports transactions and optimistic locking templates. - Customizable queries with named parameters and the ability to run multiple queries. - Import queries from files. - Customizable logging and debugging for queries and execution time. - Compile-time query syntax validation. ## Requirements - The generated functions depend on the `sqlx` crate, so you need to add it to your dependencies before using this library. - Columns in the database must match the names and data types of the fields in the struct. - Structs need to derive `sqlx::FromRow` and `TableName`. ## Example Code ```rust use sqlx_template::{multi_query, query, select, update, DeleteTemplate, SelectTemplate, TableName, UpdateTemplate}; #[derive(sqlx::FromRow, InsertTemplate, UpdateTemplate, SelectTemplate, DeleteTemplate, TableName)] #[debug_slow = 1000] #[table_name = "users"] #[tp_delete(by = "id")] #[tp_delete(by = "id, email")] #[tp_select_all(by = "id, email", order = "id desc")] #[tp_select_one(by = "id", order = "id desc", fn_name = "get_last_inserted")] #[tp_select_one(by = "email")] #[tp_select_page(by = "org", order = "id desc, org desc")] #[tp_select_count(by = "id, email")] #[tp_update(by = "id", op_lock = "version", fn_name = "update_user")] #[tp_select_stream(order = "id desc")] #[tp_select_stream(by = "email", order = "id desc")] pub struct User { #[auto] id: i32, email: String, password: String, org: Option