Advertisement
MilkyDoritos

db.py

May 21st, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import sqlite3
  2.  
  3. class Database:
  4.     def __init__(self, db):
  5.         self.conn  = sqlite3.connect(db)
  6.         self.cur = self.conn.cursor()
  7.         self.cur.execute("CREATE TABLE IF NOT EXISTS tunes (id INTEGER PRIMARY KEY, rear real, arfront real, arrear real, springfront real, springrear real, rideheightfront real, rideheightrear real, reboundfront real, reboundrear real)")
  8.         self.conn.commit()
  9.  
  10.     def fetch(self, id):
  11.         self.cur.execute("SELECT * FROM tunes")
  12.         items = self.cur.fetchall()
  13.         return items
  14.  
  15.     def insert(self, rear, arfront, arrear, springfront, springrear, rideheightfront, rideheightrear, reboundfront, reboundrear):
  16.         self.cur.execute("INSERT INTO tunes VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (rear, arfront, arrear, springfront, springrear, rideheightfront, rideheightrear, reboundfront, reboundrear))
  17.         self.conn.commit()
  18.         self.cur.execute("SELECT last_insert_rowid()")
  19.         rowid = self.cur.fetchone()
  20.         return rowid
  21.  
  22.     def remove(self, id):
  23.         self.cur.execute("DELETE FROM tunes WHERE id=?", (id,))
  24.         self.conn.commit()
  25.  
  26.     def __del__(self):
  27.         self.conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement