feat: add merge_all_wren utility, strutil demo, and 7 new API manual pages
Add WrenFileReader class in apps/merge_all_wren.wren for recursive .wren file discovery and content printing. Introduce example/strutil_demo.wren demonstrating case conversion, hex encoding, SHA256 hashing, string repetition, padding, HTML/JSON escaping, and URL encoding/decoding. Create manual/api pages for argparse, dataset, html, markdown, uuid, wdantic, and web modules. Update manual/api/index.html sidebar and module count from 21 to 28, adding links and cards for the new modules.
This commit is contained in:
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var users = ds["users"]
|
||||
|
||||
var active = users.insert({"name": "Alice", "active": true, "admin": false})
|
||||
System.print(active["active"]) // expect: true
|
||||
System.print(active["admin"]) // expect: false
|
||||
|
||||
var inactive = users.insert({"name": "Bob", "active": false, "admin": true})
|
||||
System.print(inactive["active"]) // expect: false
|
||||
System.print(inactive["admin"]) // expect: true
|
||||
|
||||
var found = users.findOne({"name": "Alice"})
|
||||
System.print(found["active"]) // expect: 1
|
||||
System.print(found["admin"]) // expect: 0
|
||||
|
||||
var activeUsers = users.find({"active": true})
|
||||
System.print(activeUsers.count) // expect: 1
|
||||
System.print(activeUsers[0]["name"]) // expect: Alice
|
||||
|
||||
ds.close()
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var events = ds["events"]
|
||||
|
||||
var event = events.insert({
|
||||
"name": "Conference",
|
||||
"created_at": "2024-01-15T10:00:00"
|
||||
})
|
||||
|
||||
System.print(event["created_at"]) // expect: 2024-01-15T10:00:00
|
||||
System.print(event["name"]) // expect: Conference
|
||||
|
||||
var found = events.findOne({"name": "Conference"})
|
||||
System.print(found["created_at"]) // expect: 2024-01-15T10:00:00
|
||||
|
||||
var auto = events.insert({"name": "Meeting"})
|
||||
System.print(auto["created_at"] != null) // expect: true
|
||||
System.print(auto["created_at"] != "2024-01-15T10:00:00") // expect: true
|
||||
|
||||
ds.close()
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var users = ds["users"]
|
||||
|
||||
var user = users.insert({
|
||||
"uid": "my-custom-id-123",
|
||||
"name": "Alice"
|
||||
})
|
||||
|
||||
System.print(user["uid"]) // expect: my-custom-id-123
|
||||
System.print(user["name"]) // expect: Alice
|
||||
|
||||
var found = users.findOne({"uid": "my-custom-id-123"})
|
||||
System.print(found != null) // expect: true
|
||||
System.print(found["name"]) // expect: Alice
|
||||
|
||||
users.update({"uid": "my-custom-id-123", "name": "Alice Smith"})
|
||||
var updated = users.findOne({"uid": "my-custom-id-123"})
|
||||
System.print(updated["name"]) // expect: Alice Smith
|
||||
|
||||
ds.close()
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var users = ds["users"]
|
||||
|
||||
var emptyAll = users.all()
|
||||
System.print(emptyAll.count) // expect: 0
|
||||
|
||||
System.print(users.count()) // expect: 0
|
||||
|
||||
var user = users.insert({"name": "Alice", "score": 100})
|
||||
|
||||
var notFound = users.findOne({"name": "Nobody"})
|
||||
System.print(notFound == null) // expect: true
|
||||
|
||||
var emptyFind = users.find({"name": "Nobody"})
|
||||
System.print(emptyFind.count) // expect: 0
|
||||
System.print(emptyFind is List) // expect: true
|
||||
var uid = user["uid"]
|
||||
|
||||
var changes1 = users.update({"uid": uid, "score": 200})
|
||||
System.print(changes1) // expect: 1
|
||||
|
||||
var changes2 = users.update({"uid": uid, "score": 300, "level": 5})
|
||||
System.print(changes2) // expect: 1
|
||||
|
||||
var updated = users.findOne({"uid": uid})
|
||||
System.print(updated["score"]) // expect: 300
|
||||
System.print(updated["level"]) // expect: 5
|
||||
|
||||
var fakeChanges = users.update({"uid": "nonexistent-uid", "score": 999})
|
||||
System.print(fakeChanges) // expect: 0
|
||||
|
||||
System.print(users.delete("nonexistent-uid")) // expect: false
|
||||
|
||||
ds.close()
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
import "io" for File
|
||||
|
||||
var dbPath = "/tmp/test_dataset.db"
|
||||
|
||||
if (File.exists(dbPath)) {
|
||||
File.delete(dbPath)
|
||||
}
|
||||
|
||||
var ds = Dataset.open(dbPath)
|
||||
var users = ds["users"]
|
||||
|
||||
var user = users.insert({"name": "Alice", "score": 100})
|
||||
System.print(user["name"]) // expect: Alice
|
||||
System.print(users.count()) // expect: 1
|
||||
|
||||
ds.close()
|
||||
|
||||
System.print(File.exists(dbPath)) // expect: true
|
||||
|
||||
var ds2 = Dataset.open(dbPath)
|
||||
var users2 = ds2["users"]
|
||||
|
||||
System.print(users2.count()) // expect: 1
|
||||
var found = users2.findOne({"name": "Alice"})
|
||||
System.print(found["score"]) // expect: 100
|
||||
|
||||
ds2.close()
|
||||
|
||||
File.delete(dbPath)
|
||||
System.print(File.exists(dbPath)) // expect: false
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var users = ds["users"]
|
||||
|
||||
var user = users.insert({"name": "Alice"})
|
||||
var uid = user["uid"]
|
||||
|
||||
System.print(users.count()) // expect: 1
|
||||
|
||||
users.delete(uid)
|
||||
System.print(users.count()) // expect: 0
|
||||
|
||||
var softDeleted = ds.db.query("SELECT * FROM users WHERE uid = ?", [uid])
|
||||
System.print(softDeleted.count) // expect: 1
|
||||
System.print(softDeleted[0]["deleted_at"] != null) // expect: true
|
||||
|
||||
var user2 = users.insert({"name": "Bob"})
|
||||
var uid2 = user2["uid"]
|
||||
|
||||
System.print(users.hardDelete(uid2)) // expect: true
|
||||
var hardDeleted = ds.db.query("SELECT * FROM users WHERE uid = ?", [uid2])
|
||||
System.print(hardDeleted.count) // expect: 0
|
||||
|
||||
System.print(users.hardDelete("nonexistent")) // expect: false
|
||||
|
||||
ds.close()
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var posts = ds["posts"]
|
||||
|
||||
var post = posts.insert({
|
||||
"title": "Hello",
|
||||
"tags": ["wren", "programming"],
|
||||
"metadata": {"views": 100, "featured": true}
|
||||
})
|
||||
|
||||
System.print(post["title"]) // expect: Hello
|
||||
System.print(post["tags"] is List) // expect: true
|
||||
System.print(post["tags"].count) // expect: 2
|
||||
System.print(post["tags"][0]) // expect: wren
|
||||
System.print(post["metadata"] is Map) // expect: true
|
||||
System.print(post["metadata"]["views"]) // expect: 100
|
||||
System.print(post["metadata"]["featured"]) // expect: true
|
||||
|
||||
var retrieved = posts.findOne({"title": "Hello"})
|
||||
System.print(retrieved["tags"] is List) // expect: true
|
||||
System.print(retrieved["tags"][1]) // expect: programming
|
||||
System.print(retrieved["metadata"]["views"]) // expect: 100
|
||||
|
||||
var nested = posts.insert({
|
||||
"title": "Nested",
|
||||
"data": {
|
||||
"level1": {
|
||||
"level2": ["a", "b", "c"]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var fetched = posts.findOne({"title": "Nested"})
|
||||
System.print(fetched["data"]["level1"]["level2"][0]) // expect: a
|
||||
|
||||
ds.close()
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
|
||||
var users = ds["users"]
|
||||
var posts = ds["posts"]
|
||||
var comments = ds["comments"]
|
||||
|
||||
var user = users.insert({"name": "Alice"})
|
||||
var userUid = user["uid"]
|
||||
|
||||
var post = posts.insert({"title": "Hello", "author_uid": userUid})
|
||||
var postUid = post["uid"]
|
||||
|
||||
comments.insert({"text": "Nice!", "post_uid": postUid, "author_uid": userUid})
|
||||
comments.insert({"text": "Great!", "post_uid": postUid, "author_uid": userUid})
|
||||
|
||||
System.print(users.count()) // expect: 1
|
||||
System.print(posts.count()) // expect: 1
|
||||
System.print(comments.count()) // expect: 2
|
||||
|
||||
var tables = ds.tables
|
||||
System.print(tables.count) // expect: 3
|
||||
System.print(tables.contains("users")) // expect: true
|
||||
System.print(tables.contains("posts")) // expect: true
|
||||
System.print(tables.contains("comments")) // expect: true
|
||||
|
||||
var postComments = comments.find({"post_uid": postUid})
|
||||
System.print(postComments.count) // expect: 2
|
||||
|
||||
ds.close()
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var users = ds["users"]
|
||||
|
||||
users.insert({"name": "Alice", "email": "alice@example.com"})
|
||||
users.insert({"name": "Bob", "email": null})
|
||||
users.insert({"name": "Charlie"})
|
||||
|
||||
var withEmail = users.find({"email__null": false})
|
||||
System.print(withEmail.count) // expect: 1
|
||||
System.print(withEmail[0]["name"]) // expect: Alice
|
||||
|
||||
var withoutEmail = users.find({"email__null": true})
|
||||
System.print(withoutEmail.count) // expect: 2
|
||||
|
||||
var all = users.all()
|
||||
System.print(all.count) // expect: 3
|
||||
|
||||
ds.close()
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var products = ds["products"]
|
||||
|
||||
var p1 = products.insert({"name": "Widget", "price": 19.99, "quantity": 100})
|
||||
System.print(p1["price"]) // expect: 19.99
|
||||
System.print(p1["quantity"]) // expect: 100
|
||||
|
||||
var p2 = products.insert({"name": "Gadget", "price": 0.5, "quantity": 0})
|
||||
System.print(p2["price"]) // expect: 0.5
|
||||
System.print(p2["quantity"]) // expect: 0
|
||||
|
||||
var found = products.findOne({"name": "Widget"})
|
||||
System.print(found["price"]) // expect: 19.99
|
||||
System.print(found["quantity"]) // expect: 100
|
||||
|
||||
var cheap = products.find({"price__lt": 1})
|
||||
System.print(cheap.count) // expect: 1
|
||||
System.print(cheap[0]["name"]) // expect: Gadget
|
||||
|
||||
var expensive = products.find({"price__gte": 10})
|
||||
System.print(expensive.count) // expect: 1
|
||||
|
||||
ds.close()
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
var products = ds["products"]
|
||||
|
||||
products.insert({"name": "Apple", "price": 10, "stock": 100})
|
||||
products.insert({"name": "Banana", "price": 5, "stock": 50})
|
||||
products.insert({"name": "Cherry", "price": 20, "stock": 0})
|
||||
products.insert({"name": "Date", "price": 15, "stock": 25})
|
||||
|
||||
var gte = products.find({"price__gte": 15})
|
||||
System.print(gte.count) // expect: 2
|
||||
|
||||
var lte = products.find({"price__lte": 10})
|
||||
System.print(lte.count) // expect: 2
|
||||
|
||||
var ne = products.find({"name__ne": "Apple"})
|
||||
System.print(ne.count) // expect: 3
|
||||
|
||||
var like = products.find({"name__like": "A\%"})
|
||||
System.print(like.count) // expect: 1
|
||||
System.print(like[0]["name"]) // expect: Apple
|
||||
|
||||
var inList = products.find({"name__in": ["Apple", "Banana"]})
|
||||
System.print(inList.count) // expect: 2
|
||||
|
||||
var zeroStock = products.find({"stock": 0})
|
||||
System.print(zeroStock.count) // expect: 1
|
||||
System.print(zeroStock[0]["name"]) // expect: Cherry
|
||||
|
||||
var combined = products.find({"price__gte": 10, "stock__gt": 0})
|
||||
System.print(combined.count) // expect: 2
|
||||
|
||||
ds.close()
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
|
||||
var users = ds["users"]
|
||||
System.print(users.name) // expect: users
|
||||
|
||||
var products = ds["products"]
|
||||
System.print(products.name) // expect: products
|
||||
|
||||
var orders = ds["my_orders"]
|
||||
System.print(orders.name) // expect: my_orders
|
||||
|
||||
ds.close()
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "dataset" for Dataset
|
||||
|
||||
var ds = Dataset.memory()
|
||||
|
||||
System.print(ds.tables.count) // expect: 0
|
||||
|
||||
ds["users"].insert({"name": "Alice"})
|
||||
System.print(ds.tables.count) // expect: 1
|
||||
System.print(ds.tables.contains("users")) // expect: true
|
||||
|
||||
ds["products"].insert({"name": "Widget"})
|
||||
System.print(ds.tables.count) // expect: 2
|
||||
System.print(ds.tables.contains("products")) // expect: true
|
||||
|
||||
ds["orders"].insert({"total": 100})
|
||||
System.print(ds.tables.count) // expect: 3
|
||||
|
||||
ds.close()
|
||||
Reference in New Issue
Block a user