You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-23 11:02:35 +03:00
WIP: use sea-query for dynamic paginated queries
This commit is contained in:
49
crates/storage-pg/src/sea_query_sqlx.rs
Normal file
49
crates/storage-pg/src/sea_query_sqlx.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2021-2023 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sea_query::Value;
|
||||
use sqlx::Arguments;
|
||||
|
||||
pub(crate) fn map_values(values: sea_query::Values) -> sqlx::postgres::PgArguments {
|
||||
let mut arguments = sqlx::postgres::PgArguments::default();
|
||||
|
||||
for value in values {
|
||||
match value {
|
||||
Value::Bool(b) => arguments.add(b),
|
||||
Value::TinyInt(i) => arguments.add(i),
|
||||
Value::SmallInt(i) => arguments.add(i),
|
||||
Value::Int(i) => arguments.add(i),
|
||||
Value::BigInt(i) => arguments.add(i),
|
||||
Value::TinyUnsigned(u) => arguments.add(u.map(|u| u as i16)),
|
||||
Value::SmallUnsigned(u) => arguments.add(u.map(|u| u as i32)),
|
||||
Value::Unsigned(u) => arguments.add(u.map(|u| u as i64)),
|
||||
Value::BigUnsigned(u) => arguments.add(u.map(|u| i64::try_from(u).unwrap_or(i64::MAX))),
|
||||
Value::Float(f) => arguments.add(f),
|
||||
Value::Double(d) => arguments.add(d),
|
||||
Value::String(s) => arguments.add(s.as_deref()),
|
||||
Value::Char(c) => arguments.add(c.map(|c| c.to_string())),
|
||||
Value::Bytes(b) => arguments.add(b.as_deref()),
|
||||
Value::ChronoDate(d) => arguments.add(d.as_deref()),
|
||||
Value::ChronoTime(t) => arguments.add(t.as_deref()),
|
||||
Value::ChronoDateTime(dt) => arguments.add(dt.as_deref()),
|
||||
Value::ChronoDateTimeUtc(dt) => arguments.add(dt.as_deref()),
|
||||
Value::ChronoDateTimeLocal(dt) => arguments.add(dt.as_deref()),
|
||||
Value::ChronoDateTimeWithTimeZone(dt) => arguments.add(dt.as_deref()),
|
||||
Value::Uuid(u) => arguments.add(u.as_deref()),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
arguments
|
||||
}
|
||||
Reference in New Issue
Block a user