Skip to content
Snippets Groups Projects
Commit fbf675e8 authored by David Trattnig's avatar David Trattnig
Browse files

SQLite config option as in engine. engine#89

parent e469e930
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
[database]
# Use 'postgresql' or 'mysql'
# Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
db_type="postgresql"
db_name="aura_engine_api"
db_user="aura_engine_api"
......
......@@ -5,7 +5,7 @@
[database]
# Use 'postgresql' or 'mysql'
# Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
db_type="postgresql"
db_name="aura_engine_api"
db_user="aura_engine_api"
......
......@@ -5,7 +5,7 @@
[database]
# Use 'postgresql' or 'mysql'
# Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
db_type="postgresql"
db_name="aura_engine_api"
db_user="aura_engine_api"
......
......@@ -148,14 +148,18 @@ class AuraConfig:
Retrieves the database connection string.
"""
db_name = str(self.get("db_name"))
db_user = str(self.get("db_user"))
db_pass = str(self.get("db_pass"))
db_host = str(self.get("db_host"))
db_type = str(self.get("db_type"))
db_charset = self.get("db_charset", "utf8")
if db_type == "mysql":
return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset
elif db_type == "postgresql":
return f"postgresql+psycopg2://{db_user}:{db_pass}@{db_host}/{db_name}?client_encoding={db_charset}"
if db_type in {"mysql", "postgresql"}:
db_user = str(self.get("db_user"))
db_pass = str(self.get("db_pass"))
db_host = str(self.get("db_host"))
db_charset = self.get("db_charset", "utf8")
if db_type == "mysql":
return f"mysql://{db_user}:{db_pass}@{db_host}/{db_name}?charset={db_charset}"
else:
return f"postgresql+psycopg2://{db_user}:{db_pass}@{db_host}/{db_name}?client_encoding={db_charset}"
elif db_type == "sqlite":
# "db_name" is expected to be either a relative or an absolute path to the sqlite file
return f"sqlite:///{db_name}.db"
else:
return f"Error: invalid database type '{db_type}'"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment