0.7.27 +Refactor
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
// file: kb_lib/src/db/queries/pool_origin.rs
|
||||
|
||||
//! Queries for `kb_pool_origins`.
|
||||
//! Queries for `k_sol_pool_origins`.
|
||||
|
||||
/// Inserts or updates one pool-origin row and returns its stable internal id.
|
||||
pub async fn upsert_pool_origin(
|
||||
database: &crate::KbDatabase,
|
||||
dto: &crate::KbPoolOriginDto,
|
||||
) -> Result<i64, crate::KbError> {
|
||||
pub async fn query_pool_origins_upsert(
|
||||
database: &crate::Database,
|
||||
dto: &crate::PoolOriginDto,
|
||||
) -> Result<i64, crate::Error> {
|
||||
match database.connection() {
|
||||
crate::KbDatabaseConnection::Sqlite(pool) => {
|
||||
crate::DatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query(
|
||||
r#"
|
||||
INSERT INTO kb_pool_origins (
|
||||
INSERT INTO k_sol_pool_origins (
|
||||
dex_id,
|
||||
pool_id,
|
||||
pair_id,
|
||||
@@ -29,9 +29,9 @@ INSERT INTO kb_pool_origins (
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(pool_id) DO UPDATE SET
|
||||
pair_id = COALESCE(kb_pool_origins.pair_id, excluded.pair_id),
|
||||
pool_listing_id = COALESCE(kb_pool_origins.pool_listing_id, excluded.pool_listing_id),
|
||||
launch_attribution_id = COALESCE(kb_pool_origins.launch_attribution_id, excluded.launch_attribution_id),
|
||||
pair_id = COALESCE(k_sol_pool_origins.pair_id, excluded.pair_id),
|
||||
pool_listing_id = COALESCE(k_sol_pool_origins.pool_listing_id, excluded.pool_listing_id),
|
||||
launch_attribution_id = COALESCE(k_sol_pool_origins.launch_attribution_id, excluded.launch_attribution_id),
|
||||
updated_at = excluded.updated_at
|
||||
"#,
|
||||
)
|
||||
@@ -52,15 +52,15 @@ ON CONFLICT(pool_id) DO UPDATE SET
|
||||
.execute(pool)
|
||||
.await;
|
||||
if let Err(error) = query_result {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot upsert kb_pool_origins on sqlite: {}",
|
||||
return Err(crate::Error::Db(format!(
|
||||
"cannot upsert k_sol_pool_origins on sqlite: {}",
|
||||
error
|
||||
)));
|
||||
}
|
||||
let id_result = sqlx::query_scalar::<sqlx::Sqlite, i64>(
|
||||
r#"
|
||||
SELECT id
|
||||
FROM kb_pool_origins
|
||||
FROM k_sol_pool_origins
|
||||
WHERE pool_id = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
@@ -71,8 +71,8 @@ LIMIT 1
|
||||
match id_result {
|
||||
Ok(id) => return Ok(id),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot fetch kb_pool_origins id for pool_id '{}' on sqlite: {}",
|
||||
return Err(crate::Error::Db(format!(
|
||||
"cannot fetch k_sol_pool_origins id for pool_id '{}' on sqlite: {}",
|
||||
dto.pool_id, error
|
||||
)));
|
||||
},
|
||||
@@ -82,13 +82,13 @@ LIMIT 1
|
||||
}
|
||||
|
||||
/// Returns one pool-origin row identified by its pool id, if it exists.
|
||||
pub async fn get_pool_origin_by_pool_id(
|
||||
database: &crate::KbDatabase,
|
||||
pub async fn query_pool_origins_get_by_pool_id(
|
||||
database: &crate::Database,
|
||||
pool_id: i64,
|
||||
) -> Result<std::option::Option<crate::KbPoolOriginDto>, crate::KbError> {
|
||||
) -> Result<std::option::Option<crate::PoolOriginDto>, crate::Error> {
|
||||
match database.connection() {
|
||||
crate::KbDatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query_as::<sqlx::Sqlite, crate::KbPoolOriginEntity>(
|
||||
crate::DatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query_as::<sqlx::Sqlite, crate::PoolOriginEntity>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
@@ -106,7 +106,7 @@ SELECT
|
||||
launch_attribution_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM kb_pool_origins
|
||||
FROM k_sol_pool_origins
|
||||
WHERE pool_id = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
@@ -117,14 +117,14 @@ LIMIT 1
|
||||
let entity_option = match query_result {
|
||||
Ok(entity_option) => entity_option,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot read kb_pool_origins by pool_id '{}' on sqlite: {}",
|
||||
return Err(crate::Error::Db(format!(
|
||||
"cannot read k_sol_pool_origins by pool_id '{}' on sqlite: {}",
|
||||
pool_id, error
|
||||
)));
|
||||
},
|
||||
};
|
||||
match entity_option {
|
||||
Some(entity) => return crate::KbPoolOriginDto::try_from(entity).map(Some),
|
||||
Some(entity) => return crate::PoolOriginDto::try_from(entity).map(Some),
|
||||
None => return Ok(None),
|
||||
}
|
||||
},
|
||||
@@ -132,12 +132,12 @@ LIMIT 1
|
||||
}
|
||||
|
||||
/// Lists all pool-origin rows ordered by creation time then id.
|
||||
pub async fn list_pool_origins(
|
||||
database: &crate::KbDatabase,
|
||||
) -> Result<std::vec::Vec<crate::KbPoolOriginDto>, crate::KbError> {
|
||||
pub async fn query_pool_origins_list(
|
||||
database: &crate::Database,
|
||||
) -> Result<std::vec::Vec<crate::PoolOriginDto>, crate::Error> {
|
||||
match database.connection() {
|
||||
crate::KbDatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query_as::<sqlx::Sqlite, crate::KbPoolOriginEntity>(
|
||||
crate::DatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query_as::<sqlx::Sqlite, crate::PoolOriginEntity>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
@@ -155,7 +155,7 @@ SELECT
|
||||
launch_attribution_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM kb_pool_origins
|
||||
FROM k_sol_pool_origins
|
||||
ORDER BY created_at ASC, id ASC
|
||||
"#,
|
||||
)
|
||||
@@ -164,15 +164,15 @@ ORDER BY created_at ASC, id ASC
|
||||
let entities = match query_result {
|
||||
Ok(entities) => entities,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot list kb_pool_origins on sqlite: {}",
|
||||
return Err(crate::Error::Db(format!(
|
||||
"cannot list k_sol_pool_origins on sqlite: {}",
|
||||
error
|
||||
)));
|
||||
},
|
||||
};
|
||||
let mut dtos = std::vec::Vec::new();
|
||||
for entity in entities {
|
||||
let dto_result = crate::KbPoolOriginDto::try_from(entity);
|
||||
let dto_result = crate::PoolOriginDto::try_from(entity);
|
||||
let dto = match dto_result {
|
||||
Ok(dto) => dto,
|
||||
Err(error) => return Err(error),
|
||||
|
||||
Reference in New Issue
Block a user