Revert "Support for generated columns, closes #1116" - it failed CI

This reverts commit 37f87b5e52.
pull/1120/head
Simon Willison 2020-11-30 12:09:22 -08:00
rodzic 37f87b5e52
commit dea3c508b3
3 zmienionych plików z 8 dodań i 76 usunięć

Wyświetl plik

@ -64,7 +64,7 @@ HASH_LENGTH = 7
# Can replace this with Column from sqlite_utils when I add that dependency
Column = namedtuple(
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk", "hidden")
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk")
)
@ -460,11 +460,11 @@ def detect_primary_keys(conn, table):
" Figure out primary keys for a table. "
table_info_rows = [
row
for row in conn.execute(f'PRAGMA table_xinfo("{table}")').fetchall()
if row["pk"]
for row in conn.execute(f'PRAGMA table_info("{table}")').fetchall()
if row[-1]
]
table_info_rows.sort(key=lambda row: row["pk"])
return [str(r["name"]) for r in table_info_rows]
table_info_rows.sort(key=lambda row: row[-1])
return [str(r[1]) for r in table_info_rows]
def get_outbound_foreign_keys(conn, table):
@ -572,7 +572,7 @@ def table_columns(conn, table):
def table_column_details(conn, table):
return [
Column(*r)
for r in conn.execute(f"PRAGMA table_xinfo({escape_sqlite(table)});").fetchall()
for r in conn.execute(f"PRAGMA table_info({escape_sqlite(table)});").fetchall()
]

Wyświetl plik

@ -1,6 +1,5 @@
from datasette.app import Datasette
from datasette.plugins import DEFAULT_PLUGINS
from datasette.utils import detect_json1, sqlite3
from datasette.utils import detect_json1
from datasette.version import __version__
from .fixtures import ( # noqa
app_client,
@ -515,14 +514,7 @@ def test_database_page(app_client):
},
{
"name": "searchable_fts",
"columns": [
"text1",
"text2",
"name with . and spaces",
"searchable_fts",
"docid",
"__langid",
],
"columns": ["text1", "text2", "name with . and spaces"],
"primary_keys": [],
"count": 2,
"hidden": True,
@ -1921,46 +1913,3 @@ def test_paginate_using_link_header(app_client, qs):
else:
path = None
assert num_pages == 21
@pytest.mark.skipif(
tuple(
map(
int,
sqlite3.connect(":memory:")
.execute("select sqlite_version()")
.fetchone()[0]
.split("."),
)
)
< (3, 31, 0),
reason="generated columns were added in SQLite 3.31.0",
)
@pytest.mark.asyncio
async def test_generated_columns_are_visible_in_datasette(tmp_path_factory):
db_directory = tmp_path_factory.mktemp("dbs")
db_path = db_directory / "test.db"
conn = sqlite3.connect(str(db_path))
conn.executescript(
"""
CREATE TABLE deeds (
body TEXT,
id INT GENERATED ALWAYS AS (json_extract(body, '$.id')) STORED,
consideration INT GENERATED ALWAYS AS (json_extract(body, '$.consideration')) STORED
);
INSERT INTO deeds (body) VALUES ('{
"id": 1,
"consideration": "This is the consideration"
}');
"""
)
datasette = Datasette([db_path])
response = await datasette.client.get("/test/deeds.json?_shape=array")
assert response.json() == [
{
"rowid": 1,
"body": '{\n "id": 1,\n "consideration": "This is the consideration"\n }',
"id": 1,
"consideration": "This is the consideration",
}
]

Wyświetl plik

@ -120,7 +120,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=1,
hidden=0,
),
Column(
cid=1,
@ -129,7 +128,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=2,
@ -138,7 +136,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=3,
@ -147,7 +144,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=4,
@ -156,7 +152,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=5,
@ -165,7 +160,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=6,
@ -174,7 +168,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=7,
@ -183,7 +176,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=8,
@ -192,7 +184,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=9,
@ -201,7 +192,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
],
),
@ -215,7 +205,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=1,
hidden=0,
),
Column(
cid=1,
@ -224,7 +213,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=2,
hidden=0,
),
Column(
cid=2,
@ -233,7 +221,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=3,
@ -242,7 +229,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=4,
@ -251,7 +237,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=5,
@ -260,7 +245,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
Column(
cid=6,
@ -269,7 +253,6 @@ async def test_table_columns(db, table, expected):
notnull=0,
default_value=None,
is_pk=0,
hidden=0,
),
],
),