made some work for pastedb / pastecache..
This commit is contained in:
0
btc_tracker/01042023/TheClient/database/__init__.py
Normal file
0
btc_tracker/01042023/TheClient/database/__init__.py
Normal file
27
btc_tracker/01042023/TheClient/database/db_utils.py
Normal file
27
btc_tracker/01042023/TheClient/database/db_utils.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sqlite3
|
||||
|
||||
class Database():
|
||||
def __init__(self, db_file):
|
||||
self.db_file = db_file
|
||||
self._create_table()
|
||||
|
||||
def _create_table(self):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS timeseries
|
||||
(timestamp INTEGER PRIMARY KEY, value REAL)''')
|
||||
conn.commit()
|
||||
|
||||
def insert_data(self, timestamp, value):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''INSERT INTO timeseries (timestamp, value)
|
||||
VALUES (?, ?)''', (timestamp, value))
|
||||
conn.commit()
|
||||
|
||||
def fetch_data(self, limit):
|
||||
with sqlite3.connect(self.db_file) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''SELECT timestamp, value FROM timeseries
|
||||
ORDER BY timestamp DESC LIMIT ?''', (limit,))
|
||||
return cursor.fetchall()
|
Reference in New Issue
Block a user