Skip to content

Commit a54d3cc

Browse files
committed
feat: Import collection from Excel
1 parent 9740969 commit a54d3cc

File tree

26 files changed

+2207
-641
lines changed

26 files changed

+2207
-641
lines changed

samling-clorinde/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ time = ["dep:time"]
2121
[dependencies]
2222
## Core dependencies
2323
# Postgres types
24-
postgres-types = { version = "0.2.12", features = ["derive"] }
24+
postgres-types = { version = "0.2.9", features = ["derive"] }
2525
# Postgres interaction
26-
postgres-protocol = "0.6.10"
26+
postgres-protocol = "0.6.8"
2727

2828
## Types dependencies
2929
# TIME, DATE, TIMESTAMP or TIMESTAMPZ
30-
chrono = { version = "0.4.44", optional = true, features = ["serde"] }
31-
time = { version = "0.3.47", optional = true }
30+
chrono = { version = "0.4.40", optional = true, features = ["serde"] }
31+
time = { version = "0.3.41", optional = true }
3232
# DECIMAL
33-
rust_decimal = { version = "1.40.0", features = ["db-postgres"] }
33+
rust_decimal = { version = "1.37.1", features = ["db-postgres"] }
3434
# JSON or JSONB
35-
serde_json = { version = "1.0.149", features = ["raw_value"] }
36-
serde = { version = "1.0.228", features = ["derive"] }
35+
serde_json = { version = "1.0.140", features = ["raw_value"] }
36+
serde = { version = "1.0.219", features = ["derive"] }
3737

3838
# Postgres
39-
postgres = { version = "0.19.12", features = ["with-chrono-0_4", "with-time-0_3", "with-serde_json-1"] }
39+
postgres = { version = "0.19.10", features = ["with-chrono-0_4", "with-time-0_3", "with-serde_json-1"] }
4040

4141
## Async client dependencies
4242
# Postgres async client
43-
tokio-postgres = { version = "0.7.16", features = ["with-chrono-0_4", "with-time-0_3", "with-serde_json-1"] }
43+
tokio-postgres = { version = "0.7.13", features = ["with-chrono-0_4", "with-time-0_3", "with-serde_json-1"] }
4444
# Async utils
45-
futures = "0.3.32"
45+
futures = "0.3.31"
4646

4747
## Async features dependencies
4848
# Async connection pooling

samling-clorinde/src/queries/admin.rs

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub struct EntityFilterChoiceRowQuery<'c, 'a, 's, C: GenericClient, T, const N:
5050
client: &'c C,
5151
params: [&'a (dyn postgres_types::ToSql + Sync); N],
5252
stmt: &'s mut crate::client::async_::Stmt,
53-
extractor: fn(&tokio_postgres::Row) -> EntityFilterChoiceRowBorrowed,
53+
extractor:
54+
fn(&tokio_postgres::Row) -> Result<EntityFilterChoiceRowBorrowed, tokio_postgres::Error>,
5455
mapper: fn(EntityFilterChoiceRowBorrowed) -> T,
5556
}
5657
impl<'c, 'a, 's, C, T: 'c, const N: usize> EntityFilterChoiceRowQuery<'c, 'a, 's, C, T, N>
@@ -72,7 +73,7 @@ where
7273
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
7374
let stmt = self.stmt.prepare(self.client).await?;
7475
let row = self.client.query_one(stmt, &self.params).await?;
75-
Ok((self.mapper)((self.extractor)(&row)))
76+
Ok((self.mapper)((self.extractor)(&row)?))
7677
}
7778
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
7879
self.iter().await?.try_collect().await
@@ -83,7 +84,11 @@ where
8384
.client
8485
.query_opt(stmt, &self.params)
8586
.await?
86-
.map(|row| (self.mapper)((self.extractor)(&row))))
87+
.map(|row| {
88+
let extracted = (self.extractor)(&row)?;
89+
Ok((self.mapper)(extracted))
90+
})
91+
.transpose()?)
8792
}
8893
pub async fn iter(
8994
self,
@@ -96,7 +101,12 @@ where
96101
.client
97102
.query_raw(stmt, crate::slice_iter(&self.params))
98103
.await?
99-
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
104+
.map(move |res| {
105+
res.and_then(|row| {
106+
let extracted = (self.extractor)(&row)?;
107+
Ok((self.mapper)(extracted))
108+
})
109+
})
100110
.into_stream();
101111
Ok(it)
102112
}
@@ -105,7 +115,8 @@ pub struct StringFilterChoiceRowQuery<'c, 'a, 's, C: GenericClient, T, const N:
105115
client: &'c C,
106116
params: [&'a (dyn postgres_types::ToSql + Sync); N],
107117
stmt: &'s mut crate::client::async_::Stmt,
108-
extractor: fn(&tokio_postgres::Row) -> StringFilterChoiceRowBorrowed,
118+
extractor:
119+
fn(&tokio_postgres::Row) -> Result<StringFilterChoiceRowBorrowed, tokio_postgres::Error>,
109120
mapper: fn(StringFilterChoiceRowBorrowed) -> T,
110121
}
111122
impl<'c, 'a, 's, C, T: 'c, const N: usize> StringFilterChoiceRowQuery<'c, 'a, 's, C, T, N>
@@ -127,7 +138,7 @@ where
127138
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
128139
let stmt = self.stmt.prepare(self.client).await?;
129140
let row = self.client.query_one(stmt, &self.params).await?;
130-
Ok((self.mapper)((self.extractor)(&row)))
141+
Ok((self.mapper)((self.extractor)(&row)?))
131142
}
132143
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
133144
self.iter().await?.try_collect().await
@@ -138,7 +149,11 @@ where
138149
.client
139150
.query_opt(stmt, &self.params)
140151
.await?
141-
.map(|row| (self.mapper)((self.extractor)(&row))))
152+
.map(|row| {
153+
let extracted = (self.extractor)(&row)?;
154+
Ok((self.mapper)(extracted))
155+
})
156+
.transpose()?)
142157
}
143158
pub async fn iter(
144159
self,
@@ -151,7 +166,12 @@ where
151166
.client
152167
.query_raw(stmt, crate::slice_iter(&self.params))
153168
.await?
154-
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
169+
.map(move |res| {
170+
res.and_then(|row| {
171+
let extracted = (self.extractor)(&row)?;
172+
Ok((self.mapper)(extracted))
173+
})
174+
})
155175
.into_stream();
156176
Ok(it)
157177
}
@@ -172,11 +192,15 @@ impl SelectStyleFilterChoicesStmt {
172192
client,
173193
params: [organization_id],
174194
stmt: &mut self.0,
175-
extractor: |row| EntityFilterChoiceRowBorrowed {
176-
id: row.get(0),
177-
title: row.get(1),
178-
subtitle: row.get(2),
179-
image: row.get(3),
195+
extractor: |
196+
row: &tokio_postgres::Row,
197+
| -> Result<EntityFilterChoiceRowBorrowed, tokio_postgres::Error> {
198+
Ok(EntityFilterChoiceRowBorrowed {
199+
id: row.try_get(0)?,
200+
title: row.try_get(1)?,
201+
subtitle: row.try_get(2)?,
202+
image: row.try_get(3)?,
203+
})
180204
},
181205
mapper: |it| EntityFilterChoiceRow::from(it),
182206
}
@@ -198,11 +222,15 @@ impl SelectCategoryFilterChoicesStmt {
198222
client,
199223
params: [organization_id],
200224
stmt: &mut self.0,
201-
extractor: |row| EntityFilterChoiceRowBorrowed {
202-
id: row.get(0),
203-
title: row.get(1),
204-
subtitle: row.get(2),
205-
image: row.get(3),
225+
extractor: |
226+
row: &tokio_postgres::Row,
227+
| -> Result<EntityFilterChoiceRowBorrowed, tokio_postgres::Error> {
228+
Ok(EntityFilterChoiceRowBorrowed {
229+
id: row.try_get(0)?,
230+
title: row.try_get(1)?,
231+
subtitle: row.try_get(2)?,
232+
image: row.try_get(3)?,
233+
})
206234
},
207235
mapper: |it| EntityFilterChoiceRow::from(it),
208236
}
@@ -224,11 +252,15 @@ impl SelectAttributeFilterChoicesStmt {
224252
client,
225253
params: [organization_id],
226254
stmt: &mut self.0,
227-
extractor: |row| EntityFilterChoiceRowBorrowed {
228-
id: row.get(0),
229-
title: row.get(1),
230-
subtitle: row.get(2),
231-
image: row.get(3),
255+
extractor: |
256+
row: &tokio_postgres::Row,
257+
| -> Result<EntityFilterChoiceRowBorrowed, tokio_postgres::Error> {
258+
Ok(EntityFilterChoiceRowBorrowed {
259+
id: row.try_get(0)?,
260+
title: row.try_get(1)?,
261+
subtitle: row.try_get(2)?,
262+
image: row.try_get(3)?,
263+
})
232264
},
233265
mapper: |it| EntityFilterChoiceRow::from(it),
234266
}
@@ -250,7 +282,13 @@ impl SelectStatusFilterChoicesStmt {
250282
client,
251283
params: [organization_id],
252284
stmt: &mut self.0,
253-
extractor: |row| StringFilterChoiceRowBorrowed { title: row.get(0) },
285+
extractor: |
286+
row: &tokio_postgres::Row,
287+
| -> Result<StringFilterChoiceRowBorrowed, tokio_postgres::Error> {
288+
Ok(StringFilterChoiceRowBorrowed {
289+
title: row.try_get(0)?,
290+
})
291+
},
254292
mapper: |it| StringFilterChoiceRow::from(it),
255293
}
256294
}

samling-clorinde/src/queries/attribute.rs

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub struct AttributeRowQuery<'c, 'a, 's, C: GenericClient, T, const N: usize> {
117117
client: &'c C,
118118
params: [&'a (dyn postgres_types::ToSql + Sync); N],
119119
stmt: &'s mut crate::client::async_::Stmt,
120-
extractor: fn(&tokio_postgres::Row) -> AttributeRowBorrowed,
120+
extractor: fn(&tokio_postgres::Row) -> Result<AttributeRowBorrowed, tokio_postgres::Error>,
121121
mapper: fn(AttributeRowBorrowed) -> T,
122122
}
123123
impl<'c, 'a, 's, C, T: 'c, const N: usize> AttributeRowQuery<'c, 'a, 's, C, T, N>
@@ -139,7 +139,7 @@ where
139139
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
140140
let stmt = self.stmt.prepare(self.client).await?;
141141
let row = self.client.query_one(stmt, &self.params).await?;
142-
Ok((self.mapper)((self.extractor)(&row)))
142+
Ok((self.mapper)((self.extractor)(&row)?))
143143
}
144144
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
145145
self.iter().await?.try_collect().await
@@ -150,7 +150,11 @@ where
150150
.client
151151
.query_opt(stmt, &self.params)
152152
.await?
153-
.map(|row| (self.mapper)((self.extractor)(&row))))
153+
.map(|row| {
154+
let extracted = (self.extractor)(&row)?;
155+
Ok((self.mapper)(extracted))
156+
})
157+
.transpose()?)
154158
}
155159
pub async fn iter(
156160
self,
@@ -163,7 +167,12 @@ where
163167
.client
164168
.query_raw(stmt, crate::slice_iter(&self.params))
165169
.await?
166-
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
170+
.map(move |res| {
171+
res.and_then(|row| {
172+
let extracted = (self.extractor)(&row)?;
173+
Ok((self.mapper)(extracted))
174+
})
175+
})
167176
.into_stream();
168177
Ok(it)
169178
}
@@ -172,7 +181,7 @@ pub struct I32Query<'c, 'a, 's, C: GenericClient, T, const N: usize> {
172181
client: &'c C,
173182
params: [&'a (dyn postgres_types::ToSql + Sync); N],
174183
stmt: &'s mut crate::client::async_::Stmt,
175-
extractor: fn(&tokio_postgres::Row) -> i32,
184+
extractor: fn(&tokio_postgres::Row) -> Result<i32, tokio_postgres::Error>,
176185
mapper: fn(i32) -> T,
177186
}
178187
impl<'c, 'a, 's, C, T: 'c, const N: usize> I32Query<'c, 'a, 's, C, T, N>
@@ -191,7 +200,7 @@ where
191200
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
192201
let stmt = self.stmt.prepare(self.client).await?;
193202
let row = self.client.query_one(stmt, &self.params).await?;
194-
Ok((self.mapper)((self.extractor)(&row)))
203+
Ok((self.mapper)((self.extractor)(&row)?))
195204
}
196205
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
197206
self.iter().await?.try_collect().await
@@ -202,7 +211,11 @@ where
202211
.client
203212
.query_opt(stmt, &self.params)
204213
.await?
205-
.map(|row| (self.mapper)((self.extractor)(&row))))
214+
.map(|row| {
215+
let extracted = (self.extractor)(&row)?;
216+
Ok((self.mapper)(extracted))
217+
})
218+
.transpose()?)
206219
}
207220
pub async fn iter(
208221
self,
@@ -215,7 +228,12 @@ where
215228
.client
216229
.query_raw(stmt, crate::slice_iter(&self.params))
217230
.await?
218-
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
231+
.map(move |res| {
232+
res.and_then(|row| {
233+
let extracted = (self.extractor)(&row)?;
234+
Ok((self.mapper)(extracted))
235+
})
236+
})
219237
.into_stream();
220238
Ok(it)
221239
}
@@ -236,19 +254,22 @@ impl ListAttributesStmt {
236254
client,
237255
params: [organization_id],
238256
stmt: &mut self.0,
239-
extractor: |row| AttributeRowBorrowed {
240-
id: row.get(0),
241-
organization_id: row.get(1),
242-
type_id: row.get(2),
243-
title: row.get(3),
244-
description: row.get(4),
245-
slug: row.get(5),
246-
external_id: row.get(6),
247-
created_by: row.get(7),
248-
created_at: row.get(8),
249-
updated_at: row.get(9),
250-
r#type: row.get(10),
251-
},
257+
extractor:
258+
|row: &tokio_postgres::Row| -> Result<AttributeRowBorrowed, tokio_postgres::Error> {
259+
Ok(AttributeRowBorrowed {
260+
id: row.try_get(0)?,
261+
organization_id: row.try_get(1)?,
262+
type_id: row.try_get(2)?,
263+
title: row.try_get(3)?,
264+
description: row.try_get(4)?,
265+
slug: row.try_get(5)?,
266+
external_id: row.try_get(6)?,
267+
created_by: row.try_get(7)?,
268+
created_at: row.try_get(8)?,
269+
updated_at: row.try_get(9)?,
270+
r#type: row.try_get(10)?,
271+
})
272+
},
252273
mapper: |it| AttributeRow::from(it),
253274
}
254275
}
@@ -272,19 +293,22 @@ impl GetAttributeStmt {
272293
client,
273294
params: [organization_id, id, external_id, slug],
274295
stmt: &mut self.0,
275-
extractor: |row| AttributeRowBorrowed {
276-
id: row.get(0),
277-
organization_id: row.get(1),
278-
type_id: row.get(2),
279-
title: row.get(3),
280-
description: row.get(4),
281-
slug: row.get(5),
282-
external_id: row.get(6),
283-
created_by: row.get(7),
284-
created_at: row.get(8),
285-
updated_at: row.get(9),
286-
r#type: row.get(10),
287-
},
296+
extractor:
297+
|row: &tokio_postgres::Row| -> Result<AttributeRowBorrowed, tokio_postgres::Error> {
298+
Ok(AttributeRowBorrowed {
299+
id: row.try_get(0)?,
300+
organization_id: row.try_get(1)?,
301+
type_id: row.try_get(2)?,
302+
title: row.try_get(3)?,
303+
description: row.try_get(4)?,
304+
slug: row.try_get(5)?,
305+
external_id: row.try_get(6)?,
306+
created_by: row.try_get(7)?,
307+
created_at: row.try_get(8)?,
308+
updated_at: row.try_get(9)?,
309+
r#type: row.try_get(10)?,
310+
})
311+
},
288312
mapper: |it| AttributeRow::from(it),
289313
}
290314
}
@@ -332,7 +356,7 @@ impl GetAttributeIdStmt {
332356
client,
333357
params: [organization_id, id, external_id, slug],
334358
stmt: &mut self.0,
335-
extractor: |row| row.get(0),
359+
extractor: |row| Ok(row.try_get(0)?),
336360
mapper: |it| it,
337361
}
338362
}
@@ -400,7 +424,7 @@ impl InsertAttributeStmt {
400424
created_by,
401425
],
402426
stmt: &mut self.0,
403-
extractor: |row| row.get(0),
427+
extractor: |row| Ok(row.try_get(0)?),
404428
mapper: |it| it,
405429
}
406430
}
@@ -566,7 +590,7 @@ impl AssociateStyleAttributesStmt {
566590
client,
567591
params: [style_id, attribute_ids],
568592
stmt: &mut self.0,
569-
extractor: |row| row.get(0),
593+
extractor: |row| Ok(row.try_get(0)?),
570594
mapper: |it| it,
571595
}
572596
}

0 commit comments

Comments
 (0)