@@ -17,29 +17,31 @@ The repository at [simonw/simonwillisonblog-backup](https://github.com/simonw/si
17
17
## Dumping a database
18
18
19
19
Given a SQLite database called ` fixtures.db ` containing a table ` facetable ` , the following will dump out that table to the ` dump/ ` directory:
20
-
21
- sqlite-diffable dump fixtures.db dump/ facetable
22
-
20
+ ``` bash
21
+ sqlite-diffable dump fixtures.db dump/ facetable
22
+ ```
23
23
To dump out every table in that database, use ` --all ` :
24
-
25
- sqlite-diffable dump fixtures.db dump/ --all
26
-
24
+ ``` bash
25
+ sqlite-diffable dump fixtures.db dump/ --all
26
+ ```
27
27
To dump all table except some specific ones, use ` --exclude ` one or more times:
28
-
29
- sqlite-diffable dump fixtures.db dump/ --all --exclude unwanted_first_table --exclude unwanted_second_table
30
-
28
+ ``` bash
29
+ sqlite-diffable dump fixtures.db dump/ --all \
30
+ --exclude unwanted_first_table \
31
+ --exclude unwanted_second_table
32
+ ```
31
33
## Loading a database
32
34
33
35
To load a previously dumped database, run the following:
34
-
35
- sqlite-diffable load restored.db dump/
36
-
36
+ ``` bash
37
+ sqlite-diffable load restored.db dump/
38
+ ```
37
39
This will show an error if any of the tables that are being restored already exist in the database file.
38
40
39
41
You can replace those tables (dropping them before restoring them) using the ` --replace ` option:
40
-
41
- sqlite-diffable load restored.db dump/ --replace
42
-
42
+ ``` bash
43
+ sqlite-diffable load restored.db dump/ --replace
44
+ ```
43
45
## Converting to JSON objects
44
46
45
47
Table rows are stored in the ` .ndjson ` files as newline-delimited JSON arrays, like this:
@@ -52,22 +54,23 @@ Table rows are stored in the `.ndjson` files as newline-delimited JSON arrays, l
52
54
Sometimes it can be more convenient to work with a list of JSON objects.
53
55
54
56
The ` sqlite-diffable objects ` command can read a ` .ndjson ` file and its accompanying ` .metadata.json ` file and output JSON objects to standard output:
55
-
56
- sqlite-diffable objects fixtures.db dump/sortable.ndjson
57
-
57
+ ``` bash
58
+ sqlite-diffable objects fixtures.db dump/sortable.ndjson
59
+ ```
58
60
The output of that command looks something like this:
59
61
```
60
62
{"pk1": "a", "pk2": "a", "content": "a-a", "sortable": 63, "sortable_with_nulls": null, "sortable_with_nulls_2": 0.7364712141640124, "text": "$null"}
61
63
{"pk1": "a", "pk2": "b", "content": "a-b", "sortable": 51, "sortable_with_nulls": null, "sortable_with_nulls_2": 0.6020187290499803, "text": "$null"}
62
64
```
63
65
64
66
Add ` -o ` to write that output to a file:
65
-
66
- sqlite-diffable objects fixtures.db dump/sortable.ndjson -o output.txt
67
-
67
+ ``` bash
68
+ sqlite-diffable objects fixtures.db dump/sortable.ndjson -o output.txt
69
+ ```
68
70
Add ` --array ` to output a JSON array of objects, as opposed to a newline-delimited file:
69
-
70
- sqlite-diffable objects fixtures.db dump/sortable.ndjson --array
71
+ ``` bash
72
+ sqlite-diffable objects fixtures.db dump/sortable.ndjson --array
73
+ ```
71
74
Output:
72
75
```
73
76
[
0 commit comments