diff --git a/README.md b/README.md index 60850d3..7ca6972 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,12 @@ currently, there's no reason to run this except for development. however, if you 1. clone the repository 2. copy `src/toastbin/config.sample.json` to `src/toastbin/config.json` 3. install dependencies (currently, we just need `flask` and `sqlalchemy` from python and `postgresql` from the system repos but this almost absoultely will change) -4. run `src/toastbin/app.py` (`python3 src/toastbin/app.py`) +4. set up database: +```sql +CREATE DATABASE toastbin WITH ENCODING = 'UTF8'; +CREATE USER toastbin WITH ENCRYPTED PASSWORD '{YOUR_PASSWORD}'; +GRANT ALL PRIVILEGES ON DATABASE toastbin TO toastbin; +ALTER DATABASE toastbin OWNER TO toastbin; +\q +``` +5. run `src/toastbin/app.py` (`python3 src/toastbin/app.py`) diff --git a/src/toastbin/config.sample.json b/src/toastbin/config.sample.json index 3ccd3ea..f1638ed 100644 --- a/src/toastbin/config.sample.json +++ b/src/toastbin/config.sample.json @@ -1,5 +1,12 @@ { "instance": { "domain": "example.com" + }, + "database": { + "username": "toastbin", + "password": "hunter2", + "port": "5432", + "location": "localhost", + "database": "toastbin" } } diff --git a/src/toastbin/database.py b/src/toastbin/database.py index 39c97f2..f470c82 100644 --- a/src/toastbin/database.py +++ b/src/toastbin/database.py @@ -1,3 +1,14 @@ import sqlalchemy +import json -engine = sqlalchemy.create_engine('postgresql://') # todo: finish this, give users options maybe +with open('config.json', 'r') as file: + config = json.load(file) +username = config['database']['username'] +password = config['database']['password'] +port = config['database']['port'] +location = config['database']['location'] +database = config['database']['database'] + +engine = sqlalchemy.create_engine('postgresql://' + username + ':' + password + '@' + location ':' + port + '/' + database) # todo: finish this, give users options maybe +Session = sqlalchemy.orm.sessionmaker(bind=engine) +session = Session()