a bit more database work
This commit is contained in:
parent
37a80aa58c
commit
0d9655265e
3 changed files with 28 additions and 2 deletions
10
README.md
10
README.md
|
@ -15,4 +15,12 @@ currently, there's no reason to run this except for development. however, if you
|
||||||
1. clone the repository
|
1. clone the repository
|
||||||
2. copy `src/toastbin/config.sample.json` to `src/toastbin/config.json`
|
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)
|
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`)
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
{
|
{
|
||||||
"instance": {
|
"instance": {
|
||||||
"domain": "example.com"
|
"domain": "example.com"
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"username": "toastbin",
|
||||||
|
"password": "hunter2",
|
||||||
|
"port": "5432",
|
||||||
|
"location": "localhost",
|
||||||
|
"database": "toastbin"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
import sqlalchemy
|
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()
|
||||||
|
|
Loading…
Add table
Reference in a new issue