Skip to content

Commit

Permalink
style: improve naming to prevent module name repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonribble committed Sep 27, 2024
1 parent ac95875 commit 07fe348
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/db/contact_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub trait ContactRepo {
async fn get_by_id(&self, id: i64) -> anyhow::Result<models::IndexedContact>;
}

pub struct SqliteContactRepo {
pub struct Connection {
sqlite_pool: Arc<SqlitePool>,
}

impl SqliteContactRepo {
impl Connection {
pub fn new(pool: SqlitePool) -> Self {
Self {
sqlite_pool: Arc::new(pool),
Expand All @@ -26,7 +26,7 @@ impl SqliteContactRepo {
}

#[async_trait]
impl ContactRepo for SqliteContactRepo {
impl ContactRepo for Connection {
async fn create(&self, contact: models::Contact) -> anyhow::Result<i64> {
let query = "INSERT INTO contacts
(first_name, last_name, display_name, email, phone_number)
Expand Down
16 changes: 8 additions & 8 deletions src/db/metadata_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub trait MetadataRepo {
async fn create(&self, metadata: models::Metadata) -> anyhow::Result<i64>;
}

pub struct SqliteMetadataRepo {
pub struct DbPool {
sqlite_pool: Arc<SqlitePool>,
}

impl SqliteMetadataRepo {
impl DbPool {
pub fn new(pool: SqlitePool) -> Self {
Self {
sqlite_pool: Arc::new(pool),
Expand All @@ -24,7 +24,7 @@ impl SqliteMetadataRepo {
}

#[async_trait]
impl MetadataRepo for SqliteMetadataRepo {
impl MetadataRepo for DbPool {
async fn create(&self, metadata: models::Metadata) -> anyhow::Result<i64> {
let query = "INSERT INTO contact_metadata
(contact_id,
Expand All @@ -39,10 +39,10 @@ impl MetadataRepo for SqliteMetadataRepo {
VALUES (?,?,?,?,?,?,?,?,?)";

let result = sqlx::query(query)
.bind(&metadata.contact_id)
.bind(&metadata.starred)
.bind(&metadata.is_archived)
.bind(&metadata.frequency)
.bind(metadata.contact_id)
.bind(metadata.starred)
.bind(metadata.is_archived)
.bind(metadata.frequency)

.bind(metadata.created_at.to_rfc3339_opts(SecondsFormat::Millis, true))
.bind(metadata.updated_at.to_rfc3339_opts(SecondsFormat::Millis, true))
Expand Down Expand Up @@ -93,7 +93,7 @@ mod tests {
#[tokio::test]
async fn test_create_metadata_sqlite() {
let pool = setup_test_db().await;
let repo = SqliteMetadataRepo::new(pool);
let repo = DbPool::new(pool);

let test_metadata = models::Metadata::default();

Expand Down
2 changes: 1 addition & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod contact_repo;
mod metadata_repo;

pub use contact_repo::ContactRepo;
pub use contact_repo::SqliteContactRepo;
pub use contact_repo::Connection;
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod utils;

use clap::Parser;
use commander::{Cli, Commands};
use db::{ContactRepo, SqliteContactRepo};
use db::{ContactRepo, Connection};
use models::{Contact, ContactBuilder};
use sqlx::SqlitePool;

Expand All @@ -18,7 +18,7 @@ async fn main() -> anyhow::Result<()> {

let pool = SqlitePool::connect(&env::var("DATABASE_URL")?).await?;

let contact_repo = SqliteContactRepo::new(pool);
let contact_repo = Connection::new(pool);

let cli = Cli::parse();

Expand Down

0 comments on commit 07fe348

Please sign in to comment.