| Crates.io | rquery-orm-macros |
| lib.rs | rquery-orm-macros |
| version | 1.0.0 |
| created_at | 2025-09-09 04:14:03.433821+00 |
| updated_at | 2025-09-09 04:14:03.433821+00 |
| description | Procedural macros for rquery-orm. |
| homepage | |
| repository | https://github.com/luigimonsoft/rquery-orm/rquery-orm-macros |
| max_upload_size | |
| id | 1830254 |
| size | 38,362 |
Procedural macros for rquery-orm. It exposes the #[derive(Entity)] derive and
its attributes to turn Rust structs into SQL-mapped entities. The main crate
rquery-orm re-exports this derive, so in most cases you can just use rquery_orm::Entity;.
For an overview of the ORM and full examples, check ../README.md or the
rquery-orm crate page.
use rquery_orm::Entity; // re-exported from rquery-orm
#[derive(Entity, Debug, Clone)]
#[table(name = "Employees", schema = "dbo")] // schema is optional
pub struct Employees {
#[key(is_identity = true)]
pub employee_id: i32,
#[column(required, max_length = 50)]
pub first_name: String,
#[column]
pub last_name: String,
}
The derive implements traits used by rquery-orm:
Entity: access to table metadataFromRowNamed and FromRowWithPrefix: mapping from tiberius::Row and tokio_postgres::RowValidatable: attribute-based data validationPersistable: builds SQL for INSERT, UPDATE, and DELETEIt also generates associated constants:
YourType::TABLE with the table nameEmployees::first_name)If the first key is i32, String, or uuid::Uuid, it implements KeyAsInt,
KeyAsString, or KeyAsGuid to expose self.key().
#[table(...)]
name = "...": table name (defaults to the struct name)schema = "...": schema name (optional)#[column(...)] (for non-relation fields)
#[column]required: value must be present (not None) and, for String, non-emptyallow_null = true|false: allow None on Option<T> (defaults to false)allow_empty: allow empty string for String (allowed by default)max_length = N, min_length = Nregex = "...": pattern for Stringerror_required, error_allow_null,
error_allow_empty, error_max_length, error_min_length, error_regexignore: ignore the column in all operationsignore_in_update, ignore_in_insert, ignore_in_deletename = "...": column name when it differs from the field#[key(...)] (on key fields)
is_identity = true|false: identity/serial column (omitted from INSERT)name = "...": column name if differentignore_in_update, ignore_in_insert: fine-grained control per operation#[relation(...)] (on relation fields, metadata only)
foreign_key = "...": FK name in the current entitytable = "...": related tabletable_number = N: logical index/alias (optional)ignore_in_update, ignore_in_insertPersistable methods construct SQL and parameters using the placeholder style
selected by rquery-orm:
PlaceholderStyle::AtP → @P1, @P2, ... (SQL Server)PlaceholderStyle::Dollar → $1, $2, ... (PostgreSQL)Example (conceptual):
use rquery_orm::PlaceholderStyle;
let (sql, params, has_identity) = entity.build_insert(PlaceholderStyle::Dollar);
Typically you consume the derive re-exported from the main crate:
[dependencies]
rquery-orm = "1.0.0"
If you really need the macros crate directly (not recommended), add it explicitly:
[dependencies]
rquery-orm-macros = "1.0.0"
MIT © Luis Carlos Carrillo