pub struct Datasource<'a> { /* private fields */ }
Expand description

The datasource block in a PSL file.

Implementations§

source§

impl<'a> Datasource<'a>

source

pub fn new(name: &'a str, provider: &'a str, url: impl Into<Env<'a>>) -> Self

Create a new datasource with all required properties.

datasource db {
//         ^^ name
  provider = "postgresql"
//            ^^^^^^^^^^ provider
  url      = env("DATABASE_URL")
//                ^^^^^^^^^^^^ url
}
source

pub fn shadow_database_url(&mut self, url: impl Into<Env<'a>>)

Used for schema engine to reflect the contents of migrations directory to diff against the actual database.

datasource db {
  provider          = "postgresql"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
//                         ^^^^^^^^^^^^^^^^^^^ this
}
source

pub fn relation_mode(&mut self, relation_mode: RelationMode)

Who handles referential integrity.

datasource db {
  provider     = "postgresql"
  url          = env("DATABASE_URL")
  relationMode = "foreignKeys"
//                ^^^^^^^^^^^ this
}
source

pub fn push_custom_property( &mut self, key: &'a str, value: impl Into<Value<'a>> )

Add a custom connector-specific property to the datasource. Use this for settings that are only for a single database. For shared things, add an explicit property to the Datasource struct.

An example for PostgreSQL extensions, using an array of functions:

datasource db {
  provider   = "postgresql"
  url          = env("DATABASE_URL")
  extensions = [citext(version: "2.1")]
//             ^^^^^^^^^^^^^^^^^^^^^^^^ value
//^^^^^^^^^^ key
}
source

pub fn documentation(&mut self, documentation: impl Into<Cow<'a, str>>)

The documentation on top of the datasource.

/// This here is the documentation.
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
source

pub fn from_psl( psl_ds: &'a Datasource, force_namespaces: Option<&'a [String]> ) -> Self

Create a rendering from a PSL datasource.

Trait Implementations§

source§

impl<'a> Debug for Datasource<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Display for Datasource<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Datasource<'a>

§

impl<'a> Send for Datasource<'a>

§

impl<'a> Sync for Datasource<'a>

§

impl<'a> Unpin for Datasource<'a>

§

impl<'a> UnwindSafe for Datasource<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.