Refactor executable library handbooks and improve document reading

This commit is contained in:
cflmy committed 2026-11-08 22:19:11 +08:00
1 parent 16c44588d5
commit c50c515c4a
191 files changed
+29572 -7816

No files matched your search

+94 -25
View File
@@ -8,55 +8,124 @@ import:
table: lib/table.mq.md
---
Cache values belong to the selected backend and process lifetime. Use memory: only for process-local demonstration; choose and configure persistent backends explicitly. [The data entry](index.mq.md) demonstrates set, get and deletion through one receiver. Retain native ok/error fields and expiry behavior when extending this leaf; a cache miss is not evidence that a remote write succeeded.
## _load
**p = > plugin.native_path name="web"**
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
1. `p`
> plugin.load path=`p`
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
2. *
> print text=ext/data: native web plugin not found
> sys.exit code=1
****
We **[Print the prepared message](print(text="ext/data: native web plugin not found"))**.
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
# cache
+ `url`="memory:"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | any | "memory:" | Resource connection URL; scheme selects the documented backend |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Key–value cache. Use `memory:` for in-process (tests / single process) or `redis://host:6379/0` for Redis. |
Use `url`="memory:" as the inputs for this operation.
Key–value cache. Use `memory:` for in-process (tests / single process) or `redis://host:6379/0` for Redis.
> _load
*> web_cache_new url=`url`*
We **[Load the native plugin required by this operation](_load())**.
Return *[Key–value cache. Use memory: for in-process (tests / single process) or redis://host:6379/0 for Redis.](web_cache_new(url=`url`))*.
## get
+ `key`
**url = [url](access(self, "url"))**
*> web_cache_get url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read the cached value associated with a key; a miss is reported by the cache result. |
Use `key` as the inputs for this operation.
Read the cached value associated with a key; a miss is reported by the cache result.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Read the cached value associated with a key; a miss is reported by the cache result.](web_cache_get(url=`url`, key=`key`))*.
## set
+ `key`
+ `value`
+ `ttl`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| value | any | required | Value supplied to this operation; immutable transformations return a new value |
| ttl | any | None | Expiry duration in seconds; None uses the backend default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Optional `ttl` is seconds until expiry. |
Use `key`, `value`, `ttl`=None as the inputs for this operation.
Optional `ttl` is seconds until expiry.
**url = [url](access(self, "url"))**
*> web_cache_set url=`url` key=`key` value=`value` ttl=`ttl`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Optional ttl is seconds until expiry.](web_cache_set(url=`url`, key=`key`, value=`value`, ttl=`ttl`))*.
## del
+ `key`
**url = [url](access(self, "url"))**
*> web_cache_del url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delete a cached key without changing other entries. |
Use `key` as the inputs for this operation.
Delete a cached key without changing other entries.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Delete a cached key without changing other entries.](web_cache_del(url=`url`, key=`key`))*.
## exists
+ `key`
**url = [url](access(self, "url"))**
*> web_cache_exists url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Test whether the cache currently holds the selected key. |
Use `key` as the inputs for this operation.
Test whether the cache currently holds the selected key.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Test whether the cache currently holds the selected key.](web_cache_exists(url=`url`, key=`key`))*.
## ttl
+ `key`
**url = [url](access(self, "url"))**
*> web_cache_ttl url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read the remaining lifetime of a cached key using the backend TTL convention. |
Use `key` as the inputs for this operation.
Read the remaining lifetime of a cached key using the backend TTL convention.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Read the remaining lifetime of a cached key using the backend TTL convention.](web_cache_ttl(url=`url`, key=`key`))*.
+376 -131
View File
@@ -8,246 +8,491 @@ import:
table: lib/table.mq.md
---
Database receivers own a connection URL. Begin a transaction with the database receiver, use its returned identifier for transaction operations, then commit or roll back explicitly. Read [the data workflow](index.mq.md) for a real isolated SQLite example and temporary-directory ownership. Native URLs resolve differently from filesystem helpers: validate an absolute SQLite path inside the granted root before passing it to the plugin. New query behavior belongs in the native web database implementation; schema and filters remain readable tables here.
## _load
**p = > plugin.native_path name="web"**
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
1. `p`
> plugin.load path=`p`
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
2. *
> print text=ext/data: native web plugin not found
> sys.exit code=1
****
We **[Print the prepared message](print(text="ext/data: native web plugin not found"))**.
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
# db
+ `url`="sqlite:site.db"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | any | "sqlite:site.db" | Resource connection URL; scheme selects the documented backend |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Open a database handle. URL schemes: `sqlite:path` (default), `postgres://…` / `postgresql://…` (same CRUD methods). |
Use `url`="sqlite:site.db" as the inputs for this operation.
Open a database handle. URL schemes: `sqlite:path` (default), `postgres://…` / `postgresql://…` (same CRUD methods).
> _load
*> web_db_new url=`url`*
We **[Load the native plugin required by this operation](_load())**.
Return *[Open a database handle. URL schemes: sqlite:path (default), postgres://… / postgresql://… (same CRUD methods).](web_db_new(url=`url`))*.
## init
+ `name`
+ `fields`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | any | required | Name registered or looked up by this operation |
| fields | any | required | Readable field definitions with the columns described by this resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Create a table from a schema table. Optional columns: `唯一`/`unique`, `索引`/`index` (creates UNIQUE / INDEX), `外键`/`fk`/`references` (e.g. `posts.id` or `posts(id)`). Columns named `created_at` / `updated_at` are filled automatically on insert/update when present. |
Use `name`, `fields` as the inputs for this operation.
Create a table from a schema table. Optional columns: `唯一`/`unique`, `索引`/`index` (creates UNIQUE / INDEX), `外键`/`fk`/`references` (e.g. `posts.id` or `posts(id)`). Columns named `created_at` / `updated_at` are filled automatically on insert/update when present.
**url = [url](access(self, "url"))**
*> web_db_init url=`url` name=`name` fields=`fields`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Create a table from a schema table](web_db_init(url=`url`, name=`name`, fields=`fields`))*.
## insert
+ `table`
+ `rows`
+ `txn`=None
**url = [url](access(self, "url"))**
*> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| rows | any | required | Input row records to insert or process |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Insert the supplied row records, optionally within the selected open transaction. |
Use `table`, `rows`, `txn`=None as the inputs for this operation.
Insert the supplied row records, optionally within the selected open transaction.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Insert the supplied row records, optionally within the selected open transaction.](web_db_insert(url=`url`, table=`table`, rows=`rows`, txn=`txn`))*.
## select
+ `table`
+ `where`=None
+ `limit`=200
+ `order`=None
+ `txn`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| where | any | None | Explicit filter map or comparison-row table; omitted means no extra filter |
| limit | any | 200 | Maximum returned entries or candidates; this is not a success threshold |
| order | any | None | Field order specification, with a leading minus for descending database order |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Simple filters: one-row map of column→value (AND `=`), or rows `&#124;字段&#124;操作&#124;值&#124;` (`=` `!=` `>` `>=` `<` `<=` `like` `in` `between` `is null`; add `&#124;或&#124;` = `是` to join a row with `OR`). `order` is a column name with optional `-` prefix for descending (`"created_at"`, `"-created_at"`), comma-separated for multiple keys. Pass `txn` to read inside an open transaction. For pages (with a total), use `paginate`. |
Use `table`, `where`=None, `limit`=200, `order`=None, `txn`=None as the inputs for this operation.
Simple filters: one-row map of column→value (AND `=`), or rows `|字段|操作|值|` (`=` `!=` `>` `>=` `<` `<=` `like` `in` `between` `is null`; add `|或|` = `是` to join a row with `OR`). `order` is a column name with optional `-` prefix for descending (`"created_at"`, `"-created_at"`), comma-separated for multiple keys. Pass `txn` to read inside an open transaction. For pages (with a total), use `paginate`.
**url = [url](access(self, "url"))**
**r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`**
*[rows](access(r, "rows"))*
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`r` = [Simple filters: one-row map of column→value (AND =), or rows |字段|操作|值| (= != > >= < <= like in between is null; add |或| = 是 to join a row with OR)](web_db_select(url=`url`, table=`table`, where=`where`, limit=`limit`, order=`order`, offset=None, txn=`txn`))**.
Return *[rows](access(r, "rows"))*.
## paginate
+ `table`
+ `where`=None
+ `limit`=200
+ `order`=None
+ `跳过`=0
+ `txn`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| where | any | None | Explicit filter map or comparison-row table; omitted means no extra filter |
| limit | any | 200 | Maximum returned entries or candidates; this is not a success threshold |
| order | any | None | Field order specification, with a leading minus for descending database order |
| 跳过 | any | 0 | Number of matching rows skipped before the database page |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Like `select` but returns `{ rows, total }` — the total counts rows matching `where` regardless of `limit`/`跳过`, so you can render `上一页 / 下一页`. Set `跳过` to the number of rows to skip (e.g. page 2 with 10 per page ⇒ `跳过`=10). |
Use `table`, `where`=None, `limit`=200, `order`=None, `跳过`=0, `txn`=None as the inputs for this operation.
Like `select` but returns `{ rows, total }` — the total counts rows matching `where` regardless of `limit`/`跳过`, so you can render `上一页 / 下一页`. Set `跳过` to the number of rows to skip (e.g. page 2 with 10 per page ⇒ `跳过`=10).
**url = [url](access(self, "url"))**
*> web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=`跳过` txn=`txn`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Like select but returns { rows, total } — the total counts rows matching where regardless of limit/跳过, so you can render 上一页 / 下一页](web_db_select(url=`url`, table=`table`, where=`where`, limit=`limit`, order=`order`, offset=`跳过`, txn=`txn`))*.
## get
+ `table`
+ `id`
+ `txn`=None
**url = [url](access(self, "url"))**
*> web_db_get url=`url` table=`table` id=`id` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read a single row by its identifier from the selected database table. |
Use `table`, `id`, `txn`=None as the inputs for this operation.
Read a single row by its identifier from the selected database table.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Read a single row by its identifier from the selected database table.](web_db_get(url=`url`, table=`table`, id=`id`, txn=`txn`))*.
## update
+ `table`
+ `id`
+ `row`
+ `txn`=None
**url = [url](access(self, "url"))**
*> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| row | any | required | Field/value record to apply to the selected row |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Update the supplied fields of the selected row; use update_if when a revision comparison is required. |
Use `table`, `id`, `row`, `txn`=None as the inputs for this operation.
Update the supplied fields of the selected row; use update_if when a revision comparison is required.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Update the supplied fields of the selected row; use update_if when a revision comparison is required.](web_db_update(url=`url`, table=`table`, id=`id`, row=`row`, txn=`txn`))*.
## update_if
+ `table`
+ `id`
+ `row`
+ `expect_col`
+ `expect_val`
+ `txn`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| row | any | required | Field/value record to apply to the selected row |
| expect_col | any | required | Column checked atomically in the conditional database update |
| expect_val | any | required | Expected current value of the comparison column |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Conditional update (CAS) for task/revision control: `UPDATE … WHERE id=? AND expect_col=expect_val`. Returns `{ ok, updated, matched }`; `updated=0` means conflict — do not simulate atomicity with read-then-write in `.mq.md`. |
Use `table`, `id`, `row`, `expect_col`, `expect_val`, `txn`=None as the inputs for this operation.
Conditional update (CAS) for task/revision control: `UPDATE … WHERE id=? AND expect_col=expect_val`. Returns `{ ok, updated, matched }`; `updated=0` means conflict — do not simulate atomicity with read-then-write in `.mq.md`.
**url = [url](access(self, "url"))**
*> web_db_update_if url=`url` table=`table` id=`id` row=`row` expect_col=`expect_col` expect_val=`expect_val` txn=`txn`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Conditional update (CAS) for task/revision control: UPDATE … WHERE id=? AND expect_col=expect_val](web_db_update_if(url=`url`, table=`table`, id=`id`, row=`row`, expect_col=`expect_col`, expect_val=`expect_val`, txn=`txn`))*.
## delete
+ `table`
+ `id`
+ `txn`=None
**url = [url](access(self, "url"))**
*> web_db_delete url=`url` table=`table` id=`id` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delete the selected row, optionally inside the caller-owned transaction. |
Use `table`, `id`, `txn`=None as the inputs for this operation.
Delete the selected row, optionally inside the caller-owned transaction.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Delete the selected row, optionally inside the caller-owned transaction.](web_db_delete(url=`url`, table=`table`, id=`id`, txn=`txn`))*.
## exec
+ `sql`
+ `args`=None
+ `txn`=None
**url = [url](access(self, "url"))**
*> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sql | any | required | SQL statement; dynamic values belong in bound args rather than concatenated SQL |
| args | any | None | Arguments passed to the selected command or operation |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Execute SQL with bound arguments and return the native execution outcome. |
Use `sql`, `args`=None, `txn`=None as the inputs for this operation.
Execute SQL with bound arguments and return the native execution outcome.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Execute SQL with bound arguments and return the native execution outcome.](web_db_exec(url=`url`, sql=`sql`, args=`args`, txn=`txn`))*.
## query
+ `sql`
+ `args`=None
+ `txn`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sql | any | required | SQL statement; dynamic values belong in bound args rather than concatenated SQL |
| args | any | None | Arguments passed to the selected command or operation |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run bare SQL and return the result set — count / join / group / subqueries. Returns `{ rows, count }`. |
Use `sql`, `args`=None, `txn`=None as the inputs for this operation.
Run bare SQL and return the result set — count / join / group / subqueries. Returns `{ rows, count }`.
**url = [url](access(self, "url"))**
*> web_db_query url=`url` sql=`sql` args=`args` txn=`txn`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Run bare SQL and return the result set — count / join / group / subqueries. Returns { rows, count }.](web_db_query(url=`url`, sql=`sql`, args=`args`, txn=`txn`))*.
## count
+ `table`
+ `where`=None
+ `txn`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| where | any | None | Explicit filter map or comparison-row table; omitted means no extra filter |
| txn | any | None | Open transaction returned by the same database resource; None runs outside a transaction |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Count rows matching a `where` filter (same syntax as `select`). Returns a number. |
Use `table`, `where`=None, `txn`=None as the inputs for this operation.
Count rows matching a `where` filter (same syntax as `select`). Returns a number.
**url = [url](access(self, "url"))**
**r = > web_db_count url=`url` table=`table` where=`where` txn=`txn`**
*[count](access(r, "count"))*
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`r` = [Count rows matching a where filter (same syntax as select). Returns a number.](web_db_count(url=`url`, table=`table`, where=`where`, txn=`txn`))**.
Return *[count](access(r, "count"))*.
## migrate
+ `steps`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| steps | any | required | Ordered migration or operation records in the documented table shape |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Apply versioned SQL migrations. `steps` is a `&#124;version&#124;sql&#124;` / `&#124;版本&#124;SQL&#124;` table. Applied versions are recorded in `_marqdo_migrations`. Re-running is a no-op for already-applied versions. SQLite only. |
Use `steps` as the inputs for this operation.
Apply versioned SQL migrations. `steps` is a `|version|sql|` / `|版本|SQL|` table. Applied versions are recorded in `_marqdo_migrations`. Re-running is a no-op for already-applied versions. SQLite only.
**url = [url](access(self, "url"))**
*> web_db_migrate url=`url` steps=`steps`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Apply versioned SQL migrations](web_db_migrate(url=`url`, steps=`steps`))*.
## fts
+ `table`
+ `columns`
+ `name`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| columns | any | required | Column-name list or column definitions required by this operation |
| name | any | None | Name registered or looked up by this operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Create an FTS5 index on `table` for the listed content columns (CSV string or list). Default FTS name is `{table}_fts`. Keeps the index in sync via triggers. Requires integer `id` PK. SQLite only. |
Use `table`, `columns`, `name`=None as the inputs for this operation.
Create an FTS5 index on `table` for the listed content columns (CSV string or list). Default FTS name is `{table}_fts`. Keeps the index in sync via triggers. Requires integer `id` PK. SQLite only.
**url = [url](access(self, "url"))**
*> web_db_fts_create url=`url` table=`table` columns=`columns` name=`name`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Create an FTS5 index on table for the listed content columns (CSV string or list)](web_db_fts_create(url=`url`, table=`table`, columns=`columns`, name=`name`))*.
## search
+ `table`
+ `q`
+ `limit`=20
+ `name`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| q | any | required | Full-text search query |
| limit | any | 20 | Maximum returned entries or candidates; this is not a success threshold |
| name | any | None | Name registered or looked up by this operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Full-text search (`MATCH`) against the FTS5 index from `fts`. Returns `{ rows, count }` with a `rank` column (bm25). SQLite only. |
Use `table`, `q`, `limit`=20, `name`=None as the inputs for this operation.
Full-text search (`MATCH`) against the FTS5 index from `fts`. Returns `{ rows, count }` with a `rank` column (bm25). SQLite only.
**url = [url](access(self, "url"))**
*> web_db_search url=`url` table=`table` q=`q` limit=`limit` name=`name`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Full-text search (MATCH) against the FTS5 index from fts. Returns { rows, count } with a rank column (bm25). SQLite only.](web_db_search(url=`url`, table=`table`, q=`q`, limit=`limit`, name=`name`))*.
## 事务
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Begin a transaction: borrows the pooled connection exclusively and returns a Every statement runs on the same connection, so a batch is atomic. |
Begin a transaction: borrows the pooled connection exclusively and returns a
`txn` handle. Write inside it, then `提交` (commit) or `回滚` (roll back).
Every statement runs on the same connection, so a batch is atomic.
**url = [url](access(self, "url"))**
*> web_db_begin url=`url`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Begin a transaction: borrows the pooled connection exclusively and returns a Every statement runs on the same connection, so a batch is atomic.](web_db_begin(url=`url`))*.
# txn
+ `txn`
+ `url`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| txn | any | required | Open transaction returned by the same database resource; None runs outside a transaction |
| url | any | required | Resource connection URL; scheme selects the documented backend |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | A transaction handle from `db.事务`. All CRUD here runs on the transaction's connection; finish with `提交` or `回滚`. The transaction identifier and connection URL remain explicit fields for every method. |
Use `txn`, `url` as the inputs for this operation.
A transaction handle from `db.事务`. All CRUD here runs on the transaction's
connection; finish with `提交` or `回滚`.
*self*
The transaction identifier and connection URL remain explicit fields for every method.
`handle` =
| txn | url |
|---|---|
| `txn` | `url` |
Return *handle*.
## insert
+ `table`
+ `rows`
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
*> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| rows | any | required | Input row records to insert or process |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delegate to web_db_insert with the supplied inputs, preserving its result and failure behavior. |
Use `table`, `rows` as the inputs for this operation.
Delegate to web_db_insert with the supplied inputs, preserving its result and failure behavior.
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Delegate to web_db_insert with the supplied inputs, preserving its result and failure behavior.](web_db_insert(url=`url`, table=`table`, rows=`rows`, txn=`txn`))*.
## select
+ `table`
+ `where`=None
+ `limit`=200
+ `order`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| where | any | None | Explicit filter map or comparison-row table; omitted means no extra filter |
| limit | any | 200 | Maximum returned entries or candidates; this is not a success threshold |
| order | any | None | Field order specification, with a leading minus for descending database order |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Same filters as `db.select`; runs inside the transaction. |
Use `table`, `where`=None, `limit`=200, `order`=None as the inputs for this operation.
Same filters as `db.select`; runs inside the transaction.
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
**r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`**
*[rows](access(r, "rows"))*
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
We retain **`r` = [Same filters as db.select; runs inside the transaction.](web_db_select(url=`url`, table=`table`, where=`where`, limit=`limit`, order=`order`, offset=None, txn=`txn`))**.
Return *[rows](access(r, "rows"))*.
## get
+ `table`
+ `id`
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
*> web_db_get url=`url` table=`table` id=`id` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delegate to web_db_get with the supplied inputs, preserving its result and failure behavior. |
Use `table`, `id` as the inputs for this operation.
Delegate to web_db_get with the supplied inputs, preserving its result and failure behavior.
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Delegate to web_db_get with the supplied inputs, preserving its result and failure behavior.](web_db_get(url=`url`, table=`table`, id=`id`, txn=`txn`))*.
## update
+ `table`
+ `id`
+ `row`
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
*> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| row | any | required | Field/value record to apply to the selected row |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delegate to web_db_update with the supplied inputs, preserving its result and failure behavior. |
Use `table`, `id`, `row` as the inputs for this operation.
Delegate to web_db_update with the supplied inputs, preserving its result and failure behavior.
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Delegate to web_db_update with the supplied inputs, preserving its result and failure behavior.](web_db_update(url=`url`, table=`table`, id=`id`, row=`row`, txn=`txn`))*.
## delete
+ `table`
+ `id`
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
*> web_db_delete url=`url` table=`table` id=`id` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | required | Database table name or form submission table |
| id | any | required | Identifier produced or selected by the corresponding resource operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delegate to web_db_delete with the supplied inputs, preserving its result and failure behavior. |
Use `table`, `id` as the inputs for this operation.
Delegate to web_db_delete with the supplied inputs, preserving its result and failure behavior.
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Delegate to web_db_delete with the supplied inputs, preserving its result and failure behavior.](web_db_delete(url=`url`, table=`table`, id=`id`, txn=`txn`))*.
## exec
+ `sql`
+ `args`=None
**url = [url](access(self, "url"))**
**txn = [txn](access(self, "txn"))**
*> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sql | any | required | SQL statement; dynamic values belong in bound args rather than concatenated SQL |
| args | any | None | Arguments passed to the selected command or operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delegate to web_db_exec with the supplied inputs, preserving its result and failure behavior. |
Use `sql`, `args`=None as the inputs for this operation.
Delegate to web_db_exec with the supplied inputs, preserving its result and failure behavior.
We retain **`url` = [Read url field](access(`self`, "url"))**.
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Delegate to web_db_exec with the supplied inputs, preserving its result and failure behavior.](web_db_exec(url=`url`, sql=`sql`, args=`args`, txn=`txn`))*.
## 提交
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Commit the transaction and return its connection to the pool. |
Commit the transaction and return its connection to the pool.
**txn = [txn](access(self, "txn"))**
*> web_db_commit txn=`txn`*
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Commit the transaction and return its connection to the pool.](web_db_commit(txn=`txn`))*.
## 回滚
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Roll the transaction back (undo every write) and return its connection. |
Roll the transaction back (undo every write) and return its connection.
**txn = [txn](access(self, "txn"))**
*> web_db_rollback txn=`txn`*
We retain **`txn` = [Read txn field](access(`self`, "txn"))**.
Return *[Roll the transaction back (undo every write) and return its connection.](web_db_rollback(txn=`txn`))*.
+109 -29
View File
@@ -8,62 +8,142 @@ import:
table: lib/table.mq.md
---
This leaf projects form schema and submission operations through the native web runtime. Read [the data entry](index.mq.md) before connecting a form to persistent storage. Schema validation and route authorization are different responsibilities: an accepted field value does not authenticate its submitter. Keep schema rows, validation failures and persistence results visible when changing this resource.
## _load
**p = > plugin.native_path name="web"**
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
1. `p`
> plugin.load path=`p`
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
2. *
> print text=ext/data: native web plugin not found
> sys.exit code=1
****
We **[Print the prepared message](print(text="ext/data: native web plugin not found"))**.
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
# form
+ `table`=None
+ `action`=insert
+ `id`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| table | any | None | Database table name or form submission table |
| action | any | "insert" | Form submission action such as insert or update |
| id | any | None | Identifier produced or selected by the corresponding resource operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Field table + rules table; submit writes through `# db`. |
Use `table`=None, `action`="insert", `id`=None as the inputs for this operation.
Field table + rules table; submit writes through `# db`.
> _load
*> web_form_new table=`table` action=`action` id=`id`*
We **[Load the native plugin required by this operation](_load())**.
Return *[Field table + rules table; submit writes through # db.](web_form_new(table=`table`, action=`action`, id=`id`))*.
## fields
+ `fields`
*> web_form_fields form=`self` fields=`fields`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| fields | any | required | Readable field definitions with the columns described by this resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Attach the readable field definitions to this form and return the updated resource. |
Use `fields` as the inputs for this operation.
Attach the readable field definitions to this form and return the updated resource.
Return *[Attach the readable field definitions to this form and return the updated resource.](web_form_fields(form=`self`, fields=`fields`))*.
## rules
+ `rules`
*> web_form_rules form=`self` rules=`rules`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| rules | any | required | Readable validation-rule records |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Attach validation rules to this form without submitting user data. |
Use `rules` as the inputs for this operation.
Attach validation rules to this form without submitting user data.
Return *[Attach validation rules to this form without submitting user data.](web_form_rules(form=`self`, rules=`rules`))*.
## labels
+ `submit`="Submit"
+ `cancel`="cancel"
+ `cancel_href`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| submit | any | "Submit" | Displayed submit-button label |
| cancel | any | "cancel" | Displayed cancel-button label |
| cancel_href | any | "" | Navigation target of the cancel action |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Localized submit / cancel copy for rendered forms. |
Use `submit`="Submit", `cancel`="cancel", `cancel_href`="" as the inputs for this operation.
Localized submit / cancel copy for rendered forms.
*> web_form_labels form=`self` submit=`submit` cancel=`cancel` cancel_href=`cancel_href`*
Return *[Localized submit / cancel copy for rendered forms.](web_form_labels(form=`self`, submit=`submit`, cancel=`cancel`, cancel_href=`cancel_href`))*.
## validate
+ `rules`=None
+ `data`
*> web_form_validate form=`self` rules=`rules` data=`data`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| rules | any | None | Readable validation-rule records |
| data | any | required | Structured input supplied to this adapter or resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Validate supplied field values and return the native validation result; this does not submit to the database. |
Use `rules`=None, `data` as the inputs for this operation.
Validate supplied field values and return the native validation result; this does not submit to the database.
Return *[Validate supplied field values and return the native validation result; this does not submit to the database.](web_form_validate(form=`self`, rules=`rules`, data=`data`))*.
## render
+ `id`=form
+ `data`=None
+ `errors`=None
*> web_form_render form=`self` id=`id` data=`data` errors=`errors`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | "form" | Identifier produced or selected by the corresponding resource operation |
| data | any | None | Structured input supplied to this adapter or resource |
| errors | any | None | Field/error record returned by validation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Render this form using its data and field errors; rendering is separate from database submission. |
Use `id`="form", `data`=None, `errors`=None as the inputs for this operation.
Render this form using its data and field errors; rendering is separate from database submission.
Return *[Render this form using its data and field errors; rendering is separate from database submission.](web_form_render(form=`self`, id=`id`, data=`data`, errors=`errors`))*.
## submit
+ `data`
+ `db`
**url = [url](access(db, "url"))**
*> web_form_submit form=`self` data=`data` url=`url`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data | any | required | Structured input supplied to this adapter or resource |
| db | any | required | Database resource created by the public database constructor |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Submit validated form data through the selected database resource and configured action. |
Use `data`, `db` as the inputs for this operation.
Submit validated form data through the selected database resource and configured action.
We retain **`url` = [Read url field](access(`db`, "url"))**.
Return *[Submit validated form data through the selected database resource and configured action.](web_form_submit(form=`self`, data=`data`, url=`url`))*.
+121
View File
@@ -0,0 +1,121 @@
---
markup: occlusion
title: Data resources — database, cache, storage and forms
import:
cache_api: ext/data/cache.mq.md
db_api: ext/data/db.mq.md
fs: lib/fs.mq.md
path: lib/path.mq.md
---
Start here when a program needs persistent records, short-lived values, object storage or forms.
The public resource files remain the implementation: [database](db.mq.md) owns schemas and
transactions, [cache](cache.mq.md) owns expiry, [storage](storage.mq.md) owns blobs and upload
validation, and [forms](form.mq.md) separates validation, rendering and submission.
These modules use the native web plugin. In this source checkout build it with
scripts/build-web-plugin.sh; installed packages follow the web package installation route.
Commands below run at the repository root. The cache example uses memory only. The transaction example creates a SQLite file
in an owned temporary directory. Prepare an existing disposable directory and export MQ_WORK to its
absolute path; the transaction report returns work_dir for cleanup after this process exits.
Neither example needs a cloud account, credentials or an external service.
```sh
marqdo call ext/data/index.mq.md memory_cache 'key="manual"' 'value="ready"' --effects plugin --json
marqdo call ext/data/index.mq.md transaction_roundtrip "root=\"$MQ_WORK\"" --effects plugin,fs.write --fs-root "$MQ_WORK" --json
```
A resource constructor creates an object; its methods need that actual receiver. Use the free
workflow tools below for a single CLI call, or import the resource file and keep the object in
your program. Do not pass an instance method to call without its receiver or reconstruct a
transaction from guessed fields. Native resource URLs select their own backend: the marqdo
filesystem root does not rewrite a SQLite, S3 or Redis URL. Grant plugin access deliberately.
For development, keep backend operations in the native web resource implementation and expose
small, documented compositions here. Specify row/filter shapes, transaction ownership, conflicts,
expiry units and cleanup. Add an operation to its responsible leaf file and exercise it through
this facade or a real author program. Run the source-handbook regression and database/cache gold
cases on both backends. A successful transport record is not proof that a business update matched.
## memory_cache
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | "manual" | Key owned by this short-lived demonstration |
| value | any | "ready" | Value written and then read back from the in-process cache |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Actual cache get result; value contains the stored value |
Use `key`="manual" and `value`="ready" unless the caller supplies different data. This
workflow uses memory: storage, so values belong to the current native plugin process.
It removes its key after reading; do not use a production key for an illustrative roundtrip.
First **cache = [Create a process-local cache](cache_api.cache(url="memory:"))**.
We then **[Store the supplied value with a sixty-second expiry](> `cache`.set key=`key` value=`value` ttl=60 )**
and retain **stored = [Read the same cache entry](> `cache`.get key=`key` )**.
Once the value has been captured, **[Remove the demonstration key](> `cache`.del key=`key` )**
so another operation does not inherit it. Return *stored* as observed, including its backend fields.
## transaction_roundtrip
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| root | text | required | Absolute disposable root, matching --fs-root; native resource URLs need an absolute path |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | The committed row list and native commit/rollback outcomes; the second insert is rolled back |
Use the absolute `root` supplied for --fs-root. This isolated-file example shows the whole ownership sequence: create a schema, begin a transaction,
write through its receiver, finish it, and read outside it. A second transaction is explicitly
rolled back. The standalone txn constructor wraps the actual native identifier and connection URL;
it does not begin another transaction or invent an identifier.
First **directory = [Create an owned temporary directory under the granted root](fs.temp_dir(prefix="data-manual"))**.
The filesystem helper returns a root-relative name. We retain **work_dir = [Resolve that owned name against the explicit root](path.join(a=`root`, b=`directory`))**
and **[Check that this absolute directory is inside the granted filesystem root](fs.stat(path=`work_dir`))**
before giving any path to the native database. We select **database_path = [Choose the SQLite file inside that directory](path.join(a=`work_dir`, b="manual.db"))**
and select **database_url = "sqlite:" + database_path** before creating
the receiver **store = [Open only that explicitly selected SQLite resource](db_api.db(url=`database_url`))**.
The table schema is ordinary readable data; both columns and their nullability remain visible.
`fields` =
| 字段 | 类型 | 可空 |
|---|---|---|
| title | text | False |
| body | text | True |
We **[Create the isolated demonstration table](> `store`.init name="manual_notes" fields=`fields` )**
before borrowing the transaction connection. Next **native = [Begin the first transaction](> `store`.事务 )**.
To retain the exact identifier, **identifier = [Read the returned transaction identifier](access(native, "txn"))**
and **connection = [Read its connection URL](access(native, "url"))**.
Now **transaction = [Wrap those actual fields as a transaction receiver](db_api.txn(txn=`identifier`, url=`connection`))**.
`row` =
| title | body |
|---|---|
| committed | kept |
We **[Insert the first row inside its transaction](> `transaction`.insert table="manual_notes" rows=`row` )**
and keep **committed = [Commit that transaction](> `transaction`.提交 )**.
The second **cancelled = [Begin an independent transaction](> `store`.事务 )** is a native
transaction receiver, which can be used directly because its type and resource fields are retained.
We **[Insert a row that will be discarded](> `cancelled`.insert table="manual_notes" rows=`row` )**
then capture **rolled_back = [Roll back the second transaction](> `cancelled`.回滚 )**.
Finally **rows = [Read the committed state outside a transaction](> `store`.select table="manual_notes" order="id" )**.
`report` =
| rows | committed | rolled_back | work_dir |
|---|---|---|---|
| `rows` | `committed` | `rolled_back` | `work_dir` |
This example ends with one committed row. Real programs must also arrange rollback when a later
operation fails. This plugin pools open connections, so remove the owned work_dir only after this
CLI process exits and the connection is closed, including on failure. Do not assume sqlite::memory:
is in-memory through this ABI: relative resource paths are resolved against the module directory.
Return *report* with the real row data, completion records and cleanup location.
+128 -41
View File
@@ -8,81 +8,168 @@ import:
table: lib/table.mq.md
---
Use this resource for explicitly configured storage URLs; use lib/fs.mq.md for ordinary rooted filesystem operations. [The data entry](index.mq.md) explains resource ownership and the native web dependency. File bodies and byte encodings follow the native storage contract, so callers must inspect the returned operation result before publishing a resource URL. Add backend support in the existing plugin rather than encoding transport logic in callers.
## _load
**p = > plugin.native_path name="web"**
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
1. `p`
> plugin.load path=`p`
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
2. *
> print text=ext/data: native web plugin not found
> sys.exit code=1
****
We **[Print the prepared message](print(text="ext/data: native web plugin not found"))**.
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
# storage
+ `url`="file:data/blobs"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | any | "file:data/blobs" | Resource connection URL; scheme selects the documented backend |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Object storage. `file:dir` stores blobs on disk (offline / gold). `s3://bucket?endpoint=http://127.0.0.1:9000&access_key=…&secret_key=…` talks to MinIO / S3. |
Use `url`="file:data/blobs" as the inputs for this operation.
Object storage. `file:dir` stores blobs on disk (offline / gold). `s3://bucket?endpoint=http://127.0.0.1:9000&access_key=…&secret_key=…` talks to MinIO / S3.
> _load
*> web_storage_new url=`url`*
We **[Load the native plugin required by this operation](_load())**.
Return *[Object storage. file:dir stores blobs on disk (offline / gold). s3://bucket?endpoint=http://127.0.0.1:9000&access_key=…&secret_key=… talks to MinIO / S3.](web_storage_new(url=`url`))*.
## put
+ `key`
+ `body`=None
+ `path`=None
+ `content_type`="application/octet-stream"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| body | any | None | Object or request content, as described by the operation |
| path | any | None | Explicit filesystem path; honor the documented filesystem root and operation effects |
| content_type | any | "application/octet-stream" | MIME type associated with the supplied content |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Provide either `body` (text) or `path` (local file to upload). |
Use `key`, `body`=None, `path`=None, `content_type`="application/octet-stream" as the inputs for this operation.
Provide either `body` (text) or `path` (local file to upload).
**url = [url](access(self, "url"))**
*> web_storage_put url=`url` key=`key` body=`body` path=`path` content_type=`content_type`*
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Provide either body (text) or path (local file to upload).](web_storage_put(url=`url`, key=`key`, body=`body`, path=`path`, content_type=`content_type`))*.
## get
+ `key`
**url = [url](access(self, "url"))**
*> web_storage_get url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read the object selected by its storage key and retain the backend result shape. |
Use `key` as the inputs for this operation.
Read the object selected by its storage key and retain the backend result shape.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Read the object selected by its storage key and retain the backend result shape.](web_storage_get(url=`url`, key=`key`))*.
## delete
+ `key`
**url = [url](access(self, "url"))**
*> web_storage_delete url=`url` key=`key`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | any | required | Entry or field key within the selected resource |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Delete the selected object from this storage resource. |
Use `key` as the inputs for this operation.
Delete the selected object from this storage resource.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[Delete the selected object from this storage resource.](web_storage_delete(url=`url`, key=`key`))*.
## list
+ `prefix`=""
**url = [url](access(self, "url"))**
*> web_storage_list url=`url` prefix=`prefix`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| prefix | any | "" | Object-key or generated-name prefix |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | List object entries under the supplied key prefix. |
Use `prefix`="" as the inputs for this operation.
List object entries under the supplied key prefix.
We retain **`url` = [Read url field](access(`self`, "url"))**.
Return *[List object entries under the supplied key prefix.](web_storage_list(url=`url`, prefix=`prefix`))*.
# media
+ `storage`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| storage | any | None | Storage resource created by the public storage constructor |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Offline helpers for upload validation and saving into `# storage` (also used by HTTP `app.upload`). |
Use `storage`=None as the inputs for this operation.
Offline helpers for upload validation and saving into `# storage` (also used by HTTP `app.upload`).
> _load
*> web_media_new storage=`storage`*
We **[Load the native plugin required by this operation](_load())**.
Return *[Offline helpers for upload validation and saving into # storage (also used by HTTP app.upload).](web_media_new(storage=`storage`))*.
## validate
+ `filename`
+ `content_type`="application/octet-stream"
+ `size`
+ `max_bytes`=5242880
+ `types`=None
*> web_upload_validate filename=`filename` content_type=`content_type` size=`size` max_bytes=`max_bytes` types=`types`*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| filename | any | required | Original or suggested filename |
| content_type | any | "application/octet-stream" | MIME type associated with the supplied content |
| size | any | required | Byte size checked by upload validation |
| max_bytes | any | 5242880 | Maximum accepted byte count; exceeding the limit must fail explicitly |
| types | any | None | Allowed MIME types for upload validation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Validate an upload filename, MIME type and byte size against explicit limits before storing anything. |
Use `filename`, `content_type`="application/octet-stream", `size`, `max_bytes`=5242880, `types`=None as the inputs for this operation.
Validate an upload filename, MIME type and byte size against explicit limits before storing anything.
Return *[Validate an upload filename, MIME type and byte size against explicit limits before storing anything.](web_upload_validate(filename=`filename`, content_type=`content_type`, size=`size`, max_bytes=`max_bytes`, types=`types`))*.
## save
+ `path`
+ `key`=None
+ `content_type`="application/octet-stream"
+ `prefix`=uploads/
+ `storage`=None
**st = storage**
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | required | Explicit filesystem path; honor the documented filesystem root and operation effects |
| key | any | None | Entry or field key within the selected resource |
| content_type | any | "application/octet-stream" | MIME type associated with the supplied content |
| prefix | any | "uploads/" | Object-key or generated-name prefix |
| storage | any | None | Storage resource created by the public storage constructor |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Save the selected local upload through the configured storage resource and return its storage result. |
Use `path`, `key`=None, `content_type`="application/octet-stream", `prefix`="uploads/", `storage`=None as the inputs for this operation.
We retain **st = storage**.
1. `st` == None
**st = [storage](access(self, "storage"))**
We retain **`st` = [Read storage field](access(`self`, "storage"))**.
2. *
*> web_upload_save storage=`st` path=`path` key=`key` content_type=`content_type` prefix=`prefix`*
Return *[Save the selected local upload through the configured storage resource and return its storage result.](web_upload_save(storage=`st`, path=`path`, key=`key`, content_type=`content_type`, prefix=`prefix`))*.