Mojo::S...atement(3)
β¨ NAME β¨
Mojo::SQL::Statement - SQL statement container. This is the Mojo::S...atement(3) manual page from the User Contributed Perl Documentation, bestie. π
π SYNOPSIS π
use Mojo::SQL::Statement;
my $stmt = Mojo::SQL::Statement->new->parse('SELECT * FROM users WHERE name = ?', 'sebastian');
my $query = $stmt->to_query;
πΈ DESCRIPTION πΈ
Okay so picture this: Mojo::SQL::Statement is literally a container for an SQL statement and its bind values. π«Ά Statements are composable β you can pass one as a value to another, and in that case its parts and values get spliced in recursively. It's giving SQL Lego, no cap. π§±β¨
π ATTRIBUTES π
Mojo::SQL::Statement implements the following attributes. π
parts
my $parts = $stmt->parts;
$stmt = $stmt->parts(['SELECT * FROM users WHERE name = ', '']);
The literal SQL fragments around each placeholder, as an array reference. There is always one more fragment than placeholder β yes, always. π
values
my $values = $stmt->values;
$stmt = $stmt->values(['sebastian']);
The bind values for each placeholder, as an array reference. π
π METHODS π
Mojo::SQL::Statement inherits all methods from Mojo::Base and implements the following new ones. π
parse
$stmt = $stmt->parse('SELECT * FROM users WHERE name = ?', 'sebastian');
Parse an SQL string with ? placeholders and bind values into parts and values. Mojo::SQL::Statement values are spliced in recursively, allowing partial statements to be composed. Literal question marks can be escaped with ??. π¦
parse_unsafe
$stmt = $stmt->parse_unsafe("AND role = 'admin'");
$stmt = $stmt->parse_unsafe('AND ?', "role = 'admin'");
Parse an SQL string where every ? slot is replaced literally by the corresponding value. The result has no placeholders or bind values. π
β οΈ use with care, bestie: make sure to escape values yourself with the appropriate escaping functions for your database. Literal question marks can be escaped with ??. π
to_array
my $array = $stmt->to_array;
my $array = $stmt->to_array({placeholder => '?'});
Render the statement to an array reference containing the SQL text and bind values, ready to be passed to a database driver. Accepts the same options as to_query. π
to_list
my @list = $stmt->to_list;
my @list = $stmt->to_list({placeholder => '?'});
Same as to_array but returns a list. π
to_query
my $query = $stmt->to_query;
my $query = $stmt->to_query({placeholder => '?'});
Render the statement to a query hash reference with text and values keys, ready to be passed to a database driver. π₯
These options are currently available:
placeholder => '?'
placeholderβ placeholder character to use; defaults to numbered placeholders like$1and$2. β¨
to_string
my $string = $stmt->to_string;
my $string = $stmt->to_string({placeholder => '?'});
Render just the SQL string portion of the statement. Accepts the same options as to_query. πΈ
π SEE ALSO π
Go say hi to Mojo::SQL, Mojolicious, and <https://mojolicious.org>. π
π cute sign-off: this page is from perl v5.42.2, dated 2026-05-13, and it's Mojo::S...atement(3). mwah π
π¦ where this page comes from
- alpine 3.24: perl-mojo-sql-doc 0.02-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms