mirror of
https://github.com/lutris/lutris
synced 2024-11-05 18:10:49 +00:00
Add get schema db function
This commit is contained in:
parent
171e5faee2
commit
e761df47f9
2 changed files with 22 additions and 1 deletions
|
@ -27,6 +27,24 @@ from lutris import settings
|
|||
PGA_DB = settings.PGA_DB
|
||||
|
||||
|
||||
def get_schema(tablename):
|
||||
"""
|
||||
Fields:
|
||||
- position
|
||||
- name
|
||||
- type
|
||||
- not null
|
||||
- default
|
||||
- indexed
|
||||
"""
|
||||
tables = []
|
||||
query = "pragma table_info('%s')" % tablename
|
||||
with sql.db_cursor(PGA_DB) as cursor:
|
||||
for row in cursor.execute(query).fetchall():
|
||||
tables.append(row)
|
||||
return tables
|
||||
|
||||
|
||||
def create_games(cursor):
|
||||
create_game_table_query = """CREATE TABLE IF NOT EXISTS games (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
@ -89,7 +107,6 @@ def add_game(name, runner=None, slug=None, directory=None):
|
|||
game_data = {'name': name, 'slug': slug, 'runner': runner}
|
||||
if directory:
|
||||
game_data['directory'] = directory
|
||||
print game_data
|
||||
sql.db_insert(PGA_DB, "games", game_data)
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@ class TestPersonnalGameArchive(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
os.remove(TEST_PGA_PATH)
|
||||
|
||||
def test_get_schema(self):
|
||||
schema = pga.get_schema('games')
|
||||
print schema
|
||||
|
||||
def test_add_game(self):
|
||||
game_list = pga.get_games()
|
||||
game_names = [item['name'] for item in game_list]
|
||||
|
|
Loading…
Reference in a new issue