1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! MongoDB's document.
//!
//! The same assembly as the SQL family's, with three answers changed: the derives are serde's, the
//! column name rides on `#[serde(rename = "…")]`, and the emitted type is a DOCUMENT rather than a
//! row.
//!
//! No dialect parameter, and nothing shaped like one. MongoDB has no dialects — one driver, one
//! wire format, one collection vocabulary — so where the SQL family answers for three databases
//! this file answers for one. That is why the two are separate files rather than one with a switch
//! inside: the switch would be over a distinction only one side has.
//!
//! ## serde is reached through the `__private` shelf, in TWO halves
//!
//! A declaration that stores mongo documents needs serde nowhere in its own manifest: the derives
//! are `#krate::__private::serde::{Serialize, Deserialize}`, the framework's re-export of the crate
//! itself. What it asks of a consumer instead is `ingraph` carrying the shelf item — feature
//! `serde`, or the `mongodb`/`config` tiers that imply it.
//!
//! Both halves are load-bearing, and the first alone LOOKS done:
//!
//! 1. the derive path, which resolves the macro; and
//! 2. `#[serde(crate = "…::__private::serde")]`, which tells serde's OWN expansion where serde is.
//! Without it the macro resolves and the code it writes still opens with `extern crate serde as
//! _serde` — so a consumer without serde as a direct dependency still fails to compile, inside a
//! generated item they cannot edit.
//!
//! The pair works because serde's derive takes a crate-path override at all (`serde_derive`'s
//! `internals::attr` parses `CRATE` into `custom_serde_path`, and `dummy::wrap_in_const` spends it
//! as `use <path> as _serde;`). `sqlx::FromRow` takes none, which is why the SQL family cannot
//! derive at all and emits its `FromRow` impl instead — see [`super::sql`]. Both families reach the
//! shelf; only this one gets there through a derive.
//!
//! The path is the DECLARER's: `#[ingraph(crate = "…")]` retargets it like every other shelf
//! reference, the string literal included.
use quote;
use ;
use crate;
/// MongoDB's answers to the four questions a row's emission asks.
pub
/// The EXTRACTION: a document's fields read back into the row, one at a time, under the names this
/// database spells them.
///
/// # It is the `FromRow` discipline's bson twin, and the reason it is emitted at all is the CELL
///
/// serde's derive can be shelved — [`family`] above still derives the pair — so the obvious answer
/// was `#[derive(Deserialize)]` plus `#[serde(deserialize_with = "…")]` for a declaration's own
/// conversions. It was measured and refused, and the measurement is about
/// `serde::de::Error::custom`: it takes a `Display` and hands back the FORMAT's error, so a
/// declared refusal reaches a caller as a `bson::de::Error` carrying a string, and the
/// `mongo(try_into(error = "…"))` cell holds nothing at all. This framework's standing
/// rule is that a declared error type is the one a caller matches on, and a decode that flattens
/// every refusal into a string is a decode that cannot keep it.
///
/// # An INHERENT method, where the SQL family writes a trait impl
///
/// `FromRow` is sqlx's, so emitting an impl of it binds a VENDORED trait and the era rule does not
/// reach it. The bson twin is the FRAMEWORK's, and the framework's trait layer is what that rule
/// exists over — so what lands here is an inherent `from_document`, which binds nothing, and the
/// engine binding that DELEGATES to it arrives with the rest of the query face.
///
/// # What it does NOT do, and where that work is
///
/// It applies no declared conversion. The row's fields are the STORED types, so a column's
/// `into`/`try_into` legs run in the `TryFrom<Row> for Record` beside it — which is where
/// [`DatabaseBackend::conversions`](super::DatabaseBackend::conversions) already puts them, through
/// the one `Conversion` authority, `error_with` escapes included. That is the same split
/// `from_row` makes: the decode reads the format and the crossing spends the declaration.
///
/// # The error is the FORMAT's, and it is `sqlx::Error`'s position
///
/// `from_row` answers with the driver's error and `SqlQuery::record` answers with the declared
/// cell — two homes, one each. This mirrors it: the extraction answers with `MongoExtractionError`,
/// which names the FIELD on every failure, and the crossing beside it answers with whatever the
/// declaration named. A caller who wants one type gets it at the engine seam, where both are boxed.
///
/// # It rides the GATE, and it is the second item that does
///
/// Every name it writes — `bson::Document`, the extraction and its refusal — exists only in a build
/// that compiled the MongoDB backend in, so an ungated one would make a declaration naming MongoDB
/// fail to compile wherever the feature is off. That is exactly the invariant the gate exists to
/// hold, and the storability audit beside it already rides the same one.
///
/// The SQL family's decode does not, and the asymmetry is a fact about the two SHELVES rather than a
/// decision here: `__private::sqlx` is gated on the family root, so a `FromRow` impl is already
/// unreachable without it and gating it would change nothing. Closing that is its own change.