2022-02-14 10:13:50 +00:00
|
|
|
use crate::cnf::ID_CHARS;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Iterator;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Runtime;
|
2022-02-15 01:00:30 +00:00
|
|
|
use crate::dbs::Transaction;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::array::Array;
|
|
|
|
use crate::sql::model::Model;
|
|
|
|
use crate::sql::table::Table;
|
|
|
|
use crate::sql::thing::Thing;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
use async_recursion::async_recursion;
|
2022-02-14 10:13:50 +00:00
|
|
|
use nanoid::nanoid;
|
2022-02-06 01:14:56 +00:00
|
|
|
|
|
|
|
impl Value {
|
|
|
|
#[async_recursion]
|
|
|
|
pub async fn iterate(
|
|
|
|
self,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 01:00:30 +00:00
|
|
|
txn: &Transaction<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
ite: &mut Iterator<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
match self {
|
2022-02-15 01:00:30 +00:00
|
|
|
Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
v => ite.process(ctx, opt, txn, None, v).await,
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Array {
|
|
|
|
#[async_recursion]
|
|
|
|
pub async fn iterate(
|
|
|
|
self,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 01:00:30 +00:00
|
|
|
txn: &Transaction<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
ite: &mut Iterator<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
for v in self.value.into_iter() {
|
|
|
|
match v {
|
2022-02-15 01:00:30 +00:00
|
|
|
Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?,
|
|
|
|
v => ite.process(ctx, opt, txn, None, v).await,
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Model {
|
|
|
|
pub async fn iterate(
|
|
|
|
self,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 01:00:30 +00:00
|
|
|
txn: &Transaction<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
ite: &mut Iterator<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
if ctx.is_ok() {
|
|
|
|
if let Some(c) = self.count {
|
|
|
|
for _ in 0..c {
|
|
|
|
Thing {
|
|
|
|
tb: self.table.to_string(),
|
2022-02-14 10:13:50 +00:00
|
|
|
id: nanoid!(20, &ID_CHARS),
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
2022-02-15 01:00:30 +00:00
|
|
|
.iterate(ctx, opt, txn, ite)
|
2022-02-06 01:14:56 +00:00
|
|
|
.await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(r) = self.range {
|
|
|
|
for x in r.0..r.1 {
|
|
|
|
Thing {
|
|
|
|
tb: self.table.to_string(),
|
|
|
|
id: x.to_string(),
|
|
|
|
}
|
2022-02-15 01:00:30 +00:00
|
|
|
.iterate(ctx, opt, txn, ite)
|
2022-02-06 01:14:56 +00:00
|
|
|
.await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Thing {
|
|
|
|
pub async fn iterate(
|
|
|
|
self,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 01:00:30 +00:00
|
|
|
txn: &Transaction<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
ite: &mut Iterator<'_>,
|
|
|
|
) -> Result<(), Error> {
|
2022-02-15 01:00:30 +00:00
|
|
|
Ok(())
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Table {
|
|
|
|
pub async fn iterate(
|
|
|
|
self,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 01:00:30 +00:00
|
|
|
txn: &Transaction<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
ite: &mut Iterator<'_>,
|
|
|
|
) -> Result<(), Error> {
|
2022-02-15 01:00:30 +00:00
|
|
|
Ok(())
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|