···11+name = "sweetnhouse_dashboard"
22+version = "1.0.0"
33+44+# Fill out these fields if you intend to generate HTML documentation or publish
55+# your project to the Hex package manager.
66+#
77+# description = ""
88+# licences = ["Apache-2.0"]
99+# repository = { type = "github", user = "", repo = "" }
1010+# links = [{ title = "Website", href = "" }]
1111+#
1212+# For a full reference of all the available options, you can have a look at
1313+# https://gleam.run/writing-gleam/gleam-toml/.
1414+1515+[dependencies]
1616+gleam_stdlib = ">= 0.44.0 and < 2.0.0"
1717+1818+[dev-dependencies]
1919+gleeunit = ">= 1.0.0 and < 2.0.0"
+11
sweetnhouse_dashboard/manifest.toml
···11+# This file was generated by Gleam
22+# You typically do not need to edit this file
33+44+packages = [
55+ { name = "gleam_stdlib", version = "0.68.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F7FAEBD8EF260664E86A46C8DBA23508D1D11BB3BCC6EE1B89B3BC3E5C83FF1E" },
66+ { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" },
77+]
88+99+[requirements]
1010+gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
1111+gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
···11+name = "sweetnhouse_server"
22+version = "1.0.0"
33+target = "erlang"
44+55+# Fill out these fields if you intend to generate HTML documentation or publish
66+# your project to the Hex package manager.
77+#
88+# description = ""
99+# licences = ["Apache-2.0"]
1010+# repository = { type = "github", user = "", repo = "" }
1111+# links = [{ title = "Website", href = "" }]
1212+#
1313+# For a full reference of all the available options, you can have a look at
1414+# https://gleam.run/writing-gleam/gleam-toml/.
1515+1616+[dependencies]
1717+gleam_stdlib = ">= 0.44.0 and < 2.0.0"
1818+mist = ">= 2.0.0 and < 6.0.0"
1919+dot_env = ">= 1.2.0 and < 2.0.0"
2020+wisp = ">= 2.1.1 and < 3.0.0"
2121+gleam_erlang = ">= 1.3.0 and < 2.0.0"
2222+pog = ">= 4.1.0 and < 5.0.0"
2323+gleam_http = ">= 4.3.0 and < 5.0.0"
2424+2525+2626+[dev-dependencies]
2727+gleeunit = ">= 1.0.0 and < 2.0.0"
···11+import gleam/dynamic/decode
22+import pog
33+import sweetnhouse_server/web
44+55+/// Retrieve a configuration value by key from the database,
66+/// or compute, insert and return a default value if the key does not exist.
77+/// Returns a tuple of the value and a boolean indicating whether the default function was ran.
88+pub fn get_or(
99+ ctx: web.Context,
1010+ key: String,
1111+ default default: fn() -> String,
1212+) -> #(String, Bool) {
1313+ let conn = pog.named_connection(ctx.db_pool_name)
1414+1515+ case
1616+ pog.query("SELECT value FROM app_config WHERE key = $1")
1717+ |> pog.parameter(pog.text(key))
1818+ |> pog.returning(decode.at([0], decode.string))
1919+ |> pog.execute(conn)
2020+ {
2121+ Ok(res) if res.count > 0 -> {
2222+ let z = "Could not retrieve " <> key <> " from database."
2323+ let assert [val, ..] = res.rows as z
2424+ #(val, False)
2525+ }
2626+2727+ _ -> {
2828+ let new_val = default()
2929+ let assert Ok(_) =
3030+ pog.query(
3131+ "INSERT INTO app_config (key, value) VALUES ('secret_key_base', $1)",
3232+ )
3333+ |> pog.parameter(pog.text(new_val))
3434+ |> pog.execute(conn)
3535+ #(new_val, True)
3636+ }
3737+ }
3838+}
···11+name = "sweetnhouse_shared"
22+version = "1.0.0"
33+44+# Fill out these fields if you intend to generate HTML documentation or publish
55+# your project to the Hex package manager.
66+#
77+# description = ""
88+# licences = ["Apache-2.0"]
99+# repository = { type = "github", user = "", repo = "" }
1010+# links = [{ title = "Website", href = "" }]
1111+#
1212+# For a full reference of all the available options, you can have a look at
1313+# https://gleam.run/writing-gleam/gleam-toml/.
1414+1515+[dependencies]
1616+gleam_stdlib = ">= 0.44.0 and < 2.0.0"
1717+1818+[dev-dependencies]
1919+gleeunit = ">= 1.0.0 and < 2.0.0"