Crate sqlx_template

Source

Attribute Macros§

delete
The delete procedural macro transforms an SQL DELETE query with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options and support for returning the number of affected rows or no return value (void).
insert
The insert procedural macro transforms an SQL INSERT query with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options and support for returning the number of affected rows or no return value (void).
multi_query
The multi_query procedural macro transforms a series of SQL queries with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options, and is designed to handle multiple SQL statements with no return value (void).
mysql_delete
Same as crate::delete proc macro, but specified for MySQL database
mysql_insert
Same as crate::insert proc macro, but specified for MySQL database
mysql_multi_query
Same as crate::multi_query proc macro, but specified for MySQL database
mysql_query
Same as crate::query proc macro, but specified for MySQL database
mysql_select
Same as crate::select proc macro, but specified for MySQL database
mysql_update
Same as crate::update proc macro, but specified for MySQL database
postgres_delete
Same as crate::delete proc macro, but specified for Postgres database
postgres_insert
Same as crate::insert proc macro, but specified for Postgres database
postgres_multi_query
Same as crate::multi_query proc macro, but specified for Postgres database
postgres_query
Same as crate::query proc macro, but specified for Postgres database
postgres_select
Same as crate::select proc macro, but specified for Postgres database
postgres_update
Same as crate::update proc macro, but specified for Postgres database
query
The query procedural macro transforms an SQL query with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options and support for multiple return types.
select
The select procedural macro transforms a SQL query with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options and support for multiple return types.
sqlite_delete
Same as crate::delete proc macro, but specified for SQLite database
sqlite_insert
Same as crate::insert proc macro, but specified for SQLite database
sqlite_multi_query
Same as crate::multi_query proc macro, but specified for SQLite database
sqlite_query
Same as crate::query proc macro, but specified for SQLite database
sqlite_select
Same as crate::select proc macro, but specified for SQLite database
sqlite_update
Same as crate::update proc macro, but specified for SQLite database
tp_gen
tp_gen is a procedural macro attribute that provides advanced code generation capabilities for database operations. This macro allows for more complex and customizable generation of database-related functions beyond what the derive macros provide.
update
The update procedural macro transforms an SQL UPDATE query with named parameters into an asynchronous function that interacts with the database. It provides various features, including debugging options and support for returning the number of affected rows.

Derive Macros§

AnyTemplate
AnyTemplate is a database-agnostic version of SqlxTemplate that generates database operations compatible with multiple database types. This macro generates functions that work across different databases by using the most common SQL syntax.
Columns
Columns is a derive macro that generates column name constants and utility functions for database operations. This macro creates static string constants for each field in the struct, making it easier to reference column names in queries.
DDLTemplate
DDLTemplate is a derive macro that generates Data Definition Language (DDL) statements for creating database tables based on the struct definition. This macro analyzes the struct fields and their types to generate appropriate CREATE TABLE statements.
DeleteTemplate
DeleteTemplate is a derive macro designed to automatically generate record deletion functions based on sqlx. This macro creates delete methods for the struct it is applied to, returning the number of records deleted. It assumes that the columns in the database correspond to the fields in the struct.
InsertTemplate
InsertTemplate is a derive macro designed to automatically generate record insert functions based on sqlx. This macro creates insert methods for the struct it is applied to, returning the number of new records added. It assumes that the columns in the database correspond to the fields in the struct.
MysqlTemplate
MysqlTemplate is a database-specific version of SqlxTemplate optimized for MySQL. This macro generates all database operation functions specifically targeting MySQL features and syntax. It combines insert, update, select, delete, and upsert operations with MySQL-specific optimizations and syntax compatibility.
PostgresTemplate
PostgresTemplate is a database-specific version of SqlxTemplate optimized for PostgreSQL. This macro generates all database operation functions specifically targeting PostgreSQL features and syntax. It combines insert, update, select, delete, and upsert operations with PostgreSQL-specific optimizations and features like RETURNING clauses.
SelectTemplate
SelectTemplate is a derive macro designed to automatically generate record retrieval functions based on sqlx. This macro creates various query methods for the struct it is applied to, returning records from the database, assuming that the columns in the database correspond to the fields in the struct.
SqliteTemplate
SqliteTemplate is a database-specific version of SqlxTemplate optimized for SQLite. This macro generates all database operation functions specifically targeting SQLite features and syntax. It combines insert, update, select, delete, and upsert operations with SQLite-specific optimizations and syntax compatibility.
SqlxTemplate
SqlxTemplate is a comprehensive derive macro that combines all database operation templates into a single macro. This macro generates functions for insert, update, select, delete, and upsert operations based on sqlx. It’s a convenience macro that applies InsertTemplate, UpdateTemplate, SelectTemplate, DeleteTemplate, UpsertTemplate, and TableName all at once.
TableName
The TableName derive macro automatically generates a table_name function for a struct, returning the value specified in the table attribute.
UpdateTemplate
UpdateTemplate is a derive macro designed to automatically generate record update functions based on sqlx. This macro creates update methods for the struct it is applied to, reducing repetitive code and improving the readability and maintainability of your code. It assumes that the columns in the database correspond to the fields in the struct.
UpsertTemplate
UpsertTemplate is a derive macro designed to automatically generate upsert (INSERT … ON CONFLICT) functions based on sqlx. This macro creates upsert methods for the struct it is applied to, which can either insert a new record or update an existing one based on conflict resolution. It assumes that the columns in the database correspond to the fields in the struct.