-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_example.fun
More file actions
executable file
·48 lines (39 loc) · 1.41 KB
/
sqlite_example.fun
File metadata and controls
executable file
·48 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-11-26
*/
// Prepare sample DB from SQL if needed (requires sqlite3 CLI installed)
// Create it once with:
// sqlite3 ./database.sqlite < ./examples/data/database.sql
string db_path = "./database.sqlite"
number h = sqlite_open(db_path)
if h == 0
print("Failed to open DB: " + db_path)
exit(1)
rows = sqlite_query(h, "SELECT id, title, done, created_at FROM tasks ORDER BY id;")
print("Tasks (" + to_string(len(rows)) + "):")
for row in rows
string status = "✘"
if row["done"] == 1
status = "✔"
print("- [" + status + "] (#" + to_string(row["id"]) + ") " + to_string(row["title"]) + " — " + to_string(row["created_at"]))
number rc = sqlite_exec(h, "INSERT INTO tasks (title, done) VALUES ('Try Fun + SQLite', 0);")
print("Insert rc=" + to_string(rc))
rows2 = sqlite_query(h, "SELECT count(*) AS cnt FROM tasks;")
print("Total tasks now: " + to_string(rows2[0]["cnt"]))
sqlite_close(h)
/* Example output:
Tasks (3):
- [✔] (#1) Write Fun + SQLite example — 2025-11-26 23:22:04
- [✘] (#2) Ship optional feature flag — 2025-11-26 23:22:04
- [✘] (#3) Celebrate with coffee — 2025-11-26 23:22:04
Insert rc=0
Total tasks now: 4
*/