Skip to content

Commit

Permalink
Fix from / to query
Browse files Browse the repository at this point in the history
  • Loading branch information
erikreppel committed Apr 26, 2024
1 parent 466f4d2 commit bf02e3f
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::config::Config;
use crate::premints::zora_premint_v2::types::ZoraPremintV2;
use crate::types::{InclusionClaim, Premint, PremintName, PremintTypes};
use alloy_primitives::Address;
use async_trait::async_trait;
use chrono::Utc;
use eyre::WrapErr;
use serde::Deserialize;
use sqlx::sqlite::SqliteConnectOptions;
Expand Down Expand Up @@ -308,11 +310,11 @@ fn build_query(options: &QueryOptions) -> QueryBuilder<Sqlite> {
}
if let Some(from) = options.from {
query_build.push(" AND created_at >= ");
query_build.push_bind(from);
query_build.push_bind(from.to_string());
}
if let Some(to) = options.to {
query_build.push(" AND created_at <= ");
query_build.push_bind(to);
query_build.push_bind(to.to_string());
}

query_build
Expand All @@ -321,8 +323,9 @@ fn build_query(options: &QueryOptions) -> QueryBuilder<Sqlite> {
#[cfg(test)]
mod test {
use alloy_primitives::Address;
use chrono::Utc;
use chrono::{Duration, Utc};
use sqlx::Row;
use std::ops::Sub;

use crate::config::Config;
use crate::premints::zora_premint_v2::types::ZoraPremintV2;
Expand Down Expand Up @@ -452,6 +455,25 @@ mod test {
.await
.unwrap();
assert_eq!(vec![premint_simple.clone()], all);

let to = chrono::Utc::now();

let from = to.sub(Duration::seconds(10));

let all = list_all_with_options(
&store.db,
&QueryOptions {
chain_id: None,
kind: Some("simple".to_string()),
collection_address: None,
creator_address: None,
from: Some(from),
to: Some(to),
},
)
.await
.unwrap();
assert_eq!(vec![premint_simple.clone()], all);
}

#[tokio::test]
Expand Down

0 comments on commit bf02e3f

Please sign in to comment.