easy +8 pts

Create Table Schema

Design an SQLite table schema for a simple library catalog and verify it with PRAGMA.

Write a function `create_table_schema(table_name: str, columns: list[tuple[str, str]]) -> list[str]` that uses the `sqlite3` module (in-memory database) to create a table. The `columns` parameter is a list of `(name, type)` tuples where `name` is the column name and `type` is a SQLite type string (e.g., 'INTEGER', 'TEXT'). The function should create the table with a single `id INTEGER PRIMARY KEY` column first, then append the given columns in order. After creation, use `PRAGMA table_info(table_name)` to retrieve the column definitions and return them as a list of strings formatted as `"name type"` (e.g., `"id INTEGER"`, `"title TEXT"`). The returned list must include the `id` column first, followed by the columns in the original order. The function should handle empty column lists and should always start with the `id` column. Do not return any other information.

Constraints

0 <= len(columns) <= 100. Each column name is a non-empty string, type is a valid SQLite type. The table name is a valid SQLite identifier. The database is always in-memory. The function must create the table using the provided schema and exactly return the list of strings read from PRAGMA.

Example

>>> create_table_schema('books', [('title', 'TEXT'), ('pages', 'INTEGER')])
['id INTEGER', 'title TEXT', 'pages INTEGER']
>>> create_table_schema('empty', [])
['id INTEGER']
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use sqlite3.connect(':memory:') to create an in-memory database.
After executing CREATE TABLE, run `PRAGMA table_info(table_name)` to get column metadata.
In the PRAGMA result, each row has (cid, name, type, notnull, dflt_value, pk). Extract name and type.
Remember to create the id column first with 'id INTEGER PRIMARY KEY'.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.