pub struct CreateFunctionStatement { /* private fields */ }Expand description
CREATE FUNCTION statement builder
This struct provides a fluent API for constructing CREATE FUNCTION queries.
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::function::{FunctionLanguage, FunctionBehavior};
// CREATE FUNCTION my_func() RETURNS integer LANGUAGE SQL AS 'SELECT 1'
let query = Query::create_function()
.name("my_func")
.returns("integer")
.language(FunctionLanguage::Sql)
.body("SELECT 1");
// CREATE OR REPLACE FUNCTION my_func(a integer) RETURNS integer
// LANGUAGE PLPGSQL IMMUTABLE AS 'BEGIN RETURN a + 1; END;'
let query = Query::create_function()
.name("my_func")
.or_replace()
.add_parameter("a", "integer")
.returns("integer")
.language(FunctionLanguage::PlPgSql)
.behavior(FunctionBehavior::Immutable)
.body("BEGIN RETURN a + 1; END;");Implementations§
Source§impl CreateFunctionStatement
impl CreateFunctionStatement
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new CREATE FUNCTION statement
§Examples
use reinhardt_query::prelude::*;
let query = Query::create_function();Sourcepub fn take(&mut self) -> Self
pub fn take(&mut self) -> Self
Take the ownership of data in the current CreateFunctionStatement
Sourcepub fn name<N>(&mut self, name: N) -> &mut Selfwhere
N: IntoIden,
pub fn name<N>(&mut self, name: N) -> &mut Selfwhere
N: IntoIden,
Set the function name
§Examples
use reinhardt_query::prelude::*;
let query = Query::create_function()
.name("my_func");Sourcepub fn or_replace(&mut self) -> &mut Self
pub fn or_replace(&mut self) -> &mut Self
Add OR REPLACE clause
§Examples
use reinhardt_query::prelude::*;
let query = Query::create_function()
.name("my_func")
.or_replace();Sourcepub fn add_parameter<N: IntoIden, T: Into<String>>(
&mut self,
name: N,
param_type: T,
) -> &mut Self
pub fn add_parameter<N: IntoIden, T: Into<String>>( &mut self, name: N, param_type: T, ) -> &mut Self
Add a function parameter
§Examples
use reinhardt_query::prelude::*;
let query = Query::create_function()
.name("my_func")
.add_parameter("param1", "integer")
.add_parameter("param2", "text");Sourcepub fn returns<T: Into<String>>(&mut self, returns: T) -> &mut Self
pub fn returns<T: Into<String>>(&mut self, returns: T) -> &mut Self
Set RETURNS type
§Examples
use reinhardt_query::prelude::*;
let query = Query::create_function()
.name("my_func")
.returns("integer");Sourcepub fn language(&mut self, language: FunctionLanguage) -> &mut Self
pub fn language(&mut self, language: FunctionLanguage) -> &mut Self
Set LANGUAGE
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::function::FunctionLanguage;
let query = Query::create_function()
.name("my_func")
.language(FunctionLanguage::PlPgSql);Sourcepub fn behavior(&mut self, behavior: FunctionBehavior) -> &mut Self
pub fn behavior(&mut self, behavior: FunctionBehavior) -> &mut Self
Set function behavior (IMMUTABLE/STABLE/VOLATILE)
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::function::FunctionBehavior;
let query = Query::create_function()
.name("my_func")
.behavior(FunctionBehavior::Immutable);Sourcepub fn security(&mut self, security: FunctionSecurity) -> &mut Self
pub fn security(&mut self, security: FunctionSecurity) -> &mut Self
Set security context (DEFINER/INVOKER)
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::function::FunctionSecurity;
let query = Query::create_function()
.name("my_func")
.security(FunctionSecurity::Definer);Sourcepub fn body<B: Into<String>>(&mut self, body: B) -> &mut Self
pub fn body<B: Into<String>>(&mut self, body: B) -> &mut Self
Set function body (AS clause)
§Security Warning
The function body is embedded directly into the CREATE FUNCTION statement and will be stored in the database. DO NOT pass user input directly to this method, as it could lead to arbitrary code execution.
Only use with trusted, validated code.
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::function::{FunctionLanguage, FunctionBehavior};
// ✅ SAFE: Static code
let query = Query::create_function()
.name("my_func")
.returns("integer")
.language(FunctionLanguage::Sql)
.body("SELECT 1");
// ❌ UNSAFE: User input
// let query = Query::create_function()
// .name("user_func")
// .body(&user_code);Trait Implementations§
Source§impl Clone for CreateFunctionStatement
impl Clone for CreateFunctionStatement
Source§fn clone(&self) -> CreateFunctionStatement
fn clone(&self) -> CreateFunctionStatement
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CreateFunctionStatement
impl Debug for CreateFunctionStatement
Source§impl Default for CreateFunctionStatement
impl Default for CreateFunctionStatement
Source§impl QueryStatementBuilder for CreateFunctionStatement
impl QueryStatementBuilder for CreateFunctionStatement
Source§fn build_any(&self, query_builder: &dyn QueryBuilderTrait) -> (String, Values)
fn build_any(&self, query_builder: &dyn QueryBuilderTrait) -> (String, Values)
Build SQL statement for a database backend and collect query parameters Read more
impl QueryStatementWriter for CreateFunctionStatement
Auto Trait Implementations§
impl Freeze for CreateFunctionStatement
impl !RefUnwindSafe for CreateFunctionStatement
impl !Send for CreateFunctionStatement
impl !Sync for CreateFunctionStatement
impl Unpin for CreateFunctionStatement
impl UnsafeUnpin for CreateFunctionStatement
impl !UnwindSafe for CreateFunctionStatement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more