Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpostgres_service.py
More file actions
Latest commit
32 lines (26 loc) · 1.08 KB
/
Copy pathpostgres_service.py
File metadata and controls
32 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importpsycopg2aspg
classPostgres():
def__init__(self):
self.conn_string="host='127.0.0.1' dbname='test' user='postgres' password=''"
self.conn=pg.connect(self.conn_string)
self.cursor=self.conn.cursor()
defpopulate(self):
self.cursor.execute("DROP TABLE IF EXISTS things;")
self.cursor.execute("CREATE TABLE things (name varchar(20));")
self.cursor.execute("INSERT INTO things(name) VALUES('Dre');")
self.cursor.execute("INSERT INTO things(name) VALUES('Smalls');")
self.cursor.execute("INSERT INTO things(name) VALUES('West');")
self.cursor.execute("INSERT INTO things(name) VALUES('Combs');")
self.cursor.execute("INSERT INTO things(name) VALUES('Flame');")
defread(self):
self.cursor.execute("SELECT * FROM things;")
count=self.cursor.fetchall()
returnlen(count)
defdisconnect(self):
ifself.conn:
self.conn.close()
if__name__=='__main__':
postgres=Postgres()
postgres.populate()
postgres.read()
postgres.disconnect()