You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
import sqlite3
|
|
|
|
def get_db_connection():
|
|
conn = sqlite3.connect('database.db')
|
|
conn.row_factory = sqlite3.Row
|
|
return conn
|
|
|
|
def dict_from_row(row):
|
|
return dict(zip(row.keys(), row))
|
|
|
|
def create_instrument(name, slug, description, params, sockets):
|
|
connection = get_db_connection()
|
|
cur = connection.cursor()
|
|
cur.execute(
|
|
"INSERT INTO instruments (name, slug, description, panel) VALUES (?, ?, ?, ?)",
|
|
(name, slug, description, f'{slug}.svg')
|
|
)
|
|
|
|
for param in params:
|
|
cur.execute(
|
|
"INSERT OR IGNORE INTO params (param_name) VALUES (?)",(param,)
|
|
)
|
|
cur.execute(
|
|
"INSERT INTO instrument_param (instrument, param_name) VALUES (?, ?)", (slug, param )
|
|
)
|
|
|
|
for socket in sockets:
|
|
cur.execute(
|
|
"INSERT OR IGNORE INTO sockets (socket_name) VALUES (?)", (socket,)
|
|
)
|
|
|
|
cur.execute(
|
|
"INSERT INTO instrument_socket (instrument, socket_name) VALUES (?, ?)", (slug, socket )
|
|
)
|
|
|
|
connection.commit()
|
|
connection.close() |