1#![allow(dead_code)]
2#![allow(unused_imports)]
3use std::{pin::pin, str::FromStr, sync::LazyLock};
4use tank::{
5 Driver, Entity, Executor, Interval, Query, QueryResult, SqlWriter,
6 stream::{StreamExt, TryStreamExt},
7};
8use tokio::sync::Mutex;
9use uuid::Uuid;
10
11#[derive(Entity, Debug, PartialEq)]
12struct Container {
13 first: [[Interval; 2]; 1],
14 second: [[[Uuid; 1]; 3]; 1],
15}
16static MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
17
18pub async fn arrays2<E: Executor>(executor: &mut E) {
19 let _ = MUTEX.lock().await;
20
21 #[cfg(not(feature = "disable-multiple-statements"))]
23 {
24 let mut query = String::new();
25 let writer = executor.driver().sql_writer();
26 writer.write_drop_table::<Container>(&mut query, true);
27 writer.write_create_table::<Container>(&mut query, true);
28 let value = Container {
29 first: [[
30 Interval::from_years(500),
31 Interval::from_micros(1) + Interval::from_months(4),
32 ]],
33 second: [[
34 [Uuid::from_str("c1412337-cfce-444a-ac46-5e6edcc0bf23").unwrap()],
35 [Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap()],
36 [Uuid::from_str("9d7f0f5b-19d6-4298-a332-214fc85e2652").unwrap()],
37 ]],
38 };
39 writer.write_insert(&mut query, &[value], false);
40 writer.write_select(
41 &mut query,
42 Container::columns(),
43 Container::table(),
44 &true,
45 Some(1),
46 );
47 let rows = pin!(executor.run(query).try_filter_map(|v| async move {
48 Ok(match v {
49 QueryResult::Row(v) => Some(v),
50 QueryResult::Affected(..) => None,
51 })
52 }));
53 let rows = rows
54 .map(|v| v.and_then(Container::from_row))
55 .try_collect::<Vec<_>>()
56 .await
57 .expect("Coult not execute the query");
58 assert_eq!(
59 rows,
60 [Container {
61 first: [[
62 Interval::from_years(500),
63 Interval::from_micros(1) + Interval::from_months(4),
64 ]],
65 second: [[
66 [Uuid::from_str("c1412337-cfce-444a-ac46-5e6edcc0bf23").unwrap()],
67 [Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap()],
68 [Uuid::from_str("9d7f0f5b-19d6-4298-a332-214fc85e2652").unwrap()],
69 ]],
70 }]
71 )
72 }
73}