Mojo::S...atement(3)

πŸ“¦ version 0.02, in alpine 3.24

✨ 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 $1 and $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