Skip to content

Commit 2b2fed6

Browse files
The config can be loaded from a database instead of files
1 parent 3b6061c commit 2b2fed6

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

cynthia_websites_mini_server/src/cynthia_websites_mini_server.gleam

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ pub fn main() {
2626
<> premixed.text_bright_orange(process.cwd())
2727
<> "!",
2828
)
29-
config.load()
30-
let db = database.create_database()
31-
config.store_db(db)
29+
let #(db, conf) = config.load()
30+
3231
bun.serve(ServeOptions(
3332
development: Some(True),
3433
hostname: None,

cynthia_websites_mini_server/src/cynthia_websites_mini_server/config.gleam

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import bungibindies/bun/sqlite
2+
import cynthia_websites_mini_server/database
23
import cynthia_websites_mini_server/utils/files
34
import cynthia_websites_mini_server/utils/prompts
45
import cynthia_websites_mini_shared/configtype
5-
import gleam/bool
66
import gleam/dynamic/decode
77
import gleam/io
88
import gleam/json
@@ -14,7 +14,11 @@ import plinth/javascript/console
1414
import plinth/node/process
1515
import simplifile
1616

17-
pub fn load() -> configtype.SharedCynthiaConfig {
17+
/// # Config.load()
18+
/// Loads the configuration from the `cynthia-mini.toml` file and the content from the `content` directory.
19+
/// Then saves the configuration to the database.
20+
/// If an override environment variable or call param is provided, it will use that database file instead, and load from there. It will not need any files to exist in the filesystem (except for the SQLite file) in that case.
21+
pub fn load() -> #(sqlite.Database, configtype.SharedCynthiaConfig) {
1822
let global_conf_filepath = process.cwd() <> "/cynthia-mini.toml"
1923
let global_conf_filepath_exists = files.file_exist(global_conf_filepath)
2024
case global_conf_filepath_exists {
@@ -45,7 +49,12 @@ pub fn load() -> configtype.SharedCynthiaConfig {
4549
}
4650
}
4751

48-
configtype.shared_merge_shared_cynthia_config(global_config, content)
52+
let conf =
53+
configtype.shared_merge_shared_cynthia_config(global_config, content)
54+
let db = database.create_database()
55+
store_db(db, conf)
56+
57+
#(db, conf)
4958
}
5059

5160
pub type ContentKindOnly {
@@ -107,8 +116,11 @@ fn content_getter() {
107116
}
108117
}
109118

110-
pub fn store_db(db: sqlite.Database) -> Nil {
111-
// todo: Implement this
119+
pub fn store_db(
120+
db: sqlite.Database,
121+
conf: configtype.SharedCynthiaConfig,
122+
) -> Nil {
123+
// TODO: Implement this
112124
// nil to continue
113125
Nil
114126
}

0 commit comments

Comments
 (0)