db
20 items · generated by scribe fromstdlib/db.fd· synced 2026-11-15
Contents
- MemoryDB (impl)
- new (function)
- Database (impl)
- query_one (function)
- query_scalar (function)
- insert (function)
- delete (function)
- update (function)
- query_builder (function)
- qb_param (function)
- qb_param_i64 (function)
- build_insert (function)
- build_select (function)
- build_update (function)
- build_delete (function)
- get_schema (function)
- table_exists (function)
- create_table (function)
MemoryDB
impl MemoryDB {Defined at line 34
new
Convenience function — alias for MemoryDB::new()
pub fn new() -> MemoryDB {Returns: MemoryDB
Defined at line 45
Database
impl Database for MemoryDB {Defined at line 49
query_one
Helper: query a single row as a JSON object. Returns "" if no rows.
pub fn query_one<T: Database>(db: T, sql: str) -> str {Parameters:
db:Tsql:str
Returns: str
Defined at line 64
query_scalar
Helper: query a scalar value (first column of first row).
pub fn query_scalar<T: Database>(db: T, sql: str) -> str {Parameters:
db:Tsql:str
Returns: str
Defined at line 74
insert
Helper: execute an INSERT statement and return the number of rows affected.
pub fn insert<T: Database>(db: T, table: str, values: str) -> i64 {Parameters:
db:Ttable:strvalues:str
Returns: i64
Defined at line 86
delete
Helper: execute a DELETE statement and return rows affected.
pub fn delete<T: Database>(db: T, table: str, condition: str) -> i64 {Parameters:
db:Ttable:strcondition:str
Returns: i64
Defined at line 93
update
Helper: execute an UPDATE statement and return rows affected.
pub fn update<T: Database>(db: T, table: str, set_clause: str, condition: str) -> i64 {Parameters:
db:Ttable:strset_clause:strcondition:str
Returns: i64
Defined at line 100
query_builder
Typed query builder — builds SQL queries with type-safe parameters. Parameters are passed as JSON to avoid SQL injection.
Example (native only): use db; var conn = db::new(); var qb = query_builder(“SELECT * FROM users WHERE id = ?”); qb = qb_param(qb, “1”); var rows = conn.query(qb);
pub fn query_builder(sql: str) -> str {Parameters:
sql:str
Returns: str
Defined at line 126
qb_param
Add a parameter to a query builder. Returns the updated query. In a full implementation, this would use prepared statements. For now, it does simple string substitution (safe for integer params).
pub fn qb_param(query: str, param: str) -> str {Parameters:
query:strparam:str
Returns: str
Defined at line 133
qb_param_i64
Add an integer parameter to a query builder.
pub fn qb_param_i64(query: str, param: i64) -> str {Parameters:
query:strparam:i64
Returns: str
Defined at line 145
build_insert
Build an INSERT query from a table name and column/value pairs. columns: JSON array of column names (e.g. [“name”, “age”]) values: JSON array of values (e.g. [“Alice”, 30]) Returns: INSERT INTO table (col1, col2) VALUES (val1, val2)
pub fn build_insert(table: str, columns: str, values: str) -> str {Parameters:
table:strcolumns:strvalues:str
Returns: str
Defined at line 153
build_select
Build a SELECT query from a table name and optional columns. columns: JSON array of column names, or "" for * where_clause: optional WHERE clause (e.g. “id = 1”), or "" Returns: SELECT col1, col2 FROM table [WHERE clause]
pub fn build_select(table: str, columns: str, where_clause: str) -> str {Parameters:
table:strcolumns:strwhere_clause:str
Returns: str
Defined at line 181
build_update
Build an UPDATE query from a table name, SET clause, and WHERE clause.
pub fn build_update(table: str, set_clause: str, where_clause: str) -> str {Parameters:
table:strset_clause:strwhere_clause:str
Returns: str
Defined at line 204
build_delete
Build a DELETE query from a table name and WHERE clause.
pub fn build_delete(table: str, where_clause: str) -> str {Parameters:
table:strwhere_clause:str
Returns: str
Defined at line 213
get_schema
Get the schema of a table as JSON. Returns: [{“name”: “id”, “type”: “INTEGER”}, {“name”: “name”, “type”: “TEXT”}, …]
pub fn get_schema<T: Database>(db: T, table: str) -> str {Parameters:
db:Ttable:str
Returns: str
Defined at line 230
table_exists
Check if a table exists.
pub fn table_exists<T: Database>(db: T, table: str) -> bool {Parameters:
db:Ttable:str
Returns: bool
Defined at line 235
create_table
Create a table from a schema definition. schema: JSON array of column definitions [{“name”: “id”, “type”: “INTEGER PRIMARY KEY”}, {“name”: “name”, “type”: “TEXT”}]
pub fn create_table<T: Database>(db: T, table: str, schema: str) -> i64 {Parameters:
db:Ttable:strschema:str
Returns: i64
Defined at line 243
Generated by scribe, the Fides documentation generator