1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
//! A set of datastructures meant for rendering a Prisma data model as
//! a string. We don't even try to make the result pretty. Please use
//! the functionality of prisma-fmt for that.
//!
//! All structs implement `std::fmt::Display` for easy usage.
//!
//! An example use case to render a datasource as a string:
//!
//! ```
//! use datamodel_renderer::{configuration::Datasource, value::Env};
//! use indoc::{indoc, formatdoc};
//!
//! let datasource = Datasource::new(
//! "db",
//! "postgres",
//! Env::variable("DATABASE_URL")
//! );
//!
//! // We get a string rendering without proper formatting
//! // by calling the `to_string()` method:
//! let rendered = datasource.to_string();
//!
//! // The output is not formatted, so we call the reformat
//! // function to the result to make it look more kosher.
//! let rendered = psl::reformat(&rendered, 2).unwrap();
//!
//! let expected = indoc! {r#"
//! datasource db {
//! provider = "postgres"
//! url = env("DATABASE_URL")
//! }
//! "#};
//!
//! assert_eq!(expected, &rendered);
//!
//! // Additionally we can just pass the datasource to any
//! // format block to include it in the resulting string:
//! let rendered = formatdoc!(r#"
//! {datasource}
//!
//! model A {{
//! id Int @id
//! }}
//! "#);
//!
//! // Again, making the result indentation and spacing to
//! // look prettier.
//! let rendered = psl::reformat(&rendered, 2).unwrap();
//!
//! let expected = indoc! {r#"
//! datasource db {
//! provider = "postgres"
//! url = env("DATABASE_URL")
//! }
//!
//! model A {
//! id Int @id
//! }
//! "#};
//!
//! assert_eq!(expected, &rendered);
//! ```
#![warn(missing_docs)]
pub mod configuration;
pub mod datamodel;
pub mod value;
pub use configuration::Configuration;
pub use datamodel::Datamodel;
use std::borrow::Cow;