Skip to content

stdlib/dbView source ↗

db

20 items · generated by scribe fromstdlib/db.fd· synced 2026-11-15

stdlib/db20 items

Contents

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: T
  • sql: 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: T
  • sql: 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: T
  • table: str
  • values: 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: T
  • table: str
  • condition: 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: T
  • table: str
  • set_clause: str
  • condition: 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: str
  • param: 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: str
  • param: 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: str
  • columns: str
  • values: 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: str
  • columns: str
  • where_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: str
  • set_clause: str
  • where_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: str
  • where_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: T
  • table: 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: T
  • table: 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: T
  • table: str
  • schema: str

Returns: i64

Defined at line 243


Generated by scribe, the Fides documentation generator