|
6 | 6 |
|
7 | 7 | Tools for dumping/loading a SQLite database to diffable directory structure |
8 | 8 |
|
9 | | -Installation: |
| 9 | +## Installation |
10 | 10 |
|
11 | 11 | pip install sqlite-diffable |
12 | 12 |
|
13 | | -Usage: |
| 13 | +## Usage |
14 | 14 |
|
15 | | - sqlite-diffable dump fixtures.db out/ facetable |
| 15 | +Given a SQLite database called `fixtures.db` containing a table `facetable`, the following will dump out that table to the `out/` directory: |
16 | 16 |
|
17 | | -This dumps the table called `facetable` from `fixtures.db` into the `out/` directory. |
| 17 | + sqlite-diffable dump fixtures.db out/ facetable |
18 | 18 |
|
19 | | -To dump out all tables, use `--all`: |
| 19 | +To dump out every table in that database, use `--all`: |
20 | 20 |
|
21 | 21 | sqlite-diffable dump fixtures.db out/ --all |
| 22 | + |
| 23 | +## Demo |
| 24 | + |
| 25 | +The repository at [simonw/simonwillisonblog-backup](https://github.com/simonw/simonwillisonblog-backup) contains a backup of the database on my blog, https://simonwillison.net/ - created using this tool. |
| 26 | + |
| 27 | +## Format |
| 28 | + |
| 29 | +Each table is represented as two files. The first, `table_name.metadata.json`, contains metadata describing the structure of the table. For a table called `redirects_redirect` that file might look like this: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "name": "redirects_redirect", |
| 34 | + "columns": [ |
| 35 | + "id", |
| 36 | + "domain", |
| 37 | + "path", |
| 38 | + "target", |
| 39 | + "created" |
| 40 | + ], |
| 41 | + "schema": "CREATE TABLE [redirects_redirect] (\n [id] INTEGER PRIMARY KEY,\n [domain] TEXT,\n [path] TEXT,\n [target] TEXT,\n [created] TEXT\n)" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +It is an object with three keys: `name` is the name of the table, `columns` is an array of column strings and `schema` is the SQL schema text used for tha table. |
| 46 | + |
| 47 | +The second file, `table_name.ndjson`, contains [newline-delimeted JSON] for every row in the table. Each row is represented as a JSON array with items corresponding to each of the columns defined in the metadata. |
| 48 | + |
| 49 | +That file for the `redirects_redirect.ndjson` table might look like this: |
| 50 | + |
| 51 | +``` |
| 52 | +[1, "feeds.simonwillison.net", "swn-everything", "https://simonwillison.net/atom/everything/", "2017-10-01T21:11:36.440537+00:00"] |
| 53 | +[2, "feeds.simonwillison.net", "swn-entries", "https://simonwillison.net/atom/entries/", "2017-10-01T21:12:32.478849+00:00"] |
| 54 | +[3, "feeds.simonwillison.net", "swn-links", "https://simonwillison.net/atom/links/", "2017-10-01T21:12:54.820729+00:00"] |
| 55 | +``` |
0 commit comments