using Tommy; namespace RestySqlite { public class Utils { public static dynamic? ReadConfig(string key, string? category = null) { if (!File.Exists("conf.toml")) { TomlTable toml = new TomlTable { ["title"] = "Configuration file for API", ["api"] = { ["port"] = 5417, ["handle"] = "api", }, ["sql"] = { ["database"] = "" } }; using(StreamWriter writer = File.CreateText("conf.toml")) { toml.WriteTo(writer); // Remember to flush the data if needed! writer.Flush(); } Console.WriteLine("Config created please check it."); return null; } using(StreamReader reader = File.OpenText("conf.toml")) { TomlTable table = TOML.Parse(reader); if (category != null) { return table[category][key]; } return table[key]; } } public static void CreateDatabase(string databaseName) { Console.WriteLine("Would you like to create database? Y/N"); var input = Console.ReadKey().Key.ToString() ?? throw new NullReferenceException("Can't read key from user!") ; if (input.ToUpper() != "Y") return; File.Create($"{databaseName}.db"); Console.WriteLine("Now please, create first table inside database."); Console.WriteLine("Input a valid SQL command: "); var command = Console.ReadLine() ?? throw new NullReferenceException("Can't read command from user!"); try { new DatabaseWrapper(databaseName).ExecuteCommand(command); } catch (Exception e) { Console.WriteLine(e.Message); return; } } } }