This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(proc_macro_derive_resolution_fallback)] | |
pub mod handler; | |
pub mod repository; | |
use mongodb::bson; | |
#[derive(Serialize, Deserialize, Debug, Clone)] | |
pub struct Cat { | |
#[serde(rename = "_id")] // Use MongoDB's special primary key field name when serializing | |
pub id: Option<bson::oid::ObjectId>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(proc_macro_derive_resolution_fallback)] | |
use crate::cats::{Cat, InsertableCat}; | |
use crate::mongo_connection::Conn; | |
use crate::r2d2_mongodb::mongodb::db::ThreadedDatabase; | |
use mongodb::{bson, coll::results::DeleteResult, doc, error::Error, oid::ObjectId}; | |
const COLLECTION: &str = "cats"; | |
pub fn all(connection: &Conn) -> Result<Vec<Cat>, Error> { | |
let cursor = connection.collection(COLLECTION).find(None, None).unwrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use crate::cats; | |
use crate::mongo_connection::Conn; | |
use cats::Cat; | |
use mongodb::{ doc, error::Error, oid::ObjectId}; | |
use rocket_contrib::json::Json; | |
use rocket::{http::Status}; | |
fn error_status(error: Error) -> Status { | |
match error { | |
Error::CursorNotFoundError => Status::NotFound, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use dotenv::dotenv; | |
use r2d2::PooledConnection; | |
use r2d2_mongodb::{ConnectionOptions, MongodbConnectionManager}; | |
use rocket::http::Status; | |
use rocket::request::{self, FromRequest}; | |
use rocket::{Outcome, Request, State}; | |
use std::env; | |
use std::ops::Deref; | |
type Pool = r2d2::Pool<MongodbConnectionManager>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(decl_macro, proc_macro_hygiene)] | |
#[macro_use] | |
extern crate rocket; | |
extern crate dotenv; | |
extern crate mongodb; | |
extern crate r2d2; | |
extern crate r2d2_mongodb; | |
extern crate rocket_contrib; | |
#[macro_use] | |
extern crate serde_derive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://rocket.rs/v0.4/guide/testing/#local-dispatching | |
#[cfg(test)] | |
mod test { | |
use mongodb::{doc, error::Error, oid::ObjectId}; | |
use rocket::http::{ContentType, Status}; | |
use rocket::local::Client; | |
use rocket_contrib::json::Json; | |
use rustlang_rocket_mongodb::cats::Cat; | |
use rustlang_rocket_mongodb::rocket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(proc_macro_hygiene, decl_macro)] | |
#[macro_use] extern crate rocket; | |
#[get("/")] | |
fn index() -> &'static str { | |
let coll = client.db("media").collection("movies"); | |
coll.insert_one(doc!{ "title": "Back to the Future" }, None).unwrap(); | |
coll.update_one(doc!{}, doc!{ "director": "Robert Zemeckis" }, None).unwrap(); | |
coll.delete_many(doc!{}, None).unwrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "myList", | |
"type": [ | |
"array", | |
{ | |
"count": ";", | |
"type": [ | |
"container", | |
[ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
python3 -m venv .my_super_env && # Yeah random name to avoid erasing local virtualenv | |
source .my_super_env/bin/activate && | |
pip install -q pyyaml && | |
python3 -c "import yaml, json, sys | |
sys.stdout.write(yaml.dump(json.load(sys.stdin)))" \ | |
< $1 > $2 || true | |
# Remove the temporary venv in any case | |
rm -rf .my_super_env || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER_NAME=my-awesome-container | |
PORT=1337 | |
while [ ! "$(docker exec -t -i $CONTAINER_NAME curl --write-out %{http_code} --silent --output /dev/null localhost:$PORT)" = "-ne 200" ] ; do | |
echo "Waiting for port $PORT to be opened ..." | |
sleep 20 | |
done |