Skip to content
Snippets Groups Projects

Store created elements in a local SQLite database

Merged Eva Bardou requested to merge sqlite-database into master
All threads resolved!
2 files
+ 48
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 31
0
# -*- coding: utf-8 -*-
import os
import sqlite3
class LocalDB(object):
def __init__(self, path):
if not os.path.exists(path):
open(path, "x").close()
self.db = sqlite3.connect(path)
self.cursor = self.db.cursor()
def create_elements_table(self):
try:
self.cursor.execute(
"""CREATE TABLE elements (
id TEXT PRIMARY KEY,
parent_id TEXT,
name TEXT NOT NULL,
type TEXT NOT NULL,
polygon TEXT,
worker_version_id TEXT
)"""
)
except sqlite3.OperationalError:
print("Table 'elements' already exists")
def insert(self, table, lines):
self.cursor.executemany(f"INSERT INTO {table} VALUES (?,?,?,?,?,?)", lines)
self.db.commit()
Loading