Created
January 7, 2021 16:30
-
-
Save hazardland/47fdbe394a6890d9793846c44465028e to your computer and use it in GitHub Desktop.
Insert records using postgresql-orm
This file contains hidden or 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
import sql | |
import logging as log | |
log.basicConfig(level=log.DEBUG) | |
sql.db = sql.Db('dbname=postgres user=postgres password=1234 host=127.0.0.1 port=5432') | |
class Bet: | |
pass | |
class Table(sql.Table): | |
schema = 'public' | |
name = 'bets' | |
type = Bet | |
fields = { | |
'id': {'type': 'int'}, | |
'Number': {'type': 'int'}, | |
'Color': {}, | |
'Odd_even': {}, | |
'Low_high': {}, | |
'Column': {}, | |
'Sector': {} | |
} | |
bets = [{'Number': '15', 'Color': 'black', 'Odd_even': 'odd', 'Low_high': '1/18', 'Column': 'Column3', 'Sector': 'Sector2'}] | |
for bet in bets: | |
Table.add(bet) | |
""" | |
SETUP: | |
------------------------- | |
pip install psycopg2-binary | |
pip install postgresql-orm | |
CREATE TABLE QUERY: | |
------------------------- | |
CREATE TABLE bets ( | |
id BIGSERIAL PRIMARY KEY NOT NULL, | |
"Number" SMALLINT, | |
"Color" TEXT, | |
"Odd_even" TEXT, | |
"Low_high" TEXT, | |
"Column" TEXT, | |
"Sector" TEXT | |
) | |
""" | |
# SELECT | |
bet = Table.get(1) | |
bets = Table.all(filter={'Number':{'from':5, 'to':10}}) | |
# UPDATE | |
Table.save(1, {'Sector': 'Sector3'}) | |
# DELETE | |
Table.delete(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment