Extend sqlite3 database, item and link support
This commit is contained in:
parent
60e2d3e044
commit
831b801696
10 changed files with 597 additions and 92 deletions
39
test/create-database.py
Normal file
39
test/create-database.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
|
||||
|
||||
from itemsdb.sqlite3 import *
|
||||
from itemsdb.log import *
|
||||
import os.path
|
||||
|
||||
|
||||
dbdir = os.getenv("ITEMSDB_SQLITE3_DATABASEDIR", ".")
|
||||
dbname = os.getenv("ITEMSDB_SQLITE3_FILENAME", "itemsdb.db")
|
||||
dbprefix = os.getenv("ITEMSDB_PREFIX", "")
|
||||
dbfilename = os.path.join(dbdir, f"{dbprefix}{dbname}")
|
||||
|
||||
parameter = dict(filename=dbfilename, prefix=dbprefix)
|
||||
|
||||
db = DBSqlite3(parameter=parameter)
|
||||
|
||||
debug(f"Database: '{type(db)}'")
|
||||
try:
|
||||
db_created, msg = db.create()
|
||||
debug(f"Database after create(): '{type(db)}'")
|
||||
if db_created:
|
||||
print(f"Database '{dbfilename}' created")
|
||||
else:
|
||||
print(msg)
|
||||
open, open_msg = db.open()
|
||||
print(open_msg)
|
||||
|
||||
debug(f"Database after open(): '{type(db)}'")
|
||||
tables_created, msg = db.createTables()
|
||||
if tables_created:
|
||||
print(f"{msg}: {', '.join([model.__name__ for model in db.models])}")
|
||||
else:
|
||||
print(msg)
|
||||
|
||||
|
||||
except DBException as db_e:
|
||||
print(db_e)
|
||||
Loading…
Add table
Add a link
Reference in a new issue