simonw / datasette
Showing 1 of 1 files from the diff.

@@ -1,82 +1,95 @@
Loading
1 +
import textwrap
2 +
3 +
1 4
async def init_internal_db(db):
2 5
    await db.execute_write(
3 -
        """
6 +
        textwrap.dedent(
7 +
            """
4 8
    CREATE TABLE databases (
5 -
        "database_name" TEXT PRIMARY KEY,
6 -
        "path" TEXT,
7 -
        "is_memory" INTEGER,
8 -
        "schema_version" INTEGER
9 +
        database_name TEXT PRIMARY KEY,
10 +
        path TEXT,
11 +
        is_memory INTEGER,
12 +
        schema_version INTEGER
9 13
    )
10 -
    """,
14 +
    """
15 +
        ),
11 16
        block=True,
12 17
    )
13 18
    await db.execute_write(
14 -
        """
19 +
        textwrap.dedent(
20 +
            """
15 21
    CREATE TABLE tables (
16 -
        "database_name" TEXT,
17 -
        "table_name" TEXT,
18 -
        "rootpage" INTEGER,
19 -
        "sql" TEXT,
22 +
        database_name TEXT,
23 +
        table_name TEXT,
24 +
        rootpage INTEGER,
25 +
        sql TEXT,
20 26
        PRIMARY KEY (database_name, table_name),
21 27
        FOREIGN KEY (database_name) REFERENCES databases(database_name)
22 28
    )
23 -
    """,
29 +
    """
30 +
        ),
24 31
        block=True,
25 32
    )
26 33
    await db.execute_write(
27 -
        """
34 +
        textwrap.dedent(
35 +
            """
28 36
    CREATE TABLE columns (
29 -
        "database_name" TEXT,
30 -
        "table_name" TEXT,
31 -
        "cid" INTEGER,
32 -
        "name" TEXT,
33 -
        "type" TEXT,
37 +
        database_name TEXT,
38 +
        table_name TEXT,
39 +
        cid INTEGER,
40 +
        name TEXT,
41 +
        type TEXT,
34 42
        "notnull" INTEGER,
35 -
        "default_value" TEXT, -- renamed from dflt_value
36 -
        "is_pk" INTEGER, -- renamed from pk
37 -
        "hidden" INTEGER,
43 +
        default_value TEXT, -- renamed from dflt_value
44 +
        is_pk INTEGER, -- renamed from pk
45 +
        hidden INTEGER,
38 46
        PRIMARY KEY (database_name, table_name, name),
39 47
        FOREIGN KEY (database_name) REFERENCES databases(database_name),
40 48
        FOREIGN KEY (database_name, table_name) REFERENCES tables(database_name, table_name)
41 49
    )
42 -
    """,
50 +
    """
51 +
        ),
43 52
        block=True,
44 53
    )
45 54
    await db.execute_write(
46 -
        """
55 +
        textwrap.dedent(
56 +
            """
47 57
    CREATE TABLE indexes (
48 -
        "database_name" TEXT,
49 -
        "table_name" TEXT,
50 -
        "seq" INTEGER,
51 -
        "name" TEXT,
58 +
        database_name TEXT,
59 +
        table_name TEXT,
60 +
        seq INTEGER,
61 +
        name TEXT,
52 62
        "unique" INTEGER,
53 -
        "origin" TEXT,
54 -
        "partial" INTEGER,
63 +
        origin TEXT,
64 +
        partial INTEGER,
55 65
        PRIMARY KEY (database_name, table_name, name),
56 66
        FOREIGN KEY (database_name) REFERENCES databases(database_name),
57 67
        FOREIGN KEY (database_name, table_name) REFERENCES tables(database_name, table_name)
58 68
    )
59 -
    """,
69 +
    """
70 +
        ),
60 71
        block=True,
61 72
    )
62 73
    await db.execute_write(
63 -
        """
74 +
        textwrap.dedent(
75 +
            """
64 76
    CREATE TABLE foreign_keys (
65 -
        "database_name" TEXT,
66 -
        "table_name" TEXT,
67 -
        "id" INTEGER,
68 -
        "seq" INTEGER,
77 +
        database_name TEXT,
78 +
        table_name TEXT,
79 +
        id INTEGER,
80 +
        seq INTEGER,
69 81
        "table" TEXT,
70 82
        "from" TEXT,
71 83
        "to" TEXT,
72 -
        "on_update" TEXT,
73 -
        "on_delete" TEXT,
74 -
        "match" TEXT,
84 +
        on_update TEXT,
85 +
        on_delete TEXT,
86 +
        match TEXT,
75 87
        PRIMARY KEY (database_name, table_name, id, seq),
76 88
        FOREIGN KEY (database_name) REFERENCES databases(database_name),
77 89
        FOREIGN KEY (database_name, table_name) REFERENCES tables(database_name, table_name)
78 90
    )
79 -
    """,
91 +
    """
92 +
        ),
80 93
        block=True,
81 94
    )
82 95
@@ -84,14 +97,14 @@
Loading
84 97
async def populate_schema_tables(internal_db, db):
85 98
    database_name = db.name
86 99
    await internal_db.execute_write(
87 -
        "delete from tables where database_name = ?", [database_name], block=True
100 +
        "DELETE FROM tables WHERE database_name = ?", [database_name], block=True
88 101
    )
89 -
    tables = (await db.execute("select * from sqlite_master where type = 'table'")).rows
102 +
    tables = (await db.execute("select * from sqlite_master WHERE type = 'table'")).rows
90 103
    for table in tables:
91 104
        table_name = table["name"]
92 105
        await internal_db.execute_write(
93 106
            """
94 -
            insert into tables (database_name, table_name, rootpage, sql)
107 +
            INSERT INTO tables (database_name, table_name, rootpage, sql)
95 108
            values (?, ?, ?, ?)
96 109
        """,
97 110
            [database_name, table_name, table["rootpage"], table["sql"]],
@@ -99,7 +112,7 @@
Loading
99 112
        )
100 113
        # And the columns
101 114
        await internal_db.execute_write(
102 -
            "delete from columns where database_name = ? and table_name = ?",
115 +
            "DELETE FROM columns WHERE database_name = ? and table_name = ?",
103 116
            [database_name, table_name],
104 117
            block=True,
105 118
        )
@@ -111,7 +124,7 @@
Loading
111 124
            }
112 125
            await internal_db.execute_write(
113 126
                """
114 -
                insert into columns (
127 +
                INSERT INTO columns (
115 128
                    database_name, table_name, cid, name, type, "notnull", default_value, is_pk, hidden
116 129
                ) VALUES (
117 130
                    :database_name, :table_name, :cid, :name, :type, :notnull, :default_value, :is_pk, :hidden
@@ -122,7 +135,7 @@
Loading
122 135
            )
123 136
        # And the foreign_keys
124 137
        await internal_db.execute_write(
125 -
            "delete from foreign_keys where database_name = ? and table_name = ?",
138 +
            "DELETE FROM foreign_keys WHERE database_name = ? and table_name = ?",
126 139
            [database_name, table_name],
127 140
            block=True,
128 141
        )
@@ -136,7 +149,7 @@
Loading
136 149
            }
137 150
            await internal_db.execute_write(
138 151
                """
139 -
                insert into foreign_keys (
152 +
                INSERT INTO foreign_keys (
140 153
                    database_name, table_name, "id", seq, "table", "from", "to", on_update, on_delete, match
141 154
                ) VALUES (
142 155
                    :database_name, :table_name, :id, :seq, :table, :from, :to, :on_update, :on_delete, :match
@@ -147,7 +160,7 @@
Loading
147 160
            )
148 161
        # And the indexes
149 162
        await internal_db.execute_write(
150 -
            "delete from indexes where database_name = ? and table_name = ?",
163 +
            "DELETE FROM indexes WHERE database_name = ? and table_name = ?",
151 164
            [database_name, table_name],
152 165
            block=True,
153 166
        )
@@ -159,7 +172,7 @@
Loading
159 172
            }
160 173
            await internal_db.execute_write(
161 174
                """
162 -
                insert into indexes (
175 +
                INSERT INTO indexes (
163 176
                    database_name, table_name, seq, name, "unique", origin, partial
164 177
                ) VALUES (
165 178
                    :database_name, :table_name, :seq, :name, :unique, :origin, :partial
Files Coverage
datasette 91.55%
Project Totals (32 files) 91.55%
1
coverage:
2
  status:
3
    project:
4
      default:
5
        informational: true
6
    patch:
7
      default:
8
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading