Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subqueries to Delete #145

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Add Subqueries to Delete #145

merged 1 commit into from
Oct 9, 2024

Conversation

chaseWillden
Copy link
Collaborator

This does add a little complexity. I'm not sure the other way to implement this gracefully though.

Delete without a subquery, using just the literals:

match conn {
    Ok(ref c) => {
        let condition = Condition::Eq(
            "address".to_string(),
            Value::Literal("Some Random Address 1".to_string()),
        );

        let result = sqlite::delete(c)
            .from(User::default())
            .where_clause(condition)
            .order_by(order)
            .limit(20)
            .offset(0)
            .build();
        println!("{:?}", result);
        assert!(result.is_ok());
    }
    Err(e) => {
        panic!("Failed to DELETE: {:?}", e);
    }
}

Delete with subquery:

match conn {
    Ok(ref c) => {
        let sub_query =
            SelectQueryBuilder::new(c, vec![Column::<User>::Text("username".to_string())])
                .where_clause(Condition::Eq(
                    "id".to_string(),
                    Value::Literal(1.to_string()),
                ))
                .limit(1);

        let condition =
            Condition::Eq("address".to_string(), Value::Subquery(Box::new(sub_query)));

        let result = sqlite::delete(c)
            .from(User::default())
            .where_clause(condition)
            .build();
        println!("{:?}", result);
        assert!(result.is_ok());
    }
    Err(e) => {
        panic!("Failed to DELETE: {:?}", e);
    }
}

Copy link

vercel bot commented Oct 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
njord ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 3:48am

@mjovanc
Copy link
Member

mjovanc commented Oct 9, 2024

LGTM. Thanks Chase!

@mjovanc mjovanc merged commit da76c03 into master Oct 9, 2024
3 checks passed
@mjovanc mjovanc deleted the 64_delete_subquery branch October 9, 2024 07:45
mjovanc added a commit that referenced this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants