Release 2.7.0: executable handbooks and native user-site workflows

This commit is contained in:
cflmy committed 2026-11-10 17:03:06 +08:00
1 parent aa0c4d0f55
commit d9aef957f7
562 files changed
+21064 -20387

No files matched your search

+19 -14
View File
@@ -1,27 +1,32 @@
---
markup: occlusion
title: Article schema and seed handbook
import:
document: lib/document.mq.md
---
This file explains callable use; [articles.tables.md](articles.tables.md) holds the readable literal tables. Set --fs-root to the site directory and grant fs.read. Reading returns data without running prose, opening a database or changing a page.
## schema
`fields` =
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Native table value, preserving literal types and column geometry |
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| title | text | false |
| body | text | true |
Declare article fields, native types and nullability. The initializer consumes this table to ensure structure; it must not guess a migration or erase existing rows.
*`fields`*
Call independently with fs.read on the site root. The section must match exactly and uniquely. Malformed tables or dynamic expressions retain native document diagnostics. A returned style declaration still needs compilation; returned database data still needs an explicit initializer. This value is neither HTML nor an applied browser effect.
Return *[读取 schema 的实际字面表](document.read_table(path="db/articles.tables.md", title="schema"))*.
## seed
`rows` =
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Native table value, preserving literal types and column geometry |
| id | title | body |
|----|-------|------|
| 1 | Welcome to the web-net site | Home page lists rows from SQLite. |
| 2 | Login-gated admin | The /admin page requires a session cookie. |
| 3 | WebSocket live | The /live endpoint echoes your message in real time. |
Provide initial demonstration articles with their original ids, stable slugs and content. Insert only after the database initializer confirms an empty table; this reader never changes existing articles.
*`rows`*
Call independently with fs.read on the site root. The section must match exactly and uniquely. Malformed tables or dynamic expressions retain native document diagnostics. A returned style declaration still needs compilation; returned database data still needs an explicit initializer. This value is neither HTML nor an applied browser effect.
Return *[读取 seed 的实际字面表](document.read_table(path="db/articles.tables.md", title="seed"))*.
@@ -0,0 +1,23 @@
# Article data
Literal article schema and demonstration content. Reading these tables does not open a database or insert rows. Follow articles.mq.md for callable use; the database initializer decides whether seeding is appropriate.
## schema
Field definitions for the native database initializer; nullable values remain booleans.
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| title | text | false |
| body | text | true |
## seed
Initial demonstration records in their original column-oriented shape; ids and stable slugs retain their meaning.
| id | title | body |
|----|-------|------|
| 1 | Welcome to the web-net site | Home page lists rows from SQLite. |
| 2 | Login-gated admin | The /admin page requires a session cookie. |
| 3 | WebSocket live | The /live endpoint echoes your message in real time. |
+29 -13
View File
@@ -1,21 +1,37 @@
---
markup: occlusion
title: db/index
description: Open sqlite, init articles, seed once.
title: web-net-site database lifecycle
import:
web: ext/web/web.mq.md
data: ext/data/db.mq.md
articles: articles.mq.md
fs: lib/fs.mq.md
text: lib/text.mq.md
---
The database entry connects schema and literal seed leaves to the actual data resource. It no longer uses the removed web database constructor. Grant fs.write and plugin with the site directory as --fs-root; the SQLite path is resolved through that native root rather than the process working directory.
## open
**store = > web.db url="sqlite:data/site-net.db"**
**fields = > articles.schema**
> `store`.init name=articles fields=`fields`
**rows = > store.select table="articles" limit=1**
1. `rows`
*store*
2. *
**seed = > articles.seed**
> `store`.insert table=articles rows=`seed`
*store*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | any | None | None selects data/site-net.db under the site root; tests provide a disposable explicit URI |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Initialized articles database resource with existing rows preserved |
Use `url`=None to open the site's local database. Create the default data directory through native file operations, then resolve the actual SQLite filename within the granted root. An explicit SQLite path goes through the same root and symlink checks before the native database resource receives it. Other supported database URIs retain their resource-specific backend contract; they are not sandboxed by filesystem permissions.
The schema reader preserves native field types and nullability. Initialization ensures the table exists, queries one row to distinguish an empty table, and inserts the original demonstration content only into an empty table. An existing or partly populated table is kept unchanged. This is not a column migrator, data repair tool or reason to delete a user's articles. A native connection, schema or insert diagnostic stops the caller before it starts serving.
For isolated verification choose a caller-owned temporary SQLite file and copy the article data leaf under that granted site root. Keep the returned resource in the same program for subsequent queries. Close the process before cleaning its owned directory; do not run tests against the example's existing data directory.
1. `url` == None
We **[Create only the site's default data directory](fs.make_dirs(path="data"))** and **file = [Resolve its database filename](fs.resolve(path="data/site-net.db"))** and **url = "sqlite:" + file**.
1. [The explicit or default URI selects SQLite](text.starts_with(text=`url`, prefix="sqlite:"))
We **file = [Read the selected SQLite path](text.replace(text=`url`, old="sqlite:", new="", count=1))** and **file = [Apply the native file-root policy](fs.resolve(path=`file`))** and **url = "sqlite:" + file**.
We **store = [Open the selected actual database resource](data.db(url=`url`))** and **fields = [Read the documented article schema](articles.schema())**.
We **[Ensure the table without clearing it](> `store`.init name="articles" fields=`fields`)** and **existing = [Check whether business records already exist](> `store`.select table="articles" limit=1)**.
1. not `existing`
We **seed = [Read the original demonstration data](articles.seed())** and **[Seed only the empty article table](> `store`.insert table="articles" rows=`seed`)**.
Once the selected database is ready, return *store* for the site's resource bindings.