-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
established database connection with api
- Loading branch information
Showing
9 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
from .main import * | ||
import psycopg2 | ||
|
||
__all__ = ["insertBet", "removeBet"] | ||
|
||
__all__ = ["insertBet", "removeBet"] | ||
|
||
createTableString = """ | ||
CREATE TABLE bettingtest ( | ||
id SERIAL PRIMARY KEY, | ||
userid VARCHAR, | ||
matchid INT, | ||
teamid INT, | ||
amount FLOAT | ||
); | ||
""" | ||
|
||
def __init__(): | ||
with bettingconn.cursor() as curs: | ||
try: | ||
curs.execute(createTableString) | ||
except psycopg2.errors.DuplicateTable as e: | ||
print("duplicate table encountered") | ||
pass | ||
__init__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import psycopg2 | ||
|
||
bettingconn = psycopg2.connect(host="db", user="postgres", password="postgres", dbname="betting") | ||
bettingconn.autocommit=True | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
def insertBet(): | ||
pass | ||
def insertBet(userid, matchid, teamid, amount): | ||
with bettingconn.cursor() as curs: | ||
curs.execute(f"""INSERT INTO bettingtest (userid, matchid, teamid, amount) | ||
VALUES ({userid},{matchid},{teamid},{amount});""") | ||
|
||
|
||
def removeBet(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Flask==3.0.3 | ||
Flask==3.0.3 | ||
Psycopg2==2.9.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
to connect to postgres from python: conn = psycopg2.connect(host="db", user="postgres", dbname="[the name of a database]") | ||
to connect to postgres from python: conn = psycopg2.connect(host="db", user="postgres", dbname="[the name of a database]") | ||
|
||
|
||
psql info: \l to list databases | ||
\c [database_name] to go into database | ||
\dt to list all tables in current database | ||
sql statements when u are in the database |