Giter Site home page Giter Site logo

avocado's Introduction

Avocado, the strongly-typed MongoDB driver

Avocado on crates.io Avocado on docs.rs rustc Avocado Download Avocado License Lines of Code Twitter

goto counter unsafe counter fuck counter

Usage

  • See the online documentation above, or open it locally:

  • cargo doc --open

  • Check out the examples/ folder

  • More high-level information can be found on the project page.

  • The schema_validation feature can be enabled (it's enabled by default), in which case the DatabaseExt::empty_collection() method becomes available. If a collection is created using this method, it will add a JSON schema validation pass and specify the schema as generated by magnet.

  • The raw_uuid feature (also enabled by default) adds some useful extension methods to make it more convenient to work with UUIDs as the type of the _id field.

    This can potentially be slow if you are performing many insertions into a collection of a complex type. However, it dynamically ensures that other users/drivers can't put malformed data in the collection. Therefore it's probably more useful if you or somebody else are accessing a database from outside the Avocado driver too. It's also great for debugging Avocado itself.

Changelog

v0.6.0

  • Fix #6 by adding a context dictionary to Error.

v0.5.0

  • Fix #5 by adding an #[options(...)] attribute to the Doc derive proc-macro.

v0.4.0

  • Fix #2 by adding a &self parameter to the options() methods on ops:: traits.

v0.3.3

  • Fix a deprecation warning related to Uuid::from_random_bytes()
  • Catch some errors that incorrectly pass through the MongoDB client's Cursor API

v0.3.2

  • Added a remove_inner_doc() method to DocumentExt. This allows for the easy chaining of removal from hierarchically contained Documents in transform().
  • Fixed a bug where inserting 0 entities into a collection failed.
  • Fixed the incorrect ordering of the key and the value type in the error message generated by DocumentExt::remove_*() methods.

v0.3.1

  • Added a DocumentExt trait to the prelude for convenient and idiomatic implementation of transform(raw: Document) -> Result<Bson> methods
  • Hopefully fixed the code so that docs.rs can handle it now

v0.3.0

  • Added Doc::id() and Doc::set_id() methods for the sake of better efficiency in some Collection methods
    • This means that single-element wrappers such as Box<Doc> and RefCell<Doc> can no longer implement Doc themselves
  • Added Collection::find_one_and_delete(), Collection::find_one_and_replace(), and Collection::find_one_and_update() methods
  • Added more documentation and clarified/improved existing docs
  • Added more tests, including compile-time tests for cases when #[derive(Doc)] should fail, as well as testing that an optional _id is correctly allowed

Compile-time testing the derive macro

Due to a bug in compiletest_rs, running the tests that check the error messages of the #[derive(Doc)] proc-macro requires running cargo clean first, otherwise compilation will fail with E0464.

Therefore, the recommended way of running the tests is:

cargo clean && cargo test

TODO:

  • Add weights property to text indices
  • Add migrations
  • Default Doc::Id to ObjectId and Query::Output and FindAndUpdate::Output to T, once #29661 is stabilized

avocado'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  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

Forkers

figments flitbit

avocado's Issues

How to upsert

Hello, the crate is amazing but the docs are missing somewhere.
For example, I have a vector of struct which implements Doc. Now I want to upsert_many: insert if does not exist and update content if exists.
Should I really need to create another struct-operation, implement Upsert trait for it and use it for this operation? Maybe there is a simple way for this?

No info about inserted_ids on insert_many when there were some exceptions

Hey ho! :)
It works, but now we don't have info about inserted_ids when ordered = false.

avocado/avocado/src/coll.rs

Lines 149 to 157 in e430353

self.inner
.insert_many(docs, options.into())
.chain(&message)
.and_then(|result| {
if let Some(error) = result.bulk_write_exception {
Err(Error::with_cause(message(), error))
} else if let Some(ids) = result.inserted_ids {
let ids = ids
.into_iter()

So you check result and if there were bulk error, drop the request as failed. But InsertManyResult also contains info about inserted ids:

pub struct InsertManyResult {
    pub acknowledged: bool,
    pub inserted_ids: Option<BTreeMap<i64, Bson>>,
    pub bulk_write_exception: Option<BulkWriteException>,
}

And I can't understand in code that transaction is okay and how many rows were anyway inserted because of ordered = false.

I'm not sure what's the correct way to handle such situation. Maybe when ordered=false in insert many, don't return Err if result was BulkWriteException and mark it always as success?

Statically typed filters?

Is it possible to write statically typed filters? (e.g. similar to what diesel has or something else), and if not, is there any plans for them?

Something like:

#[derive(Debug, Serialize, Deserialize, Doc, Clone)]
pub struct Example {
	#[serde(rename = "_id")]
	pub id: Uid<Example>,
	pub description: String,
}

...

let example_col: Collection<Example>  = shared.db.existing_collection();
let res: Example = example_col.find_one(Example::description.eq("abc"));

SSL?

There doesn't seem to be a feature or any documentation for SSL connections. Is that by design or does SSL just work if you need to use it?

Counters in the README are slightly off?

The "fuck counter" and the "goto counter" (does that one even make sense in Rust?) both show 1, but the only result is their entry in the README...
And the "unsafe counter" shows three, but the results are (again) the counter in the README, and then the #![deny(...)] entries which should make it impossible to have unsafe code...

I don't know if this is intentional, but it sounds like the counters don't really make sense. Just wanted to let you know :)

Doc for generic struct

Hi! Thanks again for amazing wrapper :)
I found, that it's not possible to derive Doc for generic structure:

> message: `Doc` can't be derived for a type that is generic over type parameters

#[derive(Doc, Serialize, Deserialize)]
pub struct Test<T: Serialize + Deserialize> {
   pub data<T>
}

We specify Output type for queries, maybe we also can specify somehow exact types for deserialization?

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.