Overview
Concrete tool for parsing keyword arguments from MessagePack RPC calls provided by the sqmeow-core engine.
Description
The Args struct holds the argument table for one RPC call, decoded from a MessagePack map sent by Lua. It provides typed accessors for required and optional values: strings, integers, booleans, string arrays, and connection/call identifiers. Required accessors return named errors when values are missing or wrong-typed; optional accessors tolerate absence and wrong types silently. Callers should choose the strict accessor whenever silently ignoring a malformed value could change behavior or permissions.
Usage
- Connection lifecycle:
Args::string reads required fields like "url", "id" from connection RPC calls.
- Query execution:
Args::string reads "sql", Args::opt_usize reads "line" for cursor-based statement selection.
- In-grid editing:
Args::call_id reads the result to edit, Args::opt_strings reads approved DML statements for review.
- Result export:
Args::opt_strings reads column selections, Args::opt_bool reads format options.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-core/src/server/args.rs
- Lines: L12-106
Signature
pub struct Args {
entries: Vec<(String, Value)>,
}
impl Args {
pub fn from_params(params: &[Value]) -> Result<Self, String>;
pub fn get(&self, key: &str) -> Option<&Value>;
pub fn string(&self, key: &str) -> Result<String, String>;
pub fn opt_string(&self, key: &str) -> Option<String>;
pub fn opt_integer(&self, key: &str) -> Option<i64>;
pub fn opt_usize(&self, key: &str) -> Option<usize>;
pub fn opt_bool(&self, key: &str) -> Option<bool>;
pub fn opt_strings(&self, key: &str) -> Result<Option<Vec<String>>, String>;
pub fn integer(&self, key: &str) -> Result<i64, String>;
// Extension methods (in params.rs):
pub fn call_id(&self) -> Result<CallId, String>;
pub fn conn_id(&self, key: &str) -> Result<ConnId, String>;
}
Import
use crate::server::args::Args;
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| params |
&[Value] |
Yes |
MessagePack method parameters (first element is the argument map)
|
| key |
&str |
Yes |
Argument key name to read
|
Outputs
| Name |
Type |
Description
|
| string |
Result<String, String> |
Required string value or named error
|
| opt_string |
Option<String> |
Optional string, None if absent or wrong type
|
| opt_strings |
Result<Option<Vec<String>>, String> |
Optional string array, error on non-string items
|
| call_id |
Result<CallId, String> |
Required CallId (u64) from "call_id" key
|
| conn_id |
Result<ConnId, String> |
Required ConnId (i64) from named key
|
Usage Examples
Reading connection arguments
let args = Args::from_params(¶ms)?;
let url = args.string("url")?; // Required, errors if missing
let name = args.opt_string("name"); // Optional, None if absent
let read_only = args.opt_bool("read_only").unwrap_or(false);
Reading call and connection IDs
let call_id = args.call_id()?; // Reads "call_id" as u64
let conn_id = args.conn_id("conn_id")?; // Reads named key as i64
Reading approved edit statements
let statements = args.opt_strings("statements")?
.unwrap_or_default(); // None or empty table → empty vec
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.