mik_sql_macros/
lib.rs

1// =============================================================================
2// CRATE-LEVEL QUALITY LINTS (following Tokio/Serde standards)
3// =============================================================================
4#![forbid(unsafe_code)]
5#![deny(unused_must_use)]
6#![warn(missing_docs)]
7#![warn(missing_debug_implementations)]
8#![warn(rust_2018_idioms)]
9// Note: unreachable_pub is not applicable to proc-macro crates where internal
10// functions need pub visibility for module organization but aren't exported
11#![warn(rustdoc::missing_crate_level_docs)]
12#![warn(rustdoc::broken_intra_doc_links)]
13// =============================================================================
14// CLIPPY CONFIGURATION FOR PROC-MACRO CRATES
15// =============================================================================
16// These lints are relaxed for proc-macro crates where syn/quote patterns are used
17#![allow(clippy::indexing_slicing)] // Checked by syn parsing structure
18#![allow(elided_lifetimes_in_paths)] // Common pattern with ParseStream
19
20//! Proc-macros for mik-sql - SQL query builder with Mongo-style filters.
21
22use proc_macro::TokenStream;
23
24mod codegen;
25mod create;
26mod debug;
27mod delete;
28mod errors;
29mod parse;
30mod read;
31mod trace;
32mod types;
33mod update;
34
35// ============================================================================
36// SQL CRUD MACROS - Query builder with JSON-like syntax
37// ============================================================================
38
39/// Build a SELECT query using the query builder (CRUD: Read).
40///
41/// # Example
42/// ```ignore
43/// let (sql, params) = sql_read!(users {
44///     select: [id, name, email],
45///     filter: { active: true },
46///     order: name,
47///     limit: 10,
48/// });
49/// ```
50#[proc_macro]
51pub fn sql_read(input: TokenStream) -> TokenStream {
52    read::sql_read_impl(input)
53}
54
55/// Build an INSERT query using object-like syntax (CRUD: Create).
56///
57/// # Example
58/// ```ignore
59/// let (sql, params) = sql_create!(users {
60///     name: str(name),
61///     email: str(email),
62///     returning: [id],
63/// });
64/// ```
65#[proc_macro]
66pub fn sql_create(input: TokenStream) -> TokenStream {
67    create::sql_create_impl(input)
68}
69
70/// Build an UPDATE query using object-like syntax (CRUD: Update).
71///
72/// # Example
73/// ```ignore
74/// let (sql, params) = sql_update!(users {
75///     set: { name: str(new_name) },
76///     filter: { id: int(user_id) },
77/// });
78/// ```
79#[proc_macro]
80pub fn sql_update(input: TokenStream) -> TokenStream {
81    update::sql_update_impl(input)
82}
83
84/// Build a DELETE query using object-like syntax (CRUD: Delete).
85///
86/// # Example
87/// ```ignore
88/// let (sql, params) = sql_delete!(users {
89///     filter: { id: int(user_id) },
90/// });
91/// ```
92#[proc_macro]
93pub fn sql_delete(input: TokenStream) -> TokenStream {
94    delete::sql_delete_impl(input)
95}
96
97// Note: ids! macro has been consolidated into mik-sdk-macros
98// Users get ids! via mik-sdk or mik-sql (which re-exports from mik-sdk-macros)