Giter Club home page Giter Club logo

couch-rs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

couch-rs's Issues

Consider way to differentiate errors

It's not easy to tell if a CouchError originated from something like a failure to Deserialize or some other cause. This is because CouchError is a struct rather than an enum and multiple items all get the same status:

impl std::convert::From<reqwest::Error> for CouchError {
fn from(err: reqwest::Error) -> Self {
CouchError {
id: None,
status: err.status().unwrap_or(reqwest::StatusCode::NOT_IMPLEMENTED),
message: err.to_string(),
}
}
}
impl std::convert::From<serde_json::Error> for CouchError {
fn from(err: serde_json::Error) -> Self {
CouchError {
id: None,
status: reqwest::StatusCode::NOT_IMPLEMENTED,
message: err.to_string(),
}
}
}
impl std::convert::From<url::ParseError> for CouchError {
fn from(err: url::ParseError) -> Self {
CouchError {
id: None,
status: reqwest::StatusCode::NOT_IMPLEMENTED,
message: err.to_string(),
}
}
}

Consider making CouchError an enum so downstream consumers can match over the Error types and not have to resort to string matching on message.

querying changes stream from npm regsitry reports error

https://replicate.npmjs.com exposes couchdb's _changes api. when using this library to query it, it reports error

CouchError { id: None, status: 501, message: "data did not match any variant of untagged enum Event" }

The code is

use anyhow::Result;
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() -> Result<()> {
    let client = couch_rs::Client::new_no_auth("https://replicate.npmjs.com")?;
    let db = client.db("").await?;
    let mut changes = db.changes(None);
    changes.set_infinite(true);
    let mut events = vec![];
    while let Some(change) = changes.next().await {
        match change {
            Ok(c) => {
                events.push(c);
                if events.len() == 10 {
                    break;
                }
            }
            Err(e) => println!("error: {:?}", e),
        }
    }
    println!("{:?}", &events);
    Ok(())
}

Upgrade to rust 2021 causing compatibility issues.

error: failed to parse manifest at /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/couch_rs-0.8.33/Cargo.toml

Caused by:
feature edition2021 is required

this Cargo does not support nightly features, but if you
switch to nightly channel you can add
cargo-features = ["edition2021"] to enable this feature

This is causing a big problem for me because I'm trying to stay on rust 1.53 due to some other linker problem. I can't build new versions of my webserver now, until I can figure out how to upgrade to 1.56 and edition 2021.

It seems like any include of couch_rs 0.8.32 is still pulling the 0.8.33 version.

I wish you would have made this last release version 0.9 to make this upgrade easy for me.

Optional underlying web framework support

couch-rs currently uses reqwest and hyper for its underlying web framework. In the case of an application that uses the actix stack as its web framework, this adds close to 100 dependencies and offers significant bloat to the executable (and, incidentally, about 2-3 minutes of build time with Github actions runners)

This package should optionally use the reqwest/hyper stack or the actix stack as its underlying framework.

Description of `database::Database::insert_index` is not accurate

The docs for insert_index says:

Inserts an index in a naive way, if it already exists, will throw an Err

This is not accurate. When an index already exists, the DesignCreated::results field will be "exists" and no error will be thrown. Because of this behavior, the ensure_index method on Database doesn't really have any purpose.

In my mind, the primary purpose of a method like ensure_index is to run in a 'migration' job before an application depending on couch_rs is launched. A method like this would ensure that the database in question has the indexes that are expected by the application code.

I propose the following changes:

  • Update the docs for insert_index to reflect its actual behavior.
  • Add a doctest that will validate this behavior
  • Update the arguments to insert_index to match the types::index::Index struct, to make it more compatible with the get_indexes method.
  • Create an enum for the IndexType as defined in the CouchDB docs
  • Make a new ensure_index function that will take a vector of Index and either validate that they exist in the database or create them.

Proposed functionality for testing

I made a crate to help test couch_rs.

Docs: https://docs.rs/couch_rs_test/0.2.0/couch_rs_test/
GitHub: https://github.com/kingledion/couch_rs_test

The way it works is this. You send the same arguments to the TestRepo::new method that you would to set up a couch_rs Client and Database. TestRepo will create a database with the same name as your database except appending a random string; dbname-ab13958cf or something like that. It also implements Drop to ensure that the database is destroyed in your CouchDB instance when TestRepo is de-allocated. This way, you can create multiple test databases instances in parallel to prevent collisions during testing, and clean them all up for parallel integration testing.

Not sure if you are interested in incorporating this into the repository here, the way couch_rs_derive is or not. If so, I'd be happy to open a PR and merge it in.

Add a delete index function

Add a delete index function that will call DELETE on _index.

This functionality will be required for a CouchDB "migration tool" that will allow programmatic control of indices from rust code.

bulk_upsert 500 error

bulk_upsert does crash constantly with new data sent. Resulting in a 500 message "Response does not match request". Looping through the slice with the normal upsert function works just fine. Also, updating existing data works smoothly with the bulk_upsert function.

Client.exists method returns true without existing database

Hi!

Thank you for great job with this crate! It's really helpful & I'm intensively using it in the production.

I've observed that method exists returns true even if database does not exists.

I'm attaching the screenshot from the debugger. As you see - somewhere deep inside http::status::StatusCode is 404, but method returns true.
debug_failing_exists

Remove function signature does not match other functions

The remove function signature:

pub async fn remove<T: TypedCouchDocument>(&self, doc: &T) -> bool

does not return a Result like the function signatures for other 'CRUD' operations create, save and upsert.

Remove should be changed (or possibly deprecated and replaced with a new 'delete') to return a CouchResult so that any errors as well as the http status for the db call call can be returned.

Add support for partitioned databases

Hi,

I see CouchDB 3.0 implemented partitioned databases which helps with earlier implementation pattern of using types in documents for supporting segregation. Was looking to use the lib for a project with partitioned databases, but didn't find it supported. Please correct if I missed the support already present or if there is a roadmap for that to be upstreamed soon.

If it hasn't yet been worked on, would you be willing to accept contributions around partitioned databases? (Although it should mostly be minor toying around with URLs)

Recommended practices for passing around Database objects and CouchResults

Hi all,
When creating a db object through client.db() method, I'm overflowing stack quite frequently when calling from tokio workers. Is this expected (as in Database is a heavy object) and I should be using a Box ? I was theorizing that all couch-rs objects will be small in size as its just a http client to the couch.

Let me know what would be the recommended practice in this case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.