mirror of
https://gitlab.com/jrmiller82/pathfinder-2-sqlite.git
synced 2026-10-12 22:29:44 -04:00
continue refactor gendb.py
This commit is contained in:
1 parent
612e061229
commit
34f572555d
3 files changed
+130
-115
No files matched your search
+83
-3
@@ -1,4 +1,3 @@
|
||||
|
||||
def do_abilityscore(data, conn):
|
||||
table = """
|
||||
CREATE TABLE abilityscore (
|
||||
@@ -24,6 +23,7 @@ CREATE TABLE abilityscore (
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_actioncost(data, conn):
|
||||
table = """
|
||||
CREATE TABLE actioncost (
|
||||
@@ -48,6 +48,7 @@ CREATE TABLE actioncost (
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_alignment(data, conn):
|
||||
# print(data)
|
||||
table = """
|
||||
@@ -73,6 +74,7 @@ CREATE TABLE alignment (
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_frequency(data, conn):
|
||||
table = """
|
||||
CREATE TABLE frequency (
|
||||
@@ -99,8 +101,6 @@ CREATE TABLE frequency (
|
||||
conn.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
def do_langrarity(data, conn):
|
||||
table = """
|
||||
CREATE TABLE langrarity (
|
||||
@@ -123,5 +123,85 @@ CREATE TABLE langrarity (
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating langrarity: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_movement(data, conn):
|
||||
table = """
|
||||
CREATE TABLE movement (
|
||||
movement_id INTEGER PRIMARY KEY,
|
||||
"name" TEXT UNIQUE NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i, )) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO movement(name) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt, inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating movement: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_size(data, conn):
|
||||
table = """
|
||||
CREATE TABLE size (
|
||||
size_id INTEGER PRIMARY KEY,
|
||||
short_name TEXT NOT NULL UNIQUE,
|
||||
space_in_ft INTEGER NOT NULL,
|
||||
reach_tall_ft INTEGER NOT NULL,
|
||||
reach_long_ft INTEGER NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i['name'], i['space_in_ft'], i['reach_tall_ft'],
|
||||
i['reach_long_ft']))
|
||||
|
||||
stmt = "INSERT INTO size (short_name, space_in_ft, reach_tall_ft, reach_long_ft) VALUES (?,?,?,?)"
|
||||
try:
|
||||
conn.executemany(stmt, inp_data)
|
||||
except:
|
||||
print("Error creating size")
|
||||
else:
|
||||
conn.commit()
|
||||
|
||||
|
||||
def do_weaponcategory(data, conn):
|
||||
table = """
|
||||
CREATE TABLE weaponcategory (
|
||||
weaponcategory_id INTEGER PRIMARY KEY,
|
||||
"name" TEXT NOT NULL UNIQUE
|
||||
);
|
||||
"""
|
||||
|
||||
c = conn.cursor()
|
||||
c.execute(table)
|
||||
|
||||
inp_data = []
|
||||
for i in data:
|
||||
inp_data.append((i, )) # trailing comma necessary for one-item tuple
|
||||
|
||||
stmt = "INSERT INTO weaponcategory(name) VALUES (?)"
|
||||
try:
|
||||
conn.executemany(stmt, inp_data)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print("Error creating weaponcategory: {}".format(e))
|
||||
print(vars(e))
|
||||
else:
|
||||
conn.commit()
|
||||
@@ -0,0 +1,17 @@
|
||||
import sqlite3
|
||||
|
||||
def get_db_conn(DBFILE):
|
||||
## Get database connection
|
||||
conn = sqlite3.connect(DBFILE) # eventually hook this up to be the main db
|
||||
## Set pragmas
|
||||
pragma1 = "PRAGMA synchronous=OFF;"
|
||||
pragma2 = "PRAGMA count_changes=OFF;"
|
||||
pragma3 = "PRAGMA journal_mode=MEMORY;"
|
||||
pragma4 = "PRAGMA temp_store=MEMORY;"
|
||||
pragma5 = "PRAGMA foreign_keys=ON;"
|
||||
conn.execute(pragma1)
|
||||
conn.execute(pragma2)
|
||||
conn.execute(pragma3)
|
||||
conn.execute(pragma4)
|
||||
conn.execute(pragma5)
|
||||
return conn
|
||||
Reference in new issue
Block a user