Improve code comments for documentation ()

This commit is contained in:
CelebrateVC 2022-11-23 04:42:59 -05:00 committed by GitHub
parent ddaea59d05
commit f0745386cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 196 additions and 196 deletions

View file

@ -8,13 +8,13 @@ pub struct Canceller {
}
impl Canceller {
// Create a new Canceller
/// Create a new Canceller
pub fn new(cancelled: Arc<AtomicBool>) -> Canceller {
Canceller {
cancelled,
}
}
// Cancel the context.
/// Cancel the context.
pub fn cancel(&self) {
self.cancelled.store(true, Ordering::Relaxed);
}

View file

@ -39,7 +39,7 @@ impl<'a> Default for Context<'a> {
}
impl<'a> Context<'a> {
// Create an empty background context.
/// Create an empty background context.
pub fn background() -> Self {
Context {
values: HashMap::default(),
@ -49,7 +49,7 @@ impl<'a> Context<'a> {
}
}
// Create a new child from a frozen context.
/// Create a new child from a frozen context.
pub fn new(parent: &'a Context) -> Self {
Context {
values: HashMap::default(),
@ -59,8 +59,8 @@ impl<'a> Context<'a> {
}
}
// Add cancellation to the context. The value that is returned will cancel
// the context and it's children once called.
/// Add cancellation to the context. The value that is returned will cancel
/// the context and it's children once called.
pub fn add_cancel(&mut self) -> Canceller {
let cancelled = self.cancelled.clone();
Canceller::new(cancelled)
@ -76,8 +76,8 @@ impl<'a> Context<'a> {
)
}
// Add a deadline to the context. If the current deadline is sooner than
// the provided deadline, this method does nothing.
/// Add a deadline to the context. If the current deadline is sooner than
/// the provided deadline, this method does nothing.
pub fn add_deadline(&mut self, deadline: Instant) {
match self.deadline {
Some(current) if current < deadline => (),
@ -85,14 +85,14 @@ impl<'a> Context<'a> {
}
}
// Add a timeout to the context. If the current timeout is sooner than
// the provided timeout, this method does nothing.
/// Add a timeout to the context. If the current timeout is sooner than
/// the provided timeout, this method does nothing.
pub fn add_timeout(&mut self, timeout: Duration) {
self.add_deadline(Instant::now() + timeout)
}
// Add a value to the context. It overwrites any previously set values
// with the same key.
/// Add a value to the context. It overwrites any previously set values
/// with the same key.
pub fn add_value<V>(&mut self, key: String, value: V)
where
V: Into<Cow<'a, Value>>,
@ -100,14 +100,14 @@ impl<'a> Context<'a> {
self.values.insert(key, value.into());
}
// Get the deadline for this operation, if any. This is useful for
// checking if a long job should be started or not.
/// Get the deadline for this operation, if any. This is useful for
/// checking if a long job should be started or not.
pub fn deadline(&self) -> Option<Instant> {
self.deadline
}
// Check if the context is done. If it returns `None` the operation may
// proceed, otherwise the operation should be stopped.
/// Check if the context is done. If it returns `None` the operation may
/// proceed, otherwise the operation should be stopped.
pub fn done(&self) -> Option<Reason> {
match self.deadline {
Some(deadline) if deadline <= Instant::now() => Some(Reason::Timedout),
@ -119,33 +119,33 @@ impl<'a> Context<'a> {
}
}
// Check if the context is ok to continue.
/// Check if the context is ok to continue.
pub fn is_ok(&self) -> bool {
self.done().is_none()
}
// Check if the context is not ok to continue.
/// Check if the context is not ok to continue.
pub fn is_err(&self) -> bool {
self.done().is_some()
}
// Check if the context is not ok to continue.
/// Check if the context is not ok to continue.
pub fn is_done(&self) -> bool {
self.done().is_some()
}
// Check if the context is not ok to continue, because it timed out.
/// Check if the context is not ok to continue, because it timed out.
pub fn is_timedout(&self) -> bool {
matches!(self.done(), Some(Reason::Timedout))
}
// Check if the context is not ok to continue, because it was cancelled.
/// Check if the context is not ok to continue, because it was cancelled.
pub fn is_cancelled(&self) -> bool {
matches!(self.done(), Some(Reason::Canceled))
}
// Check if the status of the context. This will return a Result, with an Ok
// if the operation may proceed, and an Error if it should be stopped.
/// Check if the status of the context. This will return a Result, with an Ok
/// if the operation may proceed, and an Error if it should be stopped.
pub fn check(&self) -> Result<(), Reason> {
match self.done() {
Some(reason) => Err(reason),
@ -153,8 +153,8 @@ impl<'a> Context<'a> {
}
}
// Get a value from the context. If no value is stored under the
// provided key, then this will return None.
/// Get a value from the context. If no value is stored under the
/// provided key, then this will return None.
pub fn value(&self, key: &str) -> Option<&Value> {
match self.values.get(key) {
Some(v) => match v {

View file

@ -57,17 +57,17 @@ pub struct Iterator {
}
impl Iterator {
// Creates a new iterator
/// Creates a new iterator
pub fn new() -> Self {
Self::default()
}
// Prepares a value for processing
/// Prepares a value for processing
pub fn ingest(&mut self, val: Iterable) {
self.entries.push(val)
}
// Process the records and output
/// Process the records and output
pub async fn output(
&mut self,
ctx: &Context<'_>,
@ -449,7 +449,7 @@ impl Iterator {
}
}
// Process a new record Thing and Value
/// Process a new record Thing and Value
pub async fn process(
&mut self,
ctx: &Context<'_>,
@ -484,7 +484,7 @@ impl Iterator {
self.result(res, stm);
}
// Accept a processed record result
/// Accept a processed record result
fn result(&mut self, res: Result<Value, Error>, stm: &Statement<'_>) {
// Process the result
match res {

View file

@ -4,12 +4,12 @@ use crate::dbs::Level;
use crate::err::Error;
use std::sync::Arc;
// An Options is passed around when processing a set of query
// statements. An Options contains specific information for how
// to process each particular statement, including the record
// version to retrieve, whether futures should be processed, and
// whether field/event/table queries should be processed (useful
// when importing data, where these queries might fail).
/// An Options is passed around when processing a set of query
/// statements. An Options contains specific information for how
/// to process each particular statement, including the record
/// version to retrieve, whether futures should be processed, and
/// whether field/event/table queries should be processed (useful
/// when importing data, where these queries might fail).
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Options {

View file

@ -77,17 +77,17 @@ impl<'a> fmt::Display for Statement<'a> {
}
impl<'a> Statement<'a> {
// Check the type of statement
/// Check the type of statement
#[inline]
pub fn is_select(&self) -> bool {
matches!(self, Statement::Select(_))
}
// Check the type of statement
/// Check the type of statement
#[inline]
pub fn is_delete(&self) -> bool {
matches!(self, Statement::Delete(_))
}
// Returns any query fields if specified
/// Returns any query fields if specified
#[inline]
pub fn expr(&self) -> Option<&Fields> {
match self {
@ -95,7 +95,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any SET clause if specified
/// Returns any SET clause if specified
#[inline]
pub fn data(&self) -> Option<&Data> {
match self {
@ -106,7 +106,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any WHERE clause if specified
/// Returns any WHERE clause if specified
#[inline]
pub fn conds(&self) -> Option<&Cond> {
match self {
@ -116,7 +116,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any SPLIT clause if specified
/// Returns any SPLIT clause if specified
#[inline]
pub fn split(&self) -> Option<&Splits> {
match self {
@ -124,7 +124,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any GROUP clause if specified
/// Returns any GROUP clause if specified
#[inline]
pub fn group(&self) -> Option<&Groups> {
match self {
@ -132,7 +132,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any ORDER clause if specified
/// Returns any ORDER clause if specified
#[inline]
pub fn order(&self) -> Option<&Orders> {
match self {
@ -140,7 +140,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any FETCH clause if specified
/// Returns any FETCH clause if specified
#[inline]
pub fn fetch(&self) -> Option<&Fetchs> {
match self {
@ -148,7 +148,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any START clause if specified
/// Returns any START clause if specified
#[inline]
pub fn start(&self) -> Option<&Start> {
match self {
@ -156,7 +156,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any LIMIT clause if specified
/// Returns any LIMIT clause if specified
#[inline]
pub fn limit(&self) -> Option<&Limit> {
match self {
@ -164,7 +164,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any VERSION clause if specified
/// Returns any VERSION clause if specified
#[inline]
pub fn version(&self) -> Option<&Version> {
match self {
@ -172,7 +172,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any RETURN clause if specified
/// Returns any RETURN clause if specified
#[inline]
pub fn output(&self) -> Option<&Output> {
match self {
@ -184,7 +184,7 @@ impl<'a> Statement<'a> {
_ => None,
}
}
// Returns any RETURN clause if specified
/// Returns any RETURN clause if specified
#[inline]
pub fn parallel(&self) -> bool {
match self {

View file

@ -37,15 +37,15 @@ impl<'a> Document<'a> {
}
impl<'a> Document<'a> {
// Check if document has changed
/// Check if document has changed
pub fn changed(&self) -> bool {
self.initial != self.current
}
// Check if document has changed
/// Check if document has changed
pub fn is_new(&self) -> bool {
self.initial.is_none()
}
// Get the table for this document
/// Get the table for this document
pub async fn tb(
&self,
opt: &Options,
@ -78,7 +78,7 @@ impl<'a> Document<'a> {
Ok(tb) => Ok(tb),
}
}
// Get the foreign tables for this document
/// Get the foreign tables for this document
pub async fn ft(
&self,
opt: &Options,
@ -89,7 +89,7 @@ impl<'a> Document<'a> {
// Get the table definitions
txn.clone().lock().await.all_ft(opt.ns(), opt.db(), &id.tb).await
}
// Get the events for this document
/// Get the events for this document
pub async fn ev(
&self,
opt: &Options,
@ -100,7 +100,7 @@ impl<'a> Document<'a> {
// Get the event definitions
txn.clone().lock().await.all_ev(opt.ns(), opt.db(), &id.tb).await
}
// Get the fields for this document
/// Get the fields for this document
pub async fn fd(
&self,
opt: &Options,
@ -111,7 +111,7 @@ impl<'a> Document<'a> {
// Get the field definitions
txn.clone().lock().await.all_fd(opt.ns(), opt.db(), &id.tb).await
}
// Get the indexes for this document
/// Get the indexes for this document
pub async fn ix(
&self,
opt: &Options,

View file

@ -326,11 +326,11 @@ impl<'a> Document<'a> {
//
Ok(Data::SetExpression(ops))
}
// Set the field in the foreign table
/// Set the field in the foreign table
fn set(&self, ops: &mut Ops, key: Idiom, val: Value) {
ops.push((key, Operator::Equal, val));
}
// Increment or decrement the field in the foreign table
/// Increment or decrement the field in the foreign table
fn chg(&self, ops: &mut Ops, act: &Action, key: Idiom, val: Value) {
ops.push((
key,
@ -342,7 +342,7 @@ impl<'a> Document<'a> {
val,
));
}
// Set the new minimum value for the field in the foreign table
/// Set the new minimum value for the field in the foreign table
fn min(&self, ops: &mut Ops, act: &Action, key: Idiom, val: Value) {
if act == &Action::Update {
ops.push((
@ -362,7 +362,7 @@ impl<'a> Document<'a> {
));
}
}
// Set the new maximum value for the field in the foreign table
/// Set the new maximum value for the field in the foreign table
fn max(&self, ops: &mut Ops, act: &Action, key: Idiom, val: Value) {
if act == &Action::Update {
ops.push((
@ -382,7 +382,7 @@ impl<'a> Document<'a> {
));
}
}
// Set the new average value for the field in the foreign table
/// Set the new average value for the field in the foreign table
fn mean(&self, ops: &mut Ops, act: &Action, key: Idiom, val: Value) {
//
let mut key_c = Idiom::from(vec![Part::from("__")]);

View file

@ -65,8 +65,8 @@ impl FromArgs for Vec<Value> {
}
}
// Some functions take a fixed number of arguments.
// The len must match the number of type idents that follow.
/// Some functions take a fixed number of arguments.
/// The len must match the number of type idents that follow.
macro_rules! impl_tuple {
($len:expr, $( $T:ident ),*) => {
impl<$($T:FromArg),*> FromArgs for ($($T,)*) {

View file

@ -34,11 +34,11 @@ pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Valu
}
}
// Each function is specified by its name (a string literal) followed by its path. The path
// may be followed by one parenthesized argument, e.g. ctx, which is passed to the function
// before the remainder of the arguments. The path may be followed by `.await` to signify that
// it is `async`. Finally, the path may be prefixed by a parenthesized wrapper function e.g.
// `cpu_intensive`.
/// Each function is specified by its name (a string literal) followed by its path. The path
/// may be followed by one parenthesized argument, e.g. ctx, which is passed to the function
/// before the remainder of the arguments. The path may be followed by `.await` to signify that
/// it is `async`. Finally, the path may be prefixed by a parenthesized wrapper function e.g.
/// `cpu_intensive`.
macro_rules! dispatch {
($name: ident, $args: ident, $($function_name: literal => $(($wrapper: tt))* $($function_path: ident)::+ $(($ctx_arg: expr))* $(.$await:tt)*,)+) => {
{

View file

@ -22,7 +22,7 @@ pub mod duration {
pub fn value(&self) -> &str {
&self.value
}
// Convert the object to a string
/// Convert the object to a string
pub fn toString(&self) -> String {
self.value.to_owned()
}

View file

@ -29,7 +29,7 @@ pub mod record {
pub fn id(&self) -> &str {
&self.id
}
// Convert the object to a string
/// Convert the object to a string
pub fn toString(&self) -> String {
format!("{}:{}", self.tb, self.id)
}

View file

@ -22,7 +22,7 @@ pub mod uuid {
pub fn value(&self) -> &str {
&self.value
}
// Convert the object to a string
/// Convert the object to a string
pub fn toString(&self) -> String {
self.value.to_owned()
}

View file

@ -2,11 +2,11 @@
#[quickjs(bare)]
#[allow(non_upper_case_globals)]
pub mod package {
// Get the target system architecture
/// Get the target system architecture
pub fn arch() -> &'static str {
crate::env::arch()
}
// Get the target operating system
/// Get the target operating system
pub fn platform() -> &'static str {
crate::env::os()
}

View file

@ -38,12 +38,12 @@ pub struct Transaction {
}
impl Datastore {
// Open a new database
//
// path must be an empty string or a local file path to a FDB cluster file.
// An empty string results in using the default cluster file placed
// at a system-dependent location defined by FDB.
// See https://apple.github.io/foundationdb/administration.html#default-cluster-file for more information on that.
/// Open a new database
///
/// path must be an empty string or a local file path to a FDB cluster file.
/// An empty string results in using the default cluster file placed
/// at a system-dependent location defined by FDB.
/// See https://apple.github.io/foundationdb/administration.html#default-cluster-file for more information on that.
pub async fn new(path: &str) -> Result<Datastore, Error> {
static FDBNET: Lazy<Arc<foundationdb::api::NetworkAutoStop>> =
Lazy::new(|| Arc::new(unsafe { foundationdb::boot() }));
@ -57,7 +57,7 @@ impl Datastore {
Err(e) => Err(Error::Ds(e.to_string())),
}
}
// Start a new transaction
/// Start a new transaction
pub async fn transaction(&self, write: bool, lock: bool) -> Result<Transaction, Error> {
match self.db.create_trx() {
Ok(tx) => Ok(Transaction {
@ -72,22 +72,22 @@ impl Datastore {
}
impl Transaction {
// Check if closed
/// Check if closed
pub fn closed(&self) -> bool {
self.ok
}
// We use lock=true to enable the tikv's own pessimistic tx (https://docs.pingcap.com/tidb/v4.0/pessimistic-transaction)
// for tikv kvs.
// FDB's standard transaction(snapshot=false) behaves like a tikv perssimistic tx
// by automatically retrying on conflict at the fdb client layer.
// So in fdb kvs we assume that lock=true is basically a request to
// use the standard fdb tx to make transactions Serializable.
// In case the tx is rw, we assume the user never wants to lose serializability
// so we go with the standard fdb serializable tx in that case too.
/// We use lock=true to enable the tikv's own pessimistic tx (https://docs.pingcap.com/tidb/v4.0/pessimistic-transaction)
/// for tikv kvs.
/// FDB's standard transaction(snapshot=false) behaves like a tikv perssimistic tx
/// by automatically retrying on conflict at the fdb client layer.
/// So in fdb kvs we assume that lock=true is basically a request to
/// use the standard fdb tx to make transactions Serializable.
/// In case the tx is rw, we assume the user never wants to lose serializability
/// so we go with the standard fdb serializable tx in that case too.
fn snapshot(&self) -> bool {
!self.rw && !self.lock
}
// Cancel a transaction
/// Cancel a transaction
pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -113,7 +113,7 @@ impl Transaction {
// Continue
Ok(())
}
// Commit a transaction
/// Commit a transaction
pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -145,7 +145,7 @@ impl Transaction {
// Continue
Ok(())
}
// Check if a key exists
/// Check if a key exists
pub async fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key>,
@ -169,7 +169,7 @@ impl Transaction {
.map(|v| v.is_some())
.map_err(|e| Error::Tx(format!("Unable to get kv from FDB: {}", e)))
}
// Fetch a key from the database
/// Fetch a key from the database
pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key>,
@ -195,7 +195,7 @@ impl Transaction {
.map_err(|e| Error::Tx(format!("Unable to get kv from FDB: {}", e)));
res
}
// Insert or update a key in the database
/// Insert or update a key in the database
pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -220,16 +220,16 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
//
// This function is used when the client sent a CREATE query,
// where the key is derived from namespace, database, table name,
// and either an auto-generated record ID or a the record ID specified by the client
// after the colon in the CREATE query's first argument.
//
// Suppose you've sent a query like `CREATE author:john SET ...` with
// the namespace `test` and the database `test`-
// You'll see SurrealDB sets a value to the key `/*test\x00*test\x00*author\x00*\x00\x00\x00\x01john\x00`.
/// Insert a key if it doesn't exist in the database
///
/// This function is used when the client sent a CREATE query,
/// where the key is derived from namespace, database, table name,
/// and either an auto-generated record ID or a the record ID specified by the client
/// after the colon in the CREATE query's first argument.
///
/// Suppose you've sent a query like `CREATE author:john SET ...` with
/// the namespace `test` and the database `test`-
/// You'll see SurrealDB sets a value to the key `/*test\x00*test\x00*author\x00*\x00\x00\x00\x01john\x00`.
pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -257,7 +257,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -298,7 +298,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key>,
@ -320,7 +320,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -350,7 +350,7 @@ impl Transaction {
// Return result
Ok(())
}
// Retrieve a range of keys from the databases
/// Retrieve a range of keys from the databases
pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key>,

View file

@ -19,7 +19,7 @@ pub struct Transaction {
}
impl Datastore {
// Open a new database
/// Open a new database
pub async fn new(path: &str) -> Result<Datastore, Error> {
match indxdb::db::new(path).await {
Ok(db) => Ok(Datastore {
@ -28,7 +28,7 @@ impl Datastore {
Err(e) => Err(Error::Ds(e.to_string())),
}
}
// Start a new transaction
/// Start a new transaction
pub async fn transaction(&self, write: bool, _: bool) -> Result<Transaction, Error> {
match self.db.begin(write).await {
Ok(tx) => Ok(Transaction {
@ -42,11 +42,11 @@ impl Datastore {
}
impl Transaction {
// Check if closed
/// Check if closed
pub fn closed(&self) -> bool {
self.ok
}
// Cancel a transaction
/// Cancel a transaction
pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -59,7 +59,7 @@ impl Transaction {
// Continue
Ok(())
}
// Commit a transaction
/// Commit a transaction
pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -76,7 +76,7 @@ impl Transaction {
// Continue
Ok(())
}
// Check if a key exists
/// Check if a key exists
pub async fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key>,
@ -90,7 +90,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Fetch a key from the database
/// Fetch a key from the database
pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key>,
@ -104,7 +104,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Insert or update a key in the database
/// Insert or update a key in the database
pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -123,7 +123,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -142,7 +142,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -161,7 +161,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key>,
@ -179,7 +179,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Delete a key
/// Delete a key
pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -198,7 +198,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Retrieve a range of keys from the databases
/// Retrieve a range of keys from the databases
pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key>,

View file

@ -4,7 +4,7 @@ pub type Key = Vec<u8>;
/// The value part of a key-value pair. An alias for [`Vec<u8>`].
pub type Val = Vec<u8>;
// This trait appends an element to a collection, and allows chaining
/// This trait appends an element to a collection, and allows chaining
pub(super) trait Add<T> {
fn add(self, v: T) -> Self;
}
@ -16,7 +16,7 @@ impl Add<u8> for Vec<u8> {
}
}
// This trait converts a collection of key-value pairs into the desired type
/// This trait converts a collection of key-value pairs into the desired type
pub(super) trait Convert<T> {
fn convert(self) -> T;
}

View file

@ -10,22 +10,22 @@ pub struct Datastore {
}
pub struct Transaction {
// Is the transaction complete?
/// Is the transaction complete?
ok: bool,
// Is the transaction read+write?
/// Is the transaction read+write?
rw: bool,
// The distributed datastore transaction
/// The distributed datastore transaction
tx: echodb::Tx<Key, Val>,
}
impl Datastore {
// Open a new database
/// Open a new database
pub async fn new() -> Result<Datastore, Error> {
Ok(Datastore {
db: echodb::db::new(),
})
}
// Start a new transaction
/// Start a new transaction
pub async fn transaction(&self, write: bool, _: bool) -> Result<Transaction, Error> {
match self.db.begin(write).await {
Ok(tx) => Ok(Transaction {
@ -39,11 +39,11 @@ impl Datastore {
}
impl Transaction {
// Check if closed
/// Check if closed
pub fn closed(&self) -> bool {
self.ok
}
// Cancel a transaction
/// Cancel a transaction
pub fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -56,7 +56,7 @@ impl Transaction {
// Continue
Ok(())
}
// Commit a transaction
/// Commit a transaction
pub fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -73,7 +73,7 @@ impl Transaction {
// Continue
Ok(())
}
// Check if a key exists
/// Check if a key exists
pub fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key>,
@ -87,7 +87,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Fetch a key from the database
/// Fetch a key from the database
pub fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key>,
@ -101,7 +101,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Insert or update a key in the database
/// Insert or update a key in the database
pub fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -120,7 +120,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -139,7 +139,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -158,7 +158,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key>,
@ -176,7 +176,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -195,7 +195,7 @@ impl Transaction {
// Return result
Ok(())
}
// Retrieve a range of keys from the databases
/// Retrieve a range of keys from the databases
pub fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key>,

View file

@ -26,13 +26,13 @@ pub struct Transaction {
}
impl Datastore {
// Open a new database
/// Open a new database
pub async fn new(path: &str) -> Result<Datastore, Error> {
Ok(Datastore {
db: Arc::pin(OptimisticTransactionDB::open_default(path)?),
})
}
// Start a new transaction
/// Start a new transaction
pub async fn transaction(&self, write: bool, _: bool) -> Result<Transaction, Error> {
// Create a new transaction
let tx = self.db.transaction();
@ -59,11 +59,11 @@ impl Datastore {
}
impl Transaction {
// Check if closed
/// Check if closed
pub fn closed(&self) -> bool {
self.ok
}
// Cancel a transaction
/// Cancel a transaction
pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -79,7 +79,7 @@ impl Transaction {
// Continue
Ok(())
}
// Commit a transaction
/// Commit a transaction
pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -99,7 +99,7 @@ impl Transaction {
// Continue
Ok(())
}
// Check if a key exists
/// Check if a key exists
pub async fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key>,
@ -113,7 +113,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Fetch a key from the database
/// Fetch a key from the database
pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key>,
@ -127,7 +127,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Insert or update a key in the database
/// Insert or update a key in the database
pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -146,7 +146,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -174,7 +174,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -204,7 +204,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key>,
@ -222,7 +222,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -251,7 +251,7 @@ impl Transaction {
// Return result
Ok(())
}
// Retrieve a range of keys from the databases
/// Retrieve a range of keys from the databases
pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key>,

View file

@ -21,7 +21,7 @@ pub struct Transaction {
}
impl Datastore {
// Open a new database
/// Open a new database
pub async fn new(path: &str) -> Result<Datastore, Error> {
match tikv::TransactionClient::new(vec![path]).await {
Ok(db) => Ok(Datastore {
@ -30,7 +30,7 @@ impl Datastore {
Err(e) => Err(Error::Ds(e.to_string())),
}
}
// Start a new transaction
/// Start a new transaction
pub async fn transaction(&self, write: bool, lock: bool) -> Result<Transaction, Error> {
match lock {
false => {
@ -72,11 +72,11 @@ impl Datastore {
}
impl Transaction {
// Check if closed
/// Check if closed
pub fn closed(&self) -> bool {
self.ok
}
// Cancel a transaction
/// Cancel a transaction
pub async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -89,7 +89,7 @@ impl Transaction {
// Continue
Ok(())
}
// Commit a transaction
/// Commit a transaction
pub async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.ok {
@ -106,7 +106,7 @@ impl Transaction {
// Continue
Ok(())
}
// Check if a key exists
/// Check if a key exists
pub async fn exi<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key>,
@ -120,7 +120,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Fetch a key from the database
/// Fetch a key from the database
pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key>,
@ -134,7 +134,7 @@ impl Transaction {
// Return result
Ok(res)
}
// Insert or update a key in the database
/// Insert or update a key in the database
pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -153,7 +153,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key>,
@ -172,7 +172,7 @@ impl Transaction {
// Return result
Ok(())
}
// Insert a key if it doesn't exist in the database
/// Insert a key if it doesn't exist in the database
pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -201,7 +201,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key>,
@ -219,7 +219,7 @@ impl Transaction {
// Return result
Ok(())
}
// Delete a key
/// Delete a key
pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where
K: Into<Key>,
@ -246,7 +246,7 @@ impl Transaction {
// Return result
Ok(())
}
// Retrieve a range of keys from the databases
/// Retrieve a range of keys from the databases
pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key>,

View file

@ -28,7 +28,7 @@ impl Default for Expression {
}
impl Expression {
// Create a new expression
/// Create a new expression
fn new(l: Value, o: Operator, r: Value) -> Self {
Self {
l,
@ -36,7 +36,7 @@ impl Expression {
r,
}
}
// Augment an existing expression
/// Augment an existing expression
fn augment(mut self, l: Value, o: Operator) -> Self {
if o.precedence() >= self.o.precedence() {
match self.l {

View file

@ -32,21 +32,21 @@ impl PartialOrd for Function {
}
impl Function {
// Get function name if applicable
/// Get function name if applicable
pub fn name(&self) -> &str {
match self {
Self::Normal(n, _) => n.as_str(),
_ => unreachable!(),
}
}
// Get function arguments if applicable
/// Get function arguments if applicable
pub fn args(&self) -> &[Value] {
match self {
Self::Normal(_, a) => a,
_ => &[],
}
}
// Convert this function to an aggregate
/// Convert this function to an aggregate
pub fn aggregate(&self, val: Value) -> Self {
match self {
Self::Normal(n, a) => {
@ -63,7 +63,7 @@ impl Function {
_ => unreachable!(),
}
}
// Check if this function is a rolling function
/// Check if this function is a rolling function
pub fn is_rolling(&self) -> bool {
match self {
Self::Normal(f, _) if f == "count" => true,
@ -74,7 +74,7 @@ impl Function {
_ => false,
}
}
// Check if this function is a grouping function
/// Check if this function is a grouping function
pub fn is_aggregate(&self) -> bool {
match self {
Self::Normal(f, _) if f == "array::concat" => true,

View file

@ -63,22 +63,22 @@ impl From<Vec<Part>> for Idiom {
}
impl Idiom {
// Appends a part to the end of this Idiom
/// Appends a part to the end of this Idiom
pub(crate) fn push(mut self, n: Part) -> Idiom {
self.0.push(n);
self
}
// Convert this Idiom to a unique hash
/// Convert this Idiom to a unique hash
pub(crate) fn to_hash(&self) -> String {
let mut hasher = Md5::new();
hasher.update(self.to_string().as_str());
format!("{:x}", hasher.finalize())
}
// Convert this Idiom to a JSON Path string
/// Convert this Idiom to a JSON Path string
pub(crate) fn to_path(&self) -> String {
format!("/{}", self).replace(']', "").replace(&['.', '['][..], "/")
}
// Simplifies this Idiom for use in object keys
/// Simplifies this Idiom for use in object keys
pub(crate) fn simplify(&self) -> Idiom {
self.0
.iter()
@ -87,23 +87,23 @@ impl Idiom {
.collect::<Vec<_>>()
.into()
}
// Check if this expression is an 'id' field
/// Check if this expression is an 'id' field
pub(crate) fn is_id(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&ID[0])
}
// Check if this expression is an 'in' field
/// Check if this expression is an 'in' field
pub(crate) fn is_in(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&IN[0])
}
// Check if this expression is an 'out' field
/// Check if this expression is an 'out' field
pub(crate) fn is_out(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&OUT[0])
}
// Check if this is an expression with multiple yields
/// Check if this is an expression with multiple yields
pub(crate) fn is_multi_yield(&self) -> bool {
self.iter().any(Self::split_multi_yield)
}
// Check if the path part is a yield in a multi-yield expression
/// Check if the path part is a yield in a multi-yield expression
pub(crate) fn split_multi_yield(v: &Part) -> bool {
matches!(v, Part::Graph(g) if g.alias.is_some())
}
@ -157,7 +157,7 @@ impl fmt::Display for Idiom {
}
}
// Used in a DEFINE FIELD and DEFINE INDEX clauses
/// Used in a DEFINE FIELD and DEFINE INDEX clauses
pub fn local(i: &str) -> IResult<&str, Idiom> {
let (i, p) = first(i)?;
let (i, mut v) = many0(alt((all, index, field)))(i)?;
@ -165,7 +165,7 @@ pub fn local(i: &str) -> IResult<&str, Idiom> {
Ok((i, Idiom::from(v)))
}
// Used in a SPLIT, ORDER, and GROUP clauses
/// Used in a SPLIT, ORDER, and GROUP clauses
pub fn basic(i: &str) -> IResult<&str, Idiom> {
let (i, p) = first(i)?;
let (i, mut v) = many0(alt((all, last, index, field)))(i)?;
@ -173,7 +173,7 @@ pub fn basic(i: &str) -> IResult<&str, Idiom> {
Ok((i, Idiom::from(v)))
}
// Used in a $param definition
/// Used in a $param definition
pub fn param(i: &str) -> IResult<&str, Idiom> {
let (i, p) = first(i)?;
let (i, mut v) = many0(part)(i)?;

View file

@ -85,14 +85,14 @@ impl IntoIterator for Object {
}
impl Object {
// Fetch the record id if there is one
/// Fetch the record id if there is one
pub fn rid(&self) -> Option<Thing> {
match self.get("id") {
Some(Value::Thing(v)) => Some(v.clone()),
_ => None,
}
}
// Convert this object to a diff-match-patch operation
/// Convert this object to a diff-match-patch operation
pub fn to_operation(&self) -> Result<Operation, Error> {
match self.get("op") {
Some(o) => match self.get("path") {

View file

@ -47,7 +47,7 @@ pub struct Rpc {
}
impl Rpc {
// Instantiate a new RPC
/// Instantiate a new RPC
pub fn new(mut session: Session) -> Arc<RwLock<Rpc>> {
// Create a new RPC variables store
let vars = BTreeMap::new();
@ -63,7 +63,7 @@ impl Rpc {
}))
}
// Serve the RPC endpoint
/// Serve the RPC endpoint
pub async fn serve(rpc: Arc<RwLock<Rpc>>, ws: WebSocket) {
// Create a channel for sending messages
let (chn, mut rcv) = channel::new(MAX_CONCURRENT_CALLS);
@ -138,7 +138,7 @@ impl Rpc {
}
}
// Call RPC methods from the WebSocket
/// Call RPC methods from the WebSocket
async fn call(rpc: Arc<RwLock<Rpc>>, msg: Message, chn: Sender<Message>) {
// Get the current output format
let mut out = { rpc.read().await.format.clone() };

View file

@ -8,7 +8,7 @@ pub trait Take {
}
impl Take for Array {
// Convert the array to one argument
/// Convert the array to one argument
fn needs_one(self) -> Result<Value, ()> {
if self.len() < 1 {
return Err(());
@ -19,7 +19,7 @@ impl Take for Array {
None => Ok(Value::None),
}
}
// Convert the array to two arguments
/// Convert the array to two arguments
fn needs_two(self) -> Result<(Value, Value), ()> {
if self.len() < 2 {
return Err(());
@ -31,7 +31,7 @@ impl Take for Array {
(_, _) => Ok((Value::None, Value::None)),
}
}
// Convert the array to two arguments
/// Convert the array to two arguments
fn needs_one_or_two(self) -> Result<(Value, Value), ()> {
if self.len() < 1 {
return Err(());

View file

@ -30,7 +30,7 @@ enum Content<T> {
}
impl<T: Serialize> Response<T> {
// Send the response to the channel
/// Send the response to the channel
pub async fn send(self, out: Output, chn: Sender<Message>) {
match out {
Output::Json => {
@ -100,7 +100,7 @@ impl Failure {
}
}
// Create a JSON RPC result response
/// Create a JSON RPC result response
pub fn success<S: Serialize>(id: Option<Value>, val: S) -> Response<S> {
Response {
id,
@ -108,7 +108,7 @@ pub fn success<S: Serialize>(id: Option<Value>, val: S) -> Response<S> {
}
}
// Create a JSON RPC failure response
/// Create a JSON RPC failure response
pub fn failure(id: Option<Value>, err: Failure) -> Response<Value> {
Response {
id,