Files
marqdo/examples/web-tenant-saas/db/index.mq.md
T
cflmy 9331af78e2 release(2.8.0): 合入 CHANGELOG/README/发版说明/skills prove 任务;CI 链接指向 doc/releases
- CHANGELOG.md:v2.8.0 条目(中英双语);
- README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明);
- doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制);
- skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/
  require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过);
- 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
2026-11-18 10:29:26 +08:00

48 lines
2.2 KiB
Markdown
Executable File

---
markup: occlusion
title: Tenant demonstration database
import:
db: ext/data/db.mq.md
fs: lib/fs.mq.md
---
This initializer owns one demonstration table. It keeps existing rows and seeds only an empty table. Pass a disposable absolute SQLite URI for tests; no caller should need to delete a user's data to repeat initialization.
## open
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | any | None | None chooses data/tenant-saas.db under the granted site root; otherwise an explicit SQLite URI |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Initialized database resource containing retained user rows or initial demo notes |
Use `url`=None with fs.write and plugin on the site root. The default path is resolved through the native filesystem so its location does not change with the process working directory. An explicit SQLite URI belongs to the caller, who must grant and manage that native database boundary. This initializer never deletes rows or resets ids during a restart.
The schema preserves the title and tenant_id fields used by the scoped query. Check for any existing row before seeding; a nonempty or partially populated database is retained as supplied. Only a completely empty table receives the two notes. This is an idempotent demonstration initializer, not a migration or repair tool.
1. `url` == None
We **[Create the site's selected data directory](fs.make_dirs(path="data"))** and **path = [Resolve the native database filename](fs.resolve(path="data/tenant-saas.db"))** and **url = "sqlite:" + path**.
`fields` =
| name | type | nullable |
|---|---|---|
| id | integer | False |
| title | text | False |
| tenant_id | text | False |
We **store = [Open the selected database resource](db.db(url=`url`))** and **[Ensure the demonstration table exists](> `store`.init name="items" fields=`fields`)** and **existing = [Observe whether any business rows already exist](> `store`.select table="items" limit=1)**.
1. not `existing`
`rows` =
| @ | title | tenant_id |
|---|---|---|
| 1 | Acme note | acme |
| 2 | Beta note | beta |
We **[Insert both initial notes only into the empty table](> `store`.insert table="items" rows=`rows`)**.
Once the selected database is ready, return *store* for route discovery and binding.