Utility for writing test database fixtures to a .db file

python tests/fixtures.py /tmp/hello.db

This is useful for making a SQLite database of the test fixtures for
interactive exploration.
pull/192/head
Simon Willison 2018-04-03 06:46:11 -07:00
rodzic 8f0d44d646
commit dd0566ff8e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 17E2DEA2588B7F52
1 zmienionych plików z 11 dodań i 0 usunięć

Wyświetl plik

@ -2,6 +2,7 @@ from datasette.app import Datasette
import itertools
import os
import sqlite3
import sys
import string
import tempfile
import time
@ -142,3 +143,13 @@ CREATE VIEW simple_view AS
a=a, b=b, c=c, content=content
) for a, b, c, content in generate_compound_rows(1001)
])
if __name__ == '__main__':
filename = sys.argv[-1]
if filename.endswith('.db'):
conn = sqlite3.connect(filename)
conn.executescript(TABLES)
print('Test tables written to {}'.format(filename))
else:
print('Usage: {} name_of_file_to_write.db'.format(sys.argv[0]))