made some work for pastedb / pastecache..

This commit is contained in:
kalzu
2023-04-04 09:15:28 +03:00
parent 32d3e2dfe1
commit 5ffd0f0c03
63 changed files with 2251 additions and 0 deletions

View 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()