d1-orm-engine 0.1.1

Table, model, batch, raw SQL engine for rust-d1-orm
Documentation
use worker::{D1Database, D1PreparedStatement, D1Result};
use crate::error::OrmError;

pub struct Batch<'db> {
    db: &'db D1Database,
    stmts: Vec<D1PreparedStatement>,
}

impl<'db> Batch<'db> {
    pub fn new(db: &'db D1Database) -> Self {
        Self { db, stmts: vec![] }
    }

    pub fn add(mut self, stmt: D1PreparedStatement) -> Self {
        self.stmts.push(stmt);
        self
    }

    pub async fn run(self) -> Result<Vec<D1Result>, OrmError> {
        self.db.batch(self.stmts).await.map_err(|_| OrmError::Execute)
    }
}