|
1 | 1 | use crate::error::Result;
|
2 |
| -#[cfg(any(feature = "postgres", feature = "sqlite"))] |
| 2 | +#[cfg(any(feature = "postgres", feature = "sqlite", feature = "mysql"))] |
3 | 3 | use crate::error::WundergraphError;
|
4 |
| -#[cfg(any(feature = "postgres", feature = "sqlite"))] |
| 4 | +#[cfg(any(feature = "postgres", feature = "sqlite", feature = "mysql"))] |
5 | 5 | use crate::juniper_ext::FromLookAheadValue;
|
6 | 6 | use crate::query_builder::selection::{BoxedQuery, LoadingHandler};
|
7 | 7 | use crate::scalar::WundergraphScalarValue;
|
8 | 8 | use diesel::backend::Backend;
|
9 |
| -#[cfg(feature = "sqlite")] |
| 9 | +#[cfg(any(feature = "sqlite", feature = "mysql"))] |
10 | 10 | use diesel::query_dsl::methods::LimitDsl;
|
11 |
| -#[cfg(any(feature = "postgres", feature = "sqlite"))] |
| 11 | +#[cfg(any(feature = "postgres", feature = "sqlite", feature = "mysql"))] |
12 | 12 | use diesel::query_dsl::methods::OffsetDsl;
|
| 13 | + |
13 | 14 | use juniper::LookAheadSelection;
|
14 | 15 |
|
15 | 16 | /// A trait abstracting over the different behaviour of limit/offset
|
@@ -72,3 +73,30 @@ impl ApplyOffset for diesel::sqlite::Sqlite {
|
72 | 73 | }
|
73 | 74 | }
|
74 | 75 | }
|
| 76 | + |
| 77 | +#[cfg(feature = "mysql")] |
| 78 | +impl ApplyOffset for diesel::mysql::Mysql { |
| 79 | + fn apply_offset<'a, L, Ctx>( |
| 80 | + query: BoxedQuery<'a, L, Self, Ctx>, |
| 81 | + select: &LookAheadSelection<'_, WundergraphScalarValue>, |
| 82 | + ) -> Result<BoxedQuery<'a, L, Self, Ctx>> |
| 83 | + where |
| 84 | + L: LoadingHandler<Self, Ctx>, |
| 85 | + { |
| 86 | + use juniper::LookAheadMethods; |
| 87 | + if let Some(offset) = select.argument("offset") { |
| 88 | + let q = <_ as OffsetDsl>::offset( |
| 89 | + query, |
| 90 | + i64::from_look_ahead(offset.value()) |
| 91 | + .ok_or(WundergraphError::CouldNotBuildFilterArgument)?, |
| 92 | + ); |
| 93 | + if select.argument("limit").is_some() { |
| 94 | + Ok(q) |
| 95 | + } else { |
| 96 | + Ok(<_ as LimitDsl>::limit(q, std::i64::MAX)) |
| 97 | + } |
| 98 | + } else { |
| 99 | + Ok(query) |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments