Skip to content

Commit 9fbc7be

Browse files
authored
Merge pull request #31 from dhiway/feat/heatmap
bug:fix build issue by Disable compile-time SQL checking
2 parents 7d67108 + dfa4c82 commit 9fbc7be

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/db/profiles.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::models::search::Pagination;
22
use chrono::{DateTime, Utc};
33
use serde_json::Value;
4-
use sqlx::{query, Error, PgPool};
4+
use sqlx::{query, query_scalar, Error, PgPool, Row};
55
use tracing::info;
66

77
pub struct PaginatedItems {
@@ -122,14 +122,14 @@ pub async fn delete_stale_profiles(
122122
pool: &PgPool,
123123
synced_at: DateTime<Utc>,
124124
) -> Result<u64, sqlx::Error> {
125-
let result = query!(
125+
let result = query(
126126
r#"
127-
DELETE FROM profiles
128-
WHERE last_synced_at IS NOT NULL
129-
AND last_synced_at < $1
130-
"#,
131-
synced_at
127+
DELETE FROM profiles
128+
WHERE last_synced_at IS NOT NULL
129+
AND last_synced_at < $1
130+
"#,
132131
)
132+
.bind(synced_at)
133133
.execute(pool)
134134
.await?;
135135

@@ -149,18 +149,18 @@ pub async fn fetch_beckn_profile_items(
149149
);
150150

151151
// ---- total count ----
152-
let total = sqlx::query_scalar!(
152+
let total: i64 = query_scalar(
153153
r#"
154-
SELECT COUNT(*) as "count!"
154+
SELECT COUNT(*)
155155
FROM profiles
156156
WHERE beckn_structure IS NOT NULL
157-
"#
157+
"#,
158158
)
159159
.fetch_one(db_pool)
160160
.await?;
161161

162162
// ---- paginated data ----
163-
let rows = sqlx::query!(
163+
let rows = sqlx::query(
164164
r#"
165165
SELECT beckn_structure
166166
FROM profiles
@@ -169,15 +169,19 @@ pub async fn fetch_beckn_profile_items(
169169
LIMIT $1
170170
OFFSET $2
171171
"#,
172-
limit as i64,
173-
offset as i64
174172
)
173+
.bind(limit as i64)
174+
.bind(offset as i64)
175175
.fetch_all(db_pool)
176176
.await?;
177177

178178
let items = rows
179179
.into_iter()
180-
.filter_map(|r| r.beckn_structure)
180+
.filter_map(|r| {
181+
r.try_get::<Option<Value>, _>("beckn_structure")
182+
.ok()
183+
.flatten()
184+
})
181185
.collect::<Vec<_>>();
182186

183187
Ok(PaginatedItems { items, total })

0 commit comments

Comments
 (0)