import tables import std/[os, db_sqlite, strutils, streams] import formatter proc createDb(dbSettings: Table): bool = if not fileExists(dbSettings["path"]): var userConsent: bool = false while userConsent != true: stdout.write "Did not find database. Create one now? (y/n) " stdout.flushFile() var userInput = readChar(stdin) stdin.flushFile() case userInput of 'y', 'Y': userConsent = true of 'n', 'N': return false else: discard let schema = readFile(dbSettings["schema_path"]) db = open(dbSettings["path"], "", "", "") for command in schema.split(";"): # Skip "command" if it's just a blank line if command == "\c\n" or command == "\n": continue db.exec(sql(command.strip)) logPrint("Ran SQL command from schema", "Info") db.close() return true export createDb