Skip to main content

Module sql

Module sql 

Source
Expand description

What kind of answer an SQL statement expects, from its leading keyword.

The SQL servers (postgresql, mysql) hand the model the statement text and three ways to answer it: a result set, a command tag / OK packet, or an error. The real-model eval showed a small model answering SELECT current_user with the command tag INSERT 0 1 — copied from the ok action’s example — so the client got “INSERT 0 1” for a query that asked for a value. Both servers know the statement exactly, so each tells the model which shape answers it (answer_with in the event) instead of leaving it to map SQL to the wire in its head.

This is a classifier over the first keyword, not a parser: it reads past leading whitespace, -- and /* */ comments and opening parentheses, and nothing else. A statement it cannot place is StatementShape::Unknown, and the caller says nothing rather than guess.

Enums§

StatementShape
The answer a statement’s leading keyword calls for.

Functions§

statement_shape
Classify sql by its first keyword. See the module docs for what “first” means.