MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / get_primary_key_value

Method get_primary_key_value

src/entity/active_model.rs:126–166  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

124 /// Panics if arity of primary key exceed maximum arity of [ValueTuple]
125 #[allow(clippy::question_mark)]
126 fn get_primary_key_value(&self) -> Option<ValueTuple> {
127 let mut cols = <Self::Entity as EntityTrait>::PrimaryKey::iter();
128 macro_rules! next {
129 () => {
130 if let Some(col) = cols.next() {
131 if let Some(val) = self.get(col.into_column()).into_value() {
132 val
133 } else {
134 return None;
135 }
136 } else {
137 return None;
138 }
139 };
140 }
141 match <<<Self::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {
142 1 => {
143 let s1 = next!();
144 Some(ValueTuple::One(s1))
145 }
146 2 => {
147 let s1 = next!();
148 let s2 = next!();
149 Some(ValueTuple::Two(s1, s2))
150 }
151 3 => {
152 let s1 = next!();
153 let s2 = next!();
154 let s3 = next!();
155 Some(ValueTuple::Three(s1, s2, s3))
156 }
157 len => {
158 let mut vec = Vec::with_capacity(len);
159 for _ in 0..len {
160 let s = next!();
161 vec.push(s);
162 }
163 Some(ValueTuple::Many(vec))
164 }
165 }
166 }
167
168 /// Perform an `INSERT` operation on the ActiveModel
169 ///

Callers 3

addMethod · 0.80
add_manyMethod · 0.80
find_updated_model_by_idFunction · 0.80

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected