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 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 } else if configs.len > 1 {
16 // this should never happen
17 panic('there are multiple site configs')
18 }
19 return configs[0]
20}
21
22// set_motd sets the site's current message of the day, returns true if this
23// succeeds and false otherwise.
24pub fn (app &DatabaseAccess) set_motd(motd string) bool {
25 sql app.db {
26 update Site set motd = motd where id == 1
27 } or {
28 return false
29 }
30 return true
31}