Add get schema db function

This commit is contained in:
Mathieu Comandon 2013-12-09 02:05:13 +01:00
parent 171e5faee2
commit e761df47f9
2 changed files with 22 additions and 1 deletions

View file

@ -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)

View file

@ -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]