rustyroad 1.8.5

Rusty Road is a framework written in Rust that is based on Ruby on Rails. It is designed to provide the familiar conventions and ease of use of Ruby on Rails, while also taking advantage of the performance and efficiency of Rust.
//! SQLx repository orchestration; `render(&Schema::default())` emits only a header.

mod atomic;
mod create;
mod delete_key;
mod fields;
mod inputs;
mod insert;
mod lookup;
mod patch;
mod policy;
mod selector;
mod table;
mod targets;
mod update;
mod update_key;
mod upsert;
mod upsert_patch;
mod where_key;

use crate::database::introspection::Schema;

/// Renders repositories; e.g. `render(schema)` adds unique-key policies to keyed CRUD.
pub(super) fn render(schema: &Schema) -> String {
    let mut output = String::from(
        "// Generated by `rustyroad pull --language rust`; do not edit.\n\n",
    );
    let mut body = String::new();
    let mut needs_builder = false;
    for table in schema.tables.iter().filter(|table| !table.view) {
        if table.has_simple_key() {
            body.push_str(&table::render(table, schema));
            needs_builder |= !inputs::new_columns(table).is_empty()
                || !inputs::patch_columns(table).is_empty();
        }
        let (extensions, builder) = atomic::render(table, schema);
        body.push_str(&extensions);
        needs_builder |= builder;
    }
    if body.is_empty() {
        return output;
    }
    if needs_builder {
        output.push_str("use sqlx::{PgPool, Postgres, QueryBuilder};\n\n");
    } else {
        output.push_str("use sqlx::PgPool;\n\n");
    }
    output.push_str("use super::models::*;\n\n");
    output.push_str(&body);
    output
}