Skip to content

Commit

Permalink
refactor: cleanup/rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
pjenvey committed Aug 19, 2020
1 parent c11b3af commit ce905cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
39 changes: 19 additions & 20 deletions src/db/spanner/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,46 @@ use std::{
sync::Arc,
};

use bb8::PooledConnection;
use futures::future::TryFutureExt;
use googleapis_raw::spanner::v1::transaction::{
self, TransactionOptions, TransactionOptions_ReadOnly, TransactionOptions_ReadWrite,
};
use googleapis_raw::spanner::v1::{
mutation::{Mutation, Mutation_Write},
spanner::{BeginTransactionRequest, CommitRequest, ExecuteSqlRequest, RollbackRequest},
transaction::{
TransactionOptions, TransactionOptions_ReadOnly, TransactionOptions_ReadWrite,
TransactionSelector,
},
type_pb::TypeCode,
};
#[allow(unused_imports)]
use protobuf::{well_known_types::ListValue, Message, RepeatedField};

use super::manager::{SpannerConnectionManager, SpannerSession};
use super::pool::CollectionCache;

use crate::db::{
error::{DbError, DbErrorKind},
params, results,
spanner::support::{as_type, StreamedResultSetAsync},
util::SyncTimestamp,
Db, DbFuture, Sorting, FIRST_CUSTOM_COLLECTION_ID,
use crate::{
db::{
error::{DbError, DbErrorKind},
params, results,
util::SyncTimestamp,
Db, DbFuture, Sorting, FIRST_CUSTOM_COLLECTION_ID,
},
server::metrics::Metrics,
web::extractors::{BsoQueryParams, HawkIdentifier, Offset},
};
use crate::server::metrics::Metrics;
use crate::web::extractors::{BsoQueryParams, HawkIdentifier, Offset};

use super::support::{bso_to_insert_row, bso_to_update_row};
use super::{
batch,
support::{as_list_value, as_value, bso_from_row, ExecuteSqlRequestBuilder},
pool::{CollectionCache, Conn},
support::{
as_list_value, as_type, as_value, bso_from_row, ExecuteSqlRequestBuilder,
StreamedResultSetAsync,
},
support::{bso_to_insert_row, bso_to_update_row},
};

pub type TransactionSelector = transaction::TransactionSelector;

#[derive(Debug, Eq, PartialEq)]
pub enum CollectionLock {
Read,
Write,
}

pub(super) type Conn<'a> = PooledConnection<'a, SpannerConnectionManager<SpannerSession>>;
pub type Result<T> = std::result::Result<T, DbError>;

/// The ttl to use for rows that are never supposed to expire (in seconds)
Expand Down
4 changes: 3 additions & 1 deletion src/db/spanner/pool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use bb8::Pool;
use bb8::{Pool, PooledConnection};

use std::{
collections::HashMap,
Expand All @@ -16,6 +16,8 @@ use super::manager::{SpannerConnectionManager, SpannerSession};
use super::models::SpannerDb;
use crate::error::ApiResult;

pub(super) type Conn<'a> = PooledConnection<'a, SpannerConnectionManager<SpannerSession>>;

embed_migrations!();

/// Run the diesel embedded migrations
Expand Down
10 changes: 6 additions & 4 deletions src/db/spanner/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ use protobuf::{
RepeatedField,
};

use super::models::{Conn, Result};
use crate::db::{results, util::SyncTimestamp, DbError, DbErrorKind};

use crate::{
db::{params, spanner::models::DEFAULT_BSO_TTL, util::to_rfc3339},
db::{
params, results, spanner::models::DEFAULT_BSO_TTL, util::to_rfc3339, util::SyncTimestamp,
DbError, DbErrorKind,
},
web::extractors::HawkIdentifier,
};

use super::{models::Result, pool::Conn};

pub fn as_value(string_value: String) -> Value {
let mut value = Value::new();
value.set_string_value(string_value);
Expand Down

0 comments on commit ce905cf

Please sign in to comment.