Skip to main content

Generator

Struct Generator 

Source
pub struct Generator { /* private fields */ }
Expand description

Configure code generation, then choose one explicit schema source.

Custom Rust syntax is checked before writing output. Generated structs preserve SQL names with Serde attributes. Additional derives and attributes apply to data types, not markers.

Implementations§

Source§

impl Generator

Source

pub fn new() -> Self

Source

pub fn schemas( self, schemas: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Replace the default public selection with these schemas.

Source

pub fn schema(self, schema: impl Into<String>) -> Self

Select a single schema instead of the default public.

Source

pub fn prelude(self, prelude: impl Into<String>) -> Self

Add Rust items or imports before the generated schema modules.

Source

pub fn derive(self, derive: impl Into<String>) -> Self

Add a derive path, such as ::typed_builder::TypedBuilder.

Source

pub fn attribute(self, attribute: impl Into<String>) -> Self

Add an outer attribute, including its #[...] delimiters.

Source

pub fn type_attribute( self, generated_type: impl Into<String>, attribute: impl Into<String>, ) -> Self

Add an attribute to one generated data type.

Paths use generated Rust names, for example public.tables.messages.Insert. Unknown paths fail generation instead of silently ignoring customization.

Source

pub fn type_override( self, postgres_type: impl Into<String>, rust_type: impl Into<String>, ) -> Self

Map a qualified SQL type to a Rust type that matches the PostgREST JSON representation.

Source

pub fn runtime_path(self, path: impl Into<String>) -> Self

Set the runtime module path when the client dependency has a Cargo alias.

Source

pub fn not_null( self, target: impl Into<String>, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Assert non-null fields on a view Row, composite, or RPC Record. Unknown targets and SQL field names fail generation.

Source

pub fn column_type( self, target: impl Into<String>, rust_type: impl Into<String>, ) -> Self

Override one SQL column’s base type, preserving nullability and omission. Accepts public.table.column or public.tables.table.column.

Source

pub fn json_type( self, target: impl Into<String>, rust_type: impl Into<String>, ) -> Self

Decode a JSON field, RPC argument or return using a custom Serde type. SQL arrays, nullability, and set-returning wrappers remain intact.

Source

pub const fn reexport_macros(self) -> Self

Export crate-local select! and key! wrappers with the runtime path filled. Include the generated bindings at the schema crate’s root.

Source

pub fn relationship_alias( self, target: impl Into<String>, alias: impl Into<String>, ) -> Self

Add an alias for one canonical qualified relationship marker. For example public.tables.orders.relationships.orders_customer_fkey.

Source

pub const fn strict_args(self) -> Self

Require non-default RPC inputs unless explicitly marked nullable.

Source

pub fn strict_args_for(self, target: impl Into<String>) -> Self

Apply strict RPC input contracts to one generated function module.

Source

pub fn from_snapshot(self, path: impl AsRef<Path>) -> Result<Bindings, Error>

Load a portable snapshot and register Cargo’s file change detection.

§Errors

Fails for unreadable, invalid, or unsupported-version snapshots.

Source

pub fn from_metadata(self, snapshot: Snapshot) -> Result<Bindings, Error>

Generate from in-memory metadata. Does not emit Cargo change instructions.

§Errors

Fails for unsupported versions, invalid metadata, or invalid custom Rust syntax.

Trait Implementations§

Source§

impl Clone for Generator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Generator

Source§

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

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

impl Default for Generator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.