[][src]Crate ledb_actix

LEDB Storage actor and REST interface

An implementation of storage actor for Actix.

NOTE: Use features = ["web"] to enable an optional scoped REST-interface for actix-web.

Storage actor

Usage example:

use std::env;

use serde::{Deserialize, Serialize};
use serde_json::json;

use ledb_actix::{query, Document, Options, Primary, Storage, StorageAddrExt};
use log::info;
use serde_json::from_value;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Document)]
struct BlogPost {
    #[document(primary)]
    pub id: Option<Primary>,
    pub title: String,
    pub tags: Vec<String>,
    pub content: String,
}

#[actix_rt::main]
async fn main() {
    env::set_var("RUST_LOG", "info");
    pretty_env_logger::init();

    let _ = std::fs::remove_dir_all("example_db");

    let addr = Storage::new("example_db", Options::default())
        .unwrap()
        .start(1);

    let id = addr
        .send_query(query!(
            insert into blog {
                "title": "Absurd",
                "tags": ["absurd", "psychology"],
                "content": "Still nothing..."
            }
        ))
        .await
        .unwrap();

    info!("Inserted document id: {}", id);
    assert_eq!(id, 1);

    let id = addr.send_query(query!(
        insert into blog {
            "title": "Lorem ipsum",
            "tags": ["lorem", "ipsum"],
            "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        }
    )).await.unwrap();

    info!("Inserted document id: {}", id);
    assert_eq!(id, 2);

    addr.send_query(query!(
        index for blog tags string
    ))
    .await
    .unwrap();

    info!("Indexing is ok");

    let mut docs = addr
        .send_query(query!(
            find BlogPost in blog
            where tags == "psychology"
                order asc
        ))
        .await
        .unwrap();

    info!("Number of found documents: {}", docs.size_hint().0);

    assert_eq!(docs.size_hint(), (1, Some(1)));

    let doc = docs.next().unwrap().unwrap();

    info!("Found document: {:?}", doc);

    let doc_data: BlogPost = from_value(json!({
        "id": 1,
        "title": "Absurd",
        "tags": ["absurd", "psychology"],
        "content": "Still nothing..."
    }))
    .unwrap();

    assert_eq!(&doc, &doc_data);
    assert!(docs.next().is_none());
}

REST-interface

LEDB HTTP interface 0.1.0

Storage API

get database info

GET /info

get database statistics

GET /stats

Collection API

get list of collections

GET /collection

create new empty collection

POST /collection?name=$collection_name

drop collection with all documents

DELETE /collection/$collection_name

Index API

get indexes of collection

GET /collection/$collection_name/index

create new index for collection

POST /collection/$collection_name/index?path=$field_name&kind=$index_kind&key=$key_type

drop index of collection

DELETE /collection/$collection_name/document/$index_name

Document API

find documents using query

GET /collection/$collection_name/document?filter=$query&order=$ordering&offset=$skip&length=$take

GET /collection/$collection_name?filter=$query&order=$ordering&offset=$skip&length=$take

modify documents using query

PUT /collection/$collection_name/document?filter=$query&modify=$modifications

PATCH /collection/$collection_name?filter=$query&modify=$modifications

remove documents using query

DELETE /collection/$collection_name/document?filter=$query

PUT /collection/$collection_name?filter=$query

insert new document

POST /collection/$collection_name/document

POST /collection/$collection_name

get document by id

GET /collection/$collection_name/document/$document_id

GET /collection/$collection_name/$document_id

replace document

PUT /collection/$collection_name/document/$document_id

PUT /collection/$collection_name/$document_id

remove document

DELETE /collection/$collection_name/document/$document_id

DELETE /collection/$collection_name/$document_id

Macros

query

Unified query message macro

Structs

CollectionParams

Collection parameters

DeleteMsg

Delete the previously inserted document

DocumentWithId
DocumentsIterator

Iterator across found documents

DropCollectionMsg

Drop collection from storage

DropIndexMsg

Drop spicific index from collection

EnsureCollectionMsg

Ensure collection in storage

EnsureIndexMsg

Ensure new index for collection

FindMsg

Find documents using filter and ordering

FindParams

Find query parameters

GetCollections

Get collections request

GetIndexesMsg

Get indexes of collection

GetInfo

Get database info

GetMsg

Get the previously inserted document by primary key

GetStats

Get database stats

Info

Storage info data

InsertMsg

Insert new document into collection

KeyField

Indexed field definition

KeyFields

Indexed fields definition

Modify

Modification operator

Options

Database options

PutMsg

Put new version of the previously inserted document

RemoveMsg

Remove documents using filter

RemoveParams

Remove query parameters

SetIndexesMsg

Set indexes for collection

Stats

Storage stats data

Storage

Storage actor

UpdateMsg

Update documents using filter and modifier

UpdateParams

Update query parameters

Enums

Action

Modifier action

Comp

Comparison operator of filter

Cond

Condition operator of filter

Filter

Filter operator

Identifier

Generic string indentifier

IndexKind

The kind of index

KeyData

The data of key

KeyType

The type of key

Order

Ordering operator

OrderKind

The kind ot order

Value

The Value enum, a loosely typed way of representing any valid CBOR value.

Traits

Document

Identified document representation

StorageAddrExt

Helper for sending queries

Functions

Delete

Delete the previously inserted document

DropCollection

Drop collection from storage

DropIndex

Drop spicific index from collection

EnsureCollection

Ensure collection in storage

EnsureIndex

Ensure new index for collection

Find

Find documents using filter and ordering

Get

Get the previously inserted document by primary key

GetIndexes

Get indexes of collection

Insert

Insert new document into collection

Put

Put new version of the previously inserted document

Remove

Remove documents using filter

SetIndexes

Set indexes for collection

Update

Update documents using filter and modifier

delete_document

Delete document handler

drop_collection

Drop collection handler

drop_index

Drop index handler

ensure_collection

Ensure collection handler

ensure_index

Ensure index handler

find_documents

Find documents query handler

get_collections

Storage collections handler

get_document

Get document handler

get_indexes

Get indexes handler

get_info

Storage info handler

get_stats

Storage stats handler

get_usage

Usage info handler

insert_document

Insert document handler

put_document

Put document handler

remove_documents

Remove documents query handler

storage

Scoped storage adapter for actix-web

update_documents

Update documents query handler

Type Definitions

ListCollections

The list of collections

Primary

Primary key (document identifier)

StorageAddr

Storage actor address type

Derive Macros

Document