a mini social media app for small communities
1module database
2
3import entity { Site }
4
5pub fn (app &DatabaseAccess) get_or_create_site_config() Site {
6 mut configs := sql app.db {
7 select from Site
8 } or { [] }
9 if configs.len == 0 {
10 // make the site config
11 site_config := Site{}
12 sql app.db {
13 insert site_config into Site
14 } or { panic('failed to create site config (${err})') }
15 configs = sql app.db {
16 select from Site
17 } or { [] }
18 } else if configs.len > 1 {
19 // this should never happen
20 panic('there are multiple site configs')
21 }
22 return configs[0]
23}
24
25// set_motd sets the site's current message of the day, returns true if this
26// succeeds and false otherwise.
27pub fn (app &DatabaseAccess) set_motd(motd string) bool {
28 sql app.db {
29 update Site set motd = motd where id == 1
30 } or {
31 return false
32 }
33 return true
34}